Add a tip on updating random templates (#15394)

Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
Anders Melchiorsen 2020-10-25 12:18:55 +01:00 committed by GitHub
parent 225d4fa6f3
commit 2994f0a0c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 %}