I just started over my Home Assistant installation and I’m working on setting up my automations again. I’d like to do it as clean as possible though.
Here is what my automation is for:
My laundry room has a door sensor on it. I want it so that when the door is opened, the lights turn on. When the door is closed, the lights turn off.
Before, I used to have 1 automation for turning the lights on, and 1 automation for turning the lights off.
I like to avoid working in yaml files if possible. Is there a way I can do this via the automation GUI?
If not, is there an easy way to do it via yaml?
EDIT:
I ended up figuring it out. In the “Actions” drop down box, there is a “Choose” method. I was able to set both on/off with a single automation using this “Choose” option.
Here is the code in yaml if anyone wants guidance:
alias: Laundry Room - turn on/off lights when door is opened/closed
description: ''
trigger:
- type: opened
platform: device
device_id: 5e1ee5b4640232b8042b9f057564af9a
entity_id: binary_sensor.door_sensor_laundry_room
domain: binary_sensor
- type: not_opened
platform: device
device_id: 5e1ee5b4640232b8042b9f057564af9a
entity_id: binary_sensor.door_sensor_laundry_room
domain: binary_sensor
condition: []
action:
- choose:
- conditions:
- type: is_open
condition: device
device_id: 5e1ee5b4640232b8042b9f057564af9a
entity_id: binary_sensor.door_sensor_laundry_room
domain: binary_sensor
sequence:
- type: turn_on
device_id: b78941393030d23c00e20566f531e625
entity_id: light.laundry_room
domain: light
- conditions:
- type: is_not_open
condition: device
device_id: 5e1ee5b4640232b8042b9f057564af9a
entity_id: binary_sensor.door_sensor_laundry_room
domain: binary_sensor
sequence:
- type: turn_off
device_id: b78941393030d23c00e20566f531e625
entity_id: light.laundry_room
domain: light
default: []
mode: single