I’m trying to add an automation to turn on my bedroom lights at night if one of my aqara binary sensors is triggered.
This what I got so far and I don’t understand what is wrong. Please be patient act like I’m 10 or less, please
File editor
/homeassistant/configuration.yaml
# Loads default set of integrations. Do not remove.
default_config:
frontend:
themes: front door trigger themes
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
# bedroom light turn on if front door opens
- id: turn_on_bedroom_lights
alias: Turn On Bedroom Lights When Front Sensor Opens
trigger:
- platform: state
entity_id: binary_sensor.aqara_front_door_2_contact
state: 'on'
action:
- service: automation.turn_on
entity_id:
- tp_link_smart_switch_3ead
- light.smart_rgbtw_bulb_a19_181
- service: light.turn_on
entity_id: light.smart_rgbtw_bulb_a19_181
data:
brightness: 255
rgb_color: [255, 0, 0] # Red color '
/homeassistant/configuration.yaml is the file I’m putting it in, Not even sure that is right?!?!?
Your automation needs to go into automations.yaml.
and not automation.turn_on, but homeassistant.turn_on
# Loads default set of integrations. Do not remove.
# bedroom light turn on if front door opens
- id: turn_on_bedroom_lights
alias: Turn On Bedroom Lights When Front Sensor Opens
trigger:
- platform: state
entity_id: binary_sensor.aqara_front_door_2_contact
state: 'on'
action:
- service: homeassistant.turn_on
entity_id:
- tp_link_smart_switch_3ead
- light.smart_rgbtw_bulb_a19_181
- service: light.turn_on
entity_id: light.smart_rgbtw_bulb_a19_181
data:
brightness: 255
rgb_color: [255, 0, 0] # Red color '
if you’re just learning i would strongly recommend that you start by doing this in the ui, not in the .yaml files.
let the ui guide you. then in the ui, switch it to yaml mode and make any tweaks if you need to.
not only is it easier/faster to learn, it saves you from a lot of mistakes.
this particular thing that you want to do, i believe could be done 100% via the ui.
yes, it’ll be invaluable for you to learn how to do the yaml. so i wouldn’t recommend you totally avoid it. but if you’re starting, let the ui teach you.
it would have saved you from all mistakes above … the switch statement, where the yaml goes, all of it!
in fact, if you’ve got this yaml to work, you might try going and re-implementing it using the ui. then compare the code. you might find it quite helpful in your learning path.
for your case, you just need to do the “when” and “then do” section.
try it… it’ll walk you through it. holler if you need help with it. we’re all happy to help. i do all my automation starting with this. then after getting the bones of it right i edit the yaml (if needed). i bet the vast majority of people do that now…
then when i hit “edit in yaml” : (note ignore the error message in my screenshot, … it’s claiming an error because i’m using your entity id’s… which don’t exist on my system. when you do it on your system, it shouldn’t give you an error… or if it does, it’s actually catching an error):
you might be hitting an error if the code in the automation.yaml that you tried to write by hand is invalid (which it was above). if it’s invalid, when you try to save via the ui, the ui will try to validate the file… and it could barf because you had bad yaml in it to begin with.
try removing all of your hand written code. make the yaml clean and good. the try the ui like i have…
you can use the “check configuration” (do you know how to do this?) capability in developer tools that will check for syntax errors for you: