The following automation blasts out a list of any state change directly to a file:
- alias: Device Offline
trigger: event
platform: event
event_type: state_changed
action:
service: notify.state_changed <--- this is a file notification to capture the output.
data_template:
message: "{{ trigger.event.data }}"
Here is an example of one of the results:
2018-10-05T06:39:17.546730+00:00 {'entity_id': 'sensor.sn1_connection', 'old_state': <state sensor.sn1_connection=Disconnected; friendly_name=Sensor Node 1, entity_picture=/local/images/icons/nodemcudisconnected.png @ 2018-10-04T22:45:56.331326-07:00>, 'new_state': <state sensor.sn1_connection=Connected; friendly_name=Sensor Node 1, entity_picture=/local/images/icons/nodemcuconnected.png @ 2018-10-04T23:39:17.440310-07:00>}
Question:
How do I tap into the new_state
values to return only the state of the sensor.sn1_connection, which would be the value “Connected” ?
My goal was to create an automation that watched the event bus for any device that changed to “Disconnected” regardless of its entity_id, as I’m unable to create a state trigger without an entity.