From 61f97d40d11db53e93af2417b77b0d916a836fb5 Mon Sep 17 00:00:00 2001 From: kloggy <38220016+kloggy@users.noreply.github.com> Date: Sun, 13 Oct 2019 10:42:06 +0100 Subject: [PATCH] Added alternative to using now() as a trigger (#10615) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- source/_docs/automation/trigger.markdown | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/source/_docs/automation/trigger.markdown b/source/_docs/automation/trigger.markdown index a3189cc8200..adf436e668d 100644 --- a/source/_docs/automation/trigger.markdown +++ b/source/_docs/automation/trigger.markdown @@ -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. + +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.