Having issues with conditions containing 'and'

Hey all,

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'

If I’m reading your intentions correctly, what you want is an “after: sunset” with an before_offset modifier.
See the truth table here for details :

1 Like

That’s strange…

I’ve been in another thread in which the OP said that his & and conditions are throwing the same same complaints.

Maybe it is a bug…

Which install and version are you on?

1 Like

.62 I didn’t try and restart HASS

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.
  • changed the sunset condition to be what you need.

Yes, this was off the build automations GUI. I had to add the ‘and’ stuff in there because it doesn’t support that