Automation Help - Door Close turn off hall lights

Need help with my automations…only about half of them are working/showing up in the web interface for HA. Looks to be all the automations that have conditions in them; so that is probably where I’m failing. Weirdest thing is this automation WORKED for like 2 weeks after I wrote it and now won’t work anymore without any changes to the config. Check out my code --> http://hastebin.com/pupisaruse.pl

What the heck am I doing wrong…this seems so straight forward.

thanks for the troubleshooting help!

Error received now that I’ve put the .yaml direct rather than running via !include

voluptuous.error.MultipleInvalid: not a valid value for dictionary value @ data['conditions'][0]['condition']

Saw this yesterday and for some reason it popped back in my head today as I was working on my HA.

Are you conditions being met? Are both lights on and its after sunset? If anyone of those isn’t met (since you are using and) I don’t think the condition will run. So if its before sunset or one of the lights is already off the automation won’t trigger I believe.

Have you changed anything else in your config? Maybe tweaked the name of the sensor or the light(s).

Finally, unless you have a lot of config text I would post it in the forum. My experience on other forums is people are eihter lazy and won’t open the link or are worried about malicious links and generally avoid them.

All the conditions are being met. The automations aren’t being accepted by HA as in the automations that have conditions are not showing up on the automation card like the other “non-conditioned” automations do. So there is something wrong with how I am writing the conditions section, even though I just copied and pasted from the example and tweaked entity names. All entity names have been checked an innumerable number of times…

Here is the config file so as not to require a link;

alias: "Bedroom Door Open Lights On"
trigger: 
  platform: state
  entity_id: binary_sensor.bedroom_door_sensor
  state: 'off'
condition:
  condition: and
  conditions:
    - condition: state
      entity_id: sun.sun
      state: 'below_horizon'
    - condition: state
      entity_id: light.stairs
      state: on
    - condition: state
      entity_id: light.upstairs_hall
      state: on
action: 
  - service: light.turn_off
    entity_id: light.stairs
  - service: light.turn_off
    entity_id: light.upstairs_hall

Also; for the record when I comment out the extra conditions --> no problem, when I comment out to use only a single condition --> no problem, when I use either an AND or an OR with multiple conditions like above code —> Problem.

Using most up to date Docker Image and utilizing !include_dir_list with individual .yaml’s for each automation in the directory. Context for the spacing seen in the code above.

I am stumped. One last long shot is the state of your lights. Is ‘on’ the correct state? Turn the light on and check its state. Pay attention to the capitalization also as HA is case sensitive.

When you find the solution please post it up, Ill be interested to see what it was.

I’m not sure if it makes a difference, but all my state values are quoted in conditions

[quote="ironlion27, post:5, topic:5851"]
- condition: state
      entity_id: light.upstairs_hall
      state: **'on'**
[/quote]
1 Like

Quote your ‘states’

- alias: "Bedroom Door Open Lights On"
  trigger: 
   platform: state
   entity_id: binary_sensor.bedroom_door_sensor
   state: 'off'
  condition:
 - condition: state
   entity_id: sun.sun
   state: 'below_horizon'
 - condition: state
   entity_id: light.stairs
   state: 'on'
 - condition: state
   entity_id: light.upstairs_hall
   state: 'on'
  action: 
- service: light.turn_off
  entity_id: light.stairs, light.upstairs_hall

same outcome by adding ‘states’ so that wasn’t the issue. I see you got rid of the conditions bit of code too which is not how documentation recommends .

condition: and
**conditions:**
  -condition: state

if you dont like my changes this works as well. Condtions default to “and” so you only have to specifiy Or.

alias: "Bedroom Door Open Lights On"
trigger: 
  platform: state
  entity_id: binary_sensor.bedroom_door_sensor
  state: 'off'
condition:
 condition: and
 conditions:
    - condition: state
      entity_id: sun.sun
      state: 'below_horizon'
    - condition: state
      entity_id: light.stairs
      state: 'on'
    - condition: state
      entity_id: light.upstairs_hall
      state: 'on'
action: 
  - service: light.turn_off
    entity_id: light.stairs
  - service: light.turn_off
    entity_id: light.upstairs_hall

copied and pasted your code overtop of what I had there; got the following error:

homeassistant.bootstrap: Invalid config for [automation]: expected a dictionary.

I tried to match your spacing can you copy it again?

got a ‘duplicate key’ error on second condition: line so I moved that out 2 spaces and restarted. We are back to where we started with:

voluptuous.error.MultipleInvalid: not a valid value for dictionary value @ data['conditions'][1]['condition']

Move condition: and and conditions out one space from condition:

condition
 condition: and
 conditions:

@rabittn I think you may just be THE MAN! I restarted my docker and the automation in question is present in my ‘automation card’ now along with 4 other automations that didn’t show up previously…probably because they were alphabetically named after this failed .yaml file.

I ran a diff check on the origional and the current .yaml to see what the key change was:

https://www.diffchecker.com/UzNAcXKa

Looks to be as simple and silly as the ‘states’ as mentioned above.

This evening once the sun.sun is ‘below_horizon’ I’ll see if all these actually function IRL and will report back.

You don’t have to wait until sundown. You can manually spoof the state using the <> screen. Click on the entity you want to fiddle with, make your changes and hit “set state.”

everything worked!