mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-18 23:06:58 +00:00
Added alternative to using now() as a trigger (#10615)
* Added alternative to using now() as a trigger Based on this forum thread https://community.home-assistant.io/t/automation-condition-if-a-state-of-an-entity-hasnt-changed/140791/4 and the fact that I regularly see people say how you can’t use now() as a trigger but no one has ever offered an alternative. * Reinstated {% raw %} and {% endraw %} tags
This commit is contained in:
parent
6d6aa54a97
commit
61f97d40d1
@ -279,6 +279,22 @@ The `for` template(s) will be evaluated when the `value_template` becomes `true`
|
||||
Rendering templates with time (`now()`) is dangerous as trigger templates only update based on entity state changes.
|
||||
</div>
|
||||
|
||||
|
||||
As an alternative, providing you include the sensor [time](/integrations/time_date/) in your configuration, you can use the following template:
|
||||
|
||||
{% raw %}
|
||||
|
||||
```yaml
|
||||
automation:
|
||||
trigger:
|
||||
platform: template
|
||||
value_template: "{{ (as_timestamp(states.sensor.time.last_changed) - as_timestamp(states.YOUR.ENTITY.last_changed)) > 300 }}"
|
||||
```
|
||||
|
||||
{% endraw %}
|
||||
|
||||
which will evaluate to `True` if `YOUR.ENTITY` changed more than 300 seconds ago.
|
||||
|
||||
### Time trigger
|
||||
|
||||
The time trigger is configured to run once at a specific point in time each day.
|
||||
|
Loading…
x
Reference in New Issue
Block a user