diff --git a/source/_integrations/template.markdown b/source/_integrations/template.markdown index 1f699ce7245..7f73ab9e8e2 100644 --- a/source/_integrations/template.markdown +++ b/source/_integrations/template.markdown @@ -339,3 +339,29 @@ sensor: ``` {% endraw %} + +### Updating templates using `random` + +If you use the `random` filter, you may want the template to select a different random element every now and then. If the template does not update automatically due to entity changes it can be updated periodically by using the `homeassistant.update_entity` service with a time pattern automation. For example, this will render a new random number every five minutes: + +{% raw %} + +```yaml +sensor: + - platform: template + sensors: + random_number: + friendly_name: "Random number" + value_template: "{{ range(0,100)|random }}" + +automation: + - alias: "Update random number template" + trigger: + - platform: time_pattern + minutes: "/5" + action: + - service: homeassistant.update_entity + entity_id: sensor.random_number +``` + +{% endraw %}