#React to history in conditions

1 messages · Page 1 of 1 (latest)

gilded pivot
#

Is there any way in HA to use the history of an entity in a condition, as in the time it last changed?

A little bit of background: I have two helpers, one of which will be turned off by an automation, the other will already have been off. Now I want to add an "undo" button to the mobile notification I get, but that needs to know which of the two helpers it has to turn back on.

timber quartz
#

Every entity has a last_changed property that records the time of its most recent state change. The value can be accessed via templating:

states.input_boolean.example.last_changed

Now I want to add an "undo" button to the mobile notification I get, but that needs to know which of the two helpers it has to turn back on.

You can get the entity ID of the most recently changed with something like:

{{ ['input_boolean.example_1', 'input_boolean.example_2']
| expand | sort(attribute='last_changed', reverse=true)
| map(attribute='entity_id') | first }}