Having an issue using And in a condition block. The config checker validates the code, as well as an online YAML checker. I have an automation that turns on the lights in my bedroom off of a motion sensor. Basically i want it to be working 45 mins before sunset, before 21:30 and if the lights are off. Right now, it’s acting like an OR. The automation GUI says Unsupported condition: and. Code block below:
- action:
- data:
brightness_pct: '100'
color_name: white
entity_id: light.master_bedroom
service: light.turn_on
alias: Turn on Master Bedroom lights
condition:
condition: and
conditions:
-
before: sunset
before_offset: 2700
condition: sun
-
before: "22:00:00"
condition: time
-
condition: state
entity_id: light.master_bedroom
state: "off"
id: '1514589477197'
trigger:
- entity_id: sensor.master_bedroom_burglar
from: '0'
platform: state
to: '8'
Is that expected to be in order? Did you use the ‘build automations’ gui in Hass? To me, your yaml looks like a terrible mess because it’s sorted by alphabet.
Try this instead:
- alias: Turn on Master Bedroom lights
trigger:
- platform: state
entity_id: sensor.master_bedroom_burglar
from: 0
to: 8
condition:
condition: and
conditions:
- condition: sun
after: sunset
before_offset: 2700
- condition: time
before: '22:00:00'
- condition: state
entity_id: light.master_bedroom
state: off
action:
- service: light.turn_on
entity_id: light.master_bedroom
data:
brightness_pct: 100
color_name: white
I moved some things around (I may be incorrect with what I changed, but I changed it to be more in line with what i’ve seen in the past):
Removed quotes around numbers that seem like they don’t need them.
Moved entity_id from data section to action section in the action.