I’d like to find which device has been most recently changed (i.e. turned on/off, brightness adjusted) using a template. It looks like there might be 2 values that could be of use: the state property last_changed and the device attribute timestamp. Is there one of these that would be more appropriate than the other?
I have attempted a template using timestamp, but it does not seem to give me what I’m looking for. The template I’ve been using is:
The property last_changed only refers to changes of the entities’ states, for changes that include the state and attributes like brightness you need to use the last_updated property.
You’re over quoting in state and level. Use the multi-line quote indicators or quotes around the templates, not both.
Since you are already expanding to get the entities’ state objects, there’s no need to go through the entity_id and recalculate everything to get the state and attribute value… those values are already contained in the state object.