Take a look at this example, a simple automation that sends a notification whenever a door/window i opened/closed while the house is empty.
- id: '1596462142862'
alias: Notification door/window when away
trigger:
- platform: state
entity_id: binary_sensor.door_frondoor_contact,binary_sensor.door_porch_contact,binary_sensor.window_livingroom_contact,binary_sensor.window_bathroom_contact,binary_sensor.window_lounge_contact,binary_sensor.window_bedroom1_contact,binary_sensor.window_bedroom2_contact
condition:
- condition: state
entity_id: binary_sensor.house_empty
state: 'on'
- condition: template
value_template: '{{ trigger.to_state.state != trigger.from_state.state }}'
action:
- choose:
- conditions:
- condition: template
value_template: '{{ trigger.to_state.state == ''on'' }}'
sequence:
- service: notify.both
data_template:
message: '{{ trigger.from_state.attributes.friendly_name }} open'
service: notify.both
- conditions:
- condition: template
value_template: '{{ trigger.to_state.state == ''off'' }}'
sequence:
- service: notify.both
data_template:
message: '{{ trigger.from_state.attributes.friendly_name }} closed'
Wouldn’t it be great if we could put all the relevant sensors in groups and use those as triggers?
This could also be done by adding a new parameter to the state trigger called in_group
which checks the state of entities in any given group, like this:
- platform: state
in_group: group.outer_doors, group_windows
This would, in my opinion, greatly simplify the way we write automations. Want to add or remove an entity? Just update the group and let Home Assistant handle the rest.
I originally wanted to propose the possibility of supporting wildcards in state triggers, but while writing the post it occurred to me that groups would be a way better match for this.