Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions source/_integrations/template.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}