Interesting idea. Hadn’t thought of that.
FYI, the state_changed event is documented here.
Using that, this might work for you:
- alias: Automation ran
trigger:
platform: event
event_type: state_changed
condition:
- condition: template
value_template: >
{{ trigger.event.data.entity_id.startswith('automation.') and
trigger.event.data.entity_id != 'automation.automation_ran' and
trigger.event.data.old_state is not none and
trigger.event.data.new_state is not none }}
action:
- condition: template
value_template: >
{{ trigger.event.data.new_state.attributes.last_triggered !=
trigger.event.data.old_state.attributes.last_triggered }}
- ...
The reason I split the condition into two parts, one in the automation’s condition section, and the other in the automation’s action section, is that it’s possible for either trigger.event.data.old_state or trigger.event.data.new_state to be omitted None
. Since the automation’s condition will always be evaluated, I wanted to avoid referencing something that might not exist (i.e., attributes...
).
So, the first condition tests that the event is from the automation domain, and that it’s not from this automation itself. It also makes sure that both old_state and new_state exist are not None
. Assuming all this is true, then the actions start to run.
The first action is a condition that decides if the new last_triggered is different from the old last_triggered. If so, then the automation must have just run. If not, then the rest of the automation actions don’t run.
I haven’t tested any of this, but based on my experience so far with HA, I think this might do what you want.
EDIT: This extremely old post has been brought back to haunt me. I’ve adjusted accordingly.