Hello all,
After a week of struggeling I hope some can help me with my first automation. I’m trying to convince Home Assistant to turn on al lamp in my garden when I come home after sunset, and to turn off the light after 5 minutes. I read a lot but I cannot get it to work. First, this is my code:
alias: ‘lamp tuinkast aan bij thuiskomst’
initial_state: true
hide_entity: false
trigger:
platform: state
entity_id: device_tracker.ruud_van_gurp
to: ‘home’
condition:
condition: and
conditions:
Invalid config for [automation]: expected a dictionary @ data[‘condition’][0]. Got None
extra keys not allowed @ data[‘action’][0][‘delay’]. Got None
extra keys not allowed @ data[‘conditions’]. Got None
not a valid value for dictionary value @ data[‘action’][0][‘entity_id’]. Got None. (See /config/configuration.yaml, line 105). Please check the docs at Automation - Home Assistant
When I look in configuration.yal, it’s just the standard code at line 105:
105 group: !include groups.yaml
106 automation: !include automations.yaml
107 script: !include scripts.yaml
So, I’m at a loss here. I am fairly new to HA, but eager to learn…. Can someone please help me?
this is mine… I have a solar angle as a sensor, but basically the same as sunset. Double condition as I check to see if the light is already off before trying to turn it on.
- alias: Hallway on when one of us arrives home
initial_state: 'on'
hide_entity: False
trigger:
- platform: state
entity_id: group.helen
from: 'not_home'
to: 'home'
- platform: state
entity_id: group.mark
from: 'not_home'
to: 'home'
condition:
condition: and
conditions:
- condition: numeric_state
entity_id: sensor.solar_angle
below: -1.0
- condition: state
entity_id: light.hallway
state: 'off'
action:
- service: light.turn_on
entity_id: light.hallway
data:
brightness: 200
- delay: '00:10:00'
- service: light.turn_off
entity_id: light.hallway
Thanks for the help, I rewrote my code so it looks like this (thanks to MarkR):
- alias: 'lamp tuinkast aan bij thuiskomst'
initial_state: true
hide_entity: false
trigger:
- platform: state
entity_id: device_tracker.ruud_van_gurp
from: 'not_home'
to: 'home'
condition:
- condition: and
conditions:
platform: sun
after: sunset
- condition: state
entity_id: light.lamp_tuinkast
state: 'off'
action:
- service: light.turn_on
entity_id: light.lamp_voordeur
delay: '00:05:00'
- service: light.turn_off
entity_id: light.lamp_voordeur
Still getting errors though:
Error loading /config/configuration.yaml: while parsing a block collection in “/config/automations.yaml”, line 74, column 7 expected <block end>, but found ‘?’ in “/config/automations.yaml”, line 75, column 7
So, like taikapnu suggested, there might be something wrong in the indention that I’m not aware of; I must admit I have a hard time getting my head around this YAML thing. Still trying to learn…
Are you using a text editor that knows how to correctly format YAML? If you’re not, I suggest you do otherwise editing your configuration files will continue to be a headache.
Your example contains several errors:
Indenting is incorrect in several places.
The first condition is incorrect (platform: sun).
In action: the delay is entered incorrectly.
Try this (it passes Config Check on my system):
- alias: 'lamp tuinkast aan bij thuiskomst'
initial_state: true
hide_entity: false
trigger:
- platform: state
entity_id: device_tracker.ruud_van_gurp
from: 'not_home'
to: 'home'
condition:
condition: and
conditions:
- condition: sun
after: sunset
- condition: state
entity_id: light.lamp_tuinkast
state: 'off'
action:
- service: light.turn_on
entity_id: light.lamp_voordeur
- delay: '00:05:00'
- service: light.turn_off
entity_id: light.lamp_voordeur
Yes, I use Notepad++ and Cloud9 IDE (a Hassio add-on). The problem is more that I’m not really sure where to indent what, so it’s a bit trial and error for me. I copied your code, and still got errors. But after adding two spaces in front of every line it worked!
If anyone has a simple manual on indenting I think I might have less headache in the futere. For now: thanks all (and especially 123) for helping me out!
Congrats! Figuring out yaml and getting your first automation working is a great accomplishment. I know for me, it felt like I had conquered the world.
The indenting for automations will be slightly different if they are stored in configuration.yaml or if they are in a separate file called automations.yaml. The example I gave you was created within an automations.yaml file (and passed Config Check).
In the documentation’s Automations Example, you’ll notice all automations under automation: are indented by at least two spaces. If they were in an automations.yaml file, it wouldn’t be necessary to do that.
Yes, I know exactly what you mean. I don’t think it will be a breeze from now on, but I’m hooked for sure!
The indenting for automations will be slightly different if they are stored in configuration.yaml or if they are in a separate file called automations.yaml .
Yes, I found that out the hard way I use automations.yaml, but everything works only when I use to spaces in front of every line. Else it does’nt passthe config check. For me problems begin below the first line , where (for my feeling) you sometimes use indentions, and sometimes go back to normal indention.
Will do that. I just glanced over it, hoping to sort it out myself, but it is a lot more strict then I realized.
Thanks all for helping this newbie out!
That’s interesting. I didn’t have to do that (for the example I gave you). If you have existing automations that are already indented by two spaces, all additional automations will also have to include the same indenting.
Example 1: No leading indentation (notice the hyphens are not indented).
Well, I do have a first attempt in automation .yaml which have 2 indents at the beginning. I’ll try to remove them and see what the config checker says. Thanks for the explanation, it helps in understanding what I’m doing…