Tracking Update Times

I have some MQTT sensors, binary sensors and MQTT HVAC components. I want to track the last time they got an update or had a state change. Most of the examples I’ve seen show a template formatting now - field.last_update but I’m not sure how to set last_update for these fields.

Thanks.

all state objects have a last_updated property.
For example, I have a counter called count1.
to see the last_updated time of that object I enter this into the template editor:

{{states.counter.count1.last_updated}}

If I want to see how many seconds since that entity updated, I would enter

{{as_timestamp(now()) - as_timestamp(states.counter.count1.last_updated)}}
2 Likes