Trigger automation if no state update for x minutes

I am trying something like this:

- alias: Notify if THB1 sensor state unchanged
  trigger:
    platform: template
    value_template: "{% if as_timestamp(states.sensor.date__time.last_updated) - as_timestamp(states.sensor.thb_1_0.last_updated) > 5*60 %}{% endif %}"
  action:
  - service: notify.olivia
    data:
      message: 'THB1 sensor state unchanged in the last 24hours'

But it is not working. To be specific…Trigger is not working.

1 Like

Sensor.date_time looks like it has a double underscore, is that a typo?

No. It is correct. I have finally got it working. I’ve forgotten “true”

Correct line :

value_template: "{% if as_timestamp(states.sensor.date__time.last_updated) - as_timestamp(states.sensor.thb_1_0.last_updated) > 5*60 %}true{% endif %}"
5 Likes

What is the 5*60 part? 5 hours?

No, 5 minutes

I have the same problem with my tellstick sensors, however their value does not say “undefined” it just stays the same temperature as the last reading. I assume your solution wont work for this case?

Just want to make sure that you actually have the sensor say “undefined” as a value when its battery died

i never had any battery operated sensors in HA.
and my solution was something i figured out for someone else, 4 years ago!
i doubt if it still would work with the amount of changes that HA made in those 4 years.