New to Home Assistant and can’t seem to find an answer in the Automations guidance document nor in this Forum, so please be patient. I’m coming from SmartThings and want to replicate this automation:
IF 10:00 pm AND Side Door Contact Sensor OR Sgl Garage Door OR Dbl Garage Door OR Shed Door contact sensor open
THEN
Send text message (“A door is open”)
Turn On Driveway Lights Notification (Green/80%/Chase/2 hours)
I’m still wrestling with text messages but my immediate question is how to program the ORs in an automation.
My best advice to learn this is to use the GUI to make an automation with OR and AND conditions, like the ones you want and then switch to YAML view through the three dots in the upper right corner.
This will show you the nested conditions like you need to use them.
your conditions will be Side Door Contact Sensor OR Sgl Garage Door OR Dbl Garage Door OR Shed Door contact sensor open.
that will look something like this:
triggers:
- trigger: time
at: '22:00:00'
conditions:
- condition: or
conditions:
- condition: state
entity_id:
- Side Door Contact Sensor
- Sgl Garage Door
- Dbl Garage Door
- Shed Door contact sensor
state: open
actions:
- Send text message (“A door is open”)
- Turn On Driveway Lights Notification (Green/80%/Chase/2 hours)
obviously you will need to fix all of the entity_ids, state and the actions to actual code. But that should point you in the right direction.
That’s not going to work… the OR isn’t OR-ing the states of the sensors, it’s Or-ing the AND-ed states of the sensors with no other condition.
You need to have triggers that cover all those events and then mirror them in the conditions. To get an OR logic in the State condition you need to include the configuration variable match with the value any:
triggers:
- trigger: time
at: '22:00:00'
- trigger: state
entity_id:
- binary_sensor.side_door_contact_sensor
- binary_sensor.sgl_garage_door
- binary_sensor.dbl_garage_door
- binary_sensor.shed_door_contact_sensor
to: "on"
conditions:
- condition: time
after: '22:00:00'
- condition: state
entity_id:
- binary_sensor.side_door_contact_sensor
- binary_sensor.sgl_garage_door
- binary_sensor.dbl_garage_door
- binary_sensor.shed_door_contact_sensor
state: "on"
match: any
actions:
# Your actions
Putting them in a group with “All entities” disabled would also work. You would use the same construction as above, but place the group entity in the State trigger and condition rather than the individual doors.
Just note, there is a slight difference in functionality between the two. In the automation above, each door opening generates it’s own trigger event. If someone opened the side door and left it open then opened the shed door, you would get a message for for the side door then one for the shed. Using a group you would only get a message for the side door.
FWIW, the update later this week should be adding to the “purpose specific” triggers and conditions feature available in Labs, so you would be able to just label the doors and use something like:
triggers:
- trigger: door.opened
target:
label_id: exterior_doors
options:
behavior: any
- trigger: time
at: "22:00:00"
conditions:
- condition: door.is_open
target:
label_id: exterior_doors
options:
behavior: any
- condition: time
after: "22:00:00"