Hey all,
slowly getting to know Home Assistant and I hope the community can help me to understand this question.
In the context of an event triggered automation, what is inside event_data
?
Some explanation to the question is given here - however the truth seems to lie somewhere in between.
Example
I observe events via the developer tools and the “*” filter. The event for a door sensor I want to trigger on looks as such:
Event trace...
{
"event_type": "state_changed",
"data": {
"entity_id": "binary_sensor.door_bathroom",
"old_state": {
"entity_id": "binary_sensor.door_bathroom",
"state": "off",
"attributes": {
"battery": "High",
"error": "No",
"rssi_peer": 0,
"rssi_device": -59,
"id": "LEQ1466850",
"interface": "wireless",
"friendly_name": "Homematic Türkontakt Bad",
"device_class": "opening"
},
"last_changed": "2020-03-21T17:21:42.848532+00:00",
"last_updated": "2020-03-21T17:21:42.848532+00:00",
"context": {
"id": "f4395769514d46a7a4b6656cdbd73d59",
"parent_id": null,
"user_id": null
}
},
"new_state": {
"entity_id": "binary_sensor.door_bathroom",
"state": "on",
"attributes": {
"battery": "High",
"error": "No",
"rssi_peer": 0,
"rssi_device": -59,
"id": "LEQ1466850",
"interface": "wireless",
"friendly_name": "Homematic Türkontakt Bad",
"device_class": "opening"
},
"last_changed": "2020-03-21T17:21:44.840558+00:00",
"last_updated": "2020-03-21T17:21:44.840558+00:00",
"context": {
"id": "9227ef990e5d4eab8717acc192d8ca65",
"parent_id": null,
"user_id": null
}
}
},
"origin": "LOCAL",
"time_fired": "2020-03-21T17:21:44.841066+00:00",
"context": {
"id": "9227ef990e5d4eab8717acc192d8ca65",
"parent_id": null,
"user_id": null
}
}
But this view doesn’t seem very useful, as its data clearly is not used for automations.
The following automation triggers:
- alias: bathroom_light_via_doorsensor
trigger:
- platform: event
event_type: state_changed
event_data:
entity_id: binary_sensor.door_bathroom
action:
service: light.turn_on
entity_id: light.bathroom
this one doesn’t trigger:
- alias: bathroom_light_via_doorsensor
trigger:
- platform: event
event_type: state_changed
event_data:
entity_id: binary_sensor.door_bathroom
new_state: # Added
state: 'on' # Added
# Also doesn't work
# new_state: 'on'
action:
service: light.turn_on
entity_id: light.bathroom
Of course I could work with a state trigger or tailor this with a condition but I am trying to learn.
Questions
The example raises a few questions:
- Why does the second automation not work?
- Is there any interface on which one can directly and unambiguously see all events and state changes with all linked data (which can then be used in triggers, conditions and actions)? This seems to be an important piece of the HA ecosystem I did not yet find.
Based on this discussion I’ll contribute an improvement to the documentation.
Thanks for your help!