Hello, I’m trying to get my first automation working. For the longest time I’ve simply used HA as a simple wireless light controller and status indicator for my phone. I have three door position sensors that I would like to turn on some lights when opened. I’m getting an incorrect configuration error but I’m not sure what it means. Is there something wrong with my syntax?
I am running this in Docker on my NAS. I have an automations.yaml file referenced in my configuration file.
Any thoughts or suggestions would be greatly appreciated but please do keep in mind, I’m no pro at this…again, my first automation attempt.
One additional comment, I’ve been asked this several time and that I should use the two arrow symbol things “preformatted text” but I have no idea how that works or what it’s supposed to do.
Thanks,
- alias: "Back Garage Door Open"
trigger:
platform: state
entity_id: binary_sensor.back_garage_door_sensor
# Optional
from: 'Door Closed'
# Optional
to: 'Door Open'
action:
service: light.turn_on
data:
entity_id:
- switch.back_garage_light_switch
- switch.front_lights_switch
- switch.living_room_light_switch
- alias: "Front Garage Door One Open"
trigger:
platform: state
entity_id: binary_sensor.garage_door_1_sensor
# Optional
from: 'Door Closed'
# Optional
to: 'Door Open'
action:
service: light.turn_on
data:
entity_id:
- switch.back_garage_light_switch
- switch.front_lights_switch
- switch.living_room_light_switch
- alias: "Garage Door Two Open"
trigger:
platform: state
entity_id: binary_sensor.garage_door_2_sensor
# Optional
from: 'Door Closed'
# Optional
to: 'Door Open'
action:
service: light.turn_on
data:
entity_id:
- switch.back_garage_light_switch
- switch.front_lights_switch
- switch.living_room_light_switch
Typically the domain of your service needs to match the domain of your entities. More specifically, you need to use switch.turn_on to turn on switches, even though the switches control lights.
You could also use home_assistant.turn_on , which can control items from a few different domains.
I really appreciate the reply but that talked right over my head. I’m not sure what you mean by the domain of service and domain of entities.
I’ve updated the automation file and now when I do a configuration check there are no errors but it still doesn’t work when I trigger any of the sensors.
- alias: "Back Garage Door Open"
trigger:
platform: state
entity_id: binary_sensor.back_garage_door_sensor
# Optional
from: 'Door Closed'
# Optional
to: 'Door Open'
action:
service: switch.turn_on
data:
entity_id:
- switch.back_garage_light_switch
- switch.front_lights_switch
# - switch.living_room_light_switch
- alias: "Front Garage Door One Open"
trigger:
platform: state
entity_id: binary_sensor.garage_door_1_sensor
# Optional
from: 'Door Closed'
# Optional
to: 'Door Open'
action:
service: switch.turn_on
data:
entity_id:
- switch.back_garage_light_switch
- switch.front_lights_switch
# - switch.living_room_light_switch
- alias: "Garage Door Two Open"
trigger:
platform: state
entity_id: binary_sensor.garage_door_2_sensor
# Optional
from: 'Door Closed'
# Optional
to: 'Door Open'
action:
service: switch.turn_on
data:
entity_id:
- switch.back_garage_light_switch
- switch.front_lights_switch
# - switch.living_room_light_switch
The domain is just the first part of the entity id or service, e.g. “light,” “switch,” “lock,” etc.
The other folks have already made the recommendation that I would.
I would also get rid of the “from” line in your triggers. Not because it’s definitely wrong, but because it’s probably unnecessary.
I know figuring out this automation right now feels like a pain in the neck, but you’ll get a hang of it (and the troubleshooting tools like the dev tools) in no time.
Once again, than you all very much. I believe that I understand the suggestions you’re making and I have further revised the automations.yaml file. The triggers (doors) when opened change from “off” to “on”. I made this change but still no action taken to the lights switches. I also removed the “from” statement. My new file shown below;
- alias: "Back Garage Door Open"
trigger:
platform: state
entity_id: binary_sensor.back_garage_door_sensor
to: "on"
action:
service: switch.turn_on
data:
entity_id:
- switch.back_garage_light_switch
- switch.front_lights_switch
- switch.front_lights_switch
- alias: "Front Garage Door One Open"
trigger:
platform: state
entity_id: binary_sensor.garage_door_1_sensor
to: "on"
action:
service: switch.turn_on
data:
entity_id:
- switch.back_garage_light_switch
- switch.front_lights_switch
- switch.living_room_light_switch
- alias: "Garage Door Two Open"
trigger:
platform: state
entity_id: binary_sensor.garage_door_2_sensor
to: "on"
action:
service: switch.turn_on
data:
entity_id:
- switch.back_garage_light_switch
- switch.front_lights_switch
- switch.front_lights_switch
I’m not sure what happened or why. I came home this afternoon, pulled into the garage and noticed that the lights in the house were on…a quick check and voila! It seems to be operational.
Thank you very much to those who helped. I very seriously came close to abandoning this one again. I couldn’t be more pleased. Now while I’m typing, I’m realizing the little monster I’ve created…every time I leave the house through the garage, my lights will turn on and stay on until I turn them off. . In any case…a great victory. Thank you!
One additional interesting thing to note, now I do also have a button to “reload automations”.
For the other people starting out. Here is my “automations.yaml” file.
- alias: "Back Garage Door Open"
trigger:
platform: state
entity_id: binary_sensor.back_garage_door_sensor
to: "on"
action:
service: switch.turn_on
data:
entity_id:
- switch.back_garage_light_switch
- switch.front_lights_switch
- switch.front_lights_switch
- alias: "Front Garage Door One Open"
trigger:
platform: state
entity_id: binary_sensor.garage_door_1_sensor
to: "on"
action:
service: switch.turn_on
data:
entity_id:
- switch.back_garage_light_switch
- switch.front_lights_switch
- switch.living_room_light_switch
- alias: "Garage Door Two Open"
trigger:
platform: state
entity_id: binary_sensor.garage_door_2_sensor
to: "on"
action:
service: switch.turn_on
data:
entity_id:
- switch.back_garage_light_switch
- switch.front_lights_switch
- switch.front_lights_switch
You may wish to review the steps you performed to determine what was responsible for making it work. Without this knowledge, the scenario is likely to repeat itself and cause you more frustration.
Now you need a timer to shut the lights off. For example, opening the door not only turns on the light but also starts a 5 minute timer. When the timer expires, it turns off the light.