mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-15 21:36:52 +00:00
Add a tip on updating random templates (#15394)
Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
parent
225d4fa6f3
commit
2994f0a0c4
@ -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 %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user