#last_reported trigger
1 messages · Page 1 of 1 (latest)
last_changed isn't an attribute, it's a property of the state object. But you don't need to use it, you can just set up a trigger that will fire whenever the state hasn't changed for 5 minutes:
- trigger: state
entity_id: sensor.bthome_sensor_f289_temperature
state: null
for:
minutes: 5
i think that will do it. thought i might use {{ (as_timestamp(now()) - as_timestamp(states.sensor.bthome_sensor_f289_temperature.last_reported)) }} as a value template or something.
You could do this
{{ now() - states.sensor.bthome_sensor_f289_temperature.last_reported > timedelta(minutes=5) }}
But it will get evaluated once per minute so won’t be as accurate as the state trigger. And will be less resource-efficient, although you’d never be able to measure the difference.
Well it depends what you are trying to achieve also. I just noticed your second template (and mine, since I copied yours) used last_reported instead of last_changed.
You’d use last_reported if you’re trying to determine if a sensor went offline and whatever integration you’re using isn’t appropriately detecting that it is unavailable.
You’d use last_changed if you want to know that the state of the sensor hasn’t changed, but it may still be functioning correctly.
If you wanted to use last_reported then your only option is the template trigger.
im using a bt temp senor that sometimes doesnt show an updated state for long periods of time and id like to turn a heater off if that time has been longer than 5m. they dont show as offline or unavailable. i already have it shutting off for unavailable state.
the only reason i noticed it was that the sensor shows how long its been since "last_changed" and "last_reported" in its modal ui: