From ff74babb144d8b3f2193a9c9030a7835d83fafc0 Mon Sep 17 00:00:00 2001 From: Anders Melchiorsen Date: Sat, 24 Oct 2020 18:06:34 +0200 Subject: [PATCH 1/2] Add a tip on updating random templates --- source/_integrations/template.markdown | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/source/_integrations/template.markdown b/source/_integrations/template.markdown index 1f699ce72458..2eceb88aa4a7 100644 --- a/source/_integrations/template.markdown +++ b/source/_integrations/template.markdown @@ -339,3 +339,26 @@ 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 %} From 6446387505a77d11ddf93e3be9ad59cc3a14b0fe Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sun, 25 Oct 2020 12:14:49 +0100 Subject: [PATCH 2/2] :pencil2: Tweak --- source/_integrations/template.markdown | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/_integrations/template.markdown b/source/_integrations/template.markdown index 2eceb88aa4a7..7f73ab9e8e22 100644 --- a/source/_integrations/template.markdown +++ b/source/_integrations/template.markdown @@ -343,7 +343,9 @@ sensor: ### 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 @@ -361,4 +363,5 @@ automation: - service: homeassistant.update_entity entity_id: sensor.random_number ``` + {% endraw %}