Automation condition wrong behaviour when multiple entries in state

I have automation that is using state condition and trigger. I read in documentation that if you use list in state condition or from in trigger it will act as or on listed states. Debug I have done on my automation shows otherwise:

result: false
state: cloudy
wanted_state: cloudy,snowy,rainy

I can make it work with multiple triggers and or condition but I would like to know what am I doing wrong. Would be grateful for any feedback

Full automation code:

id: '1638088596150'
alias: Włącz doświetlacz przenośny po zachodzie lub gdy jest ciemno
description: ''
trigger:
  - platform: state
    entity_id: weather.miloszyce
    to: cloudy,snowy,rainy
    for:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  - platform: sun
    event: sunset
    offset: '0'
  - platform: time
    at: '07:00'
condition:
  - condition: time
    after: '07:00'
    before: '21:00'
  - condition: or
    conditions:
      - condition: sun
        after: sunset
      - condition: state
        entity_id: weather.miloszyce
        state: cloudy,snowy,rainy
        for:
          hours: 0
          minutes: 0
          seconds: 0
          milliseconds: 0
action:
  - type: turn_on
    device_id: 29e0f59e4aa58ad01673a4d992bd1405
    entity_id: light.mobile_plant_light
    domain: light
mode: single

Selective reading of the docs is not very helpful :slight_smile:

You are not supplying a list, you are supplying a state of cloudy,snowy,rainy, which will never be true (ETA: turns out this was accidentally true). Here is one of the list examples from the docs, showing proper format:

condition:
  condition: state
  entity_id: alarm_control_panel.home
  state:
    - armed_away
    - armed_home

This will be the format for anything that is defined as a YAML list, you are not able to make up your own format.

This:

to: cloudy,snowy,rainy

is the same as

to: 
  - cloudy
  - snowy
  - rainy

However the GUI editor malforms either of these list formats to:

to: 'cloudy,snowy,rainy'

Which is definitely not a list and not correct.

If you want to use lists you need to use YAML, not the GUI editor.

It looks like this will happen automatically (drop back to YAML editing) in future:

1 Like

Huh, TIL. Never seen that before, thanks for the correction!

I was aware of this and checked in YAML before asking the question here. As you can see in attached automation config quotes were not added but it still didn’t work. I was also assuming that visual editor was the culprit here, but it seems to work correctly in this case. I find it weird

Doesn’t matter the GIU editor adds them.

Ok I will edit with VS Code only and see if it helps. It is weird that yaml editor part of the ui editor and config preview of debugger were not showing the quotes though. Thanks for assistance

I edited automatons.yaml by VS Code to be sure and reloaded automations. Automation still fails on condition check with comma separated list. Fallback to dashed list solves the problem. There might be an issue with condition checker since comma separated list was definately not in quotes this time.

1 Like