Automation action or condition yaml

Hello

I created an automation using the GUI that seemed to need a or condition in the actions section. I tried adding that in the file editor. The file editor says OK to the formatting but i’m getting this in the log:

 Logger: homeassistant.config Source: config.py:454
First occurred: 15:19:27 (3 occurrences)
 Last logged: 15:24:45 Invalid config for [automation]: Expected a dictionary @ data['action'][0]['conditions'][8]. Got None Expected a dictionary @ data['action'][0]['conditions'][9]. Got None Unexpected value for condition: 'None'. Expected and, device, not, numeric_state, or, state, sun, template, time, trigger, zone @ data['action'][0]['conditions'][1]. Got None Unexpected value for condition: 'None'. Expected and, device, not, numeric_state, or, state, sun, template, time, trigger, zone @ data['action'][0]['conditions'][3]. Got None Unexpected value for condition: 'None'. Expected and, device, not, numeric_state, or, state, sun, template, time, trigger, zone @ data['action'][0]['conditions'][5]. Got None Unexpected value for condition: 'None'. Expected and, device, not, numeric_state, or, state, sun, template, time, trigger, zone @ data['action'][0]['conditions'][7]. Got None. (See /config/configuration.yaml, line 9). 

My automation looks like this:

  ## lysrutine
- id: '1644736228461'
  alias: Night Mode off - Lysrutine
  description: ''
  trigger:
  - platform: state
    entity_id: input_boolean.godnat
    from: 'on'
    to: 'off'
  - platform: state
    entity_id: group.family
    from: not_home
    to: home
  - type: motion
    platform: device
    device_id: 51b5aa9704b060f0587e49f5f929a27b
    entity_id: binary_sensor.bryggers_motion_01_occupancy
    domain: binary_sensor
  - type: motion
    platform: device
    device_id: cfdd0b95cfc640fded81662d57986268
    entity_id: binary_sensor.gang_motion_01_occupancy
    domain: binary_sensor
  - type: motion
    platform: device
    device_id: b7393818d3b1c99a49c951c77da86718
    entity_id: binary_sensor.koekken_motion_01_occupancy
    domain: binary_sensor
  condition:
  - condition: state
    entity_id: group.family
    state: home
  - condition: state
    entity_id: input_boolean.godnat
    state: 'off'
  - condition: state
    entity_id: input_boolean.bypass_light_routine
    state: 'off'
  action:
    - condition: or
      conditions:
        - condition: time
          after: 05:00
          before: 07:54
        - scene: scene.morgenlys  ## <-- what i think is the problematic part
        - condition: time
          after: 07:55
          before: 09:15
        - scene: scene.formiddagslys
        - condition: time
          after: 09:16
          before: '19:30'
        - scene: scene.dagslys
        - condition: time
          after: '19:31'
          before: 03:00
        - service: light.turn_on
          data:
          transition: 300
          kelvin: 2200
          brightness_pct: 55
          target:
          entity_id:
        - light.stue_lights_zgrp
        - light.koekken_lights_zgrp
  mode: single

I tried added the indents i could think of to the actions section, but i cant figure it out.
Help is appreciated. Thank you.

it looks as if you are trying to control which scene is activated by using the conditions before them.

as you found out you can’t do it like that.

there are a few ways you could do it but instead of using conditions directly in the actions (which won’t work) you should use a “choose:” block and put those as conditions in there to decide which scenes to activate.

A scene service call is not a valid condition.

As @finity posted, you need to use a Choose action to handle if-then type logic for different actions.

## lysrutine
- id: '1644736228461'
  alias: Night Mode off - Lysrutine
  description: ''
  trigger:
  - platform: state
    entity_id: input_boolean.godnat
    from: 'on'
    to: 'off'
  - platform: state
    entity_id: group.family
    from: not_home
    to: home
  - type: motion
    platform: device
    device_id: 51b5aa9704b060f0587e49f5f929a27b
    entity_id: binary_sensor.bryggers_motion_01_occupancy
    domain: binary_sensor
  - type: motion
    platform: device
    device_id: cfdd0b95cfc640fded81662d57986268
    entity_id: binary_sensor.gang_motion_01_occupancy
    domain: binary_sensor
  - type: motion
    platform: device
    device_id: b7393818d3b1c99a49c951c77da86718
    entity_id: binary_sensor.koekken_motion_01_occupancy
    domain: binary_sensor
  condition:
  - condition: state
    entity_id: group.family
    state: home
  - condition: state
    entity_id: input_boolean.godnat
    state: 'off'
  - condition: state
    entity_id: input_boolean.bypass_light_routine
    state: 'off'
  action:
    - choose:
      - conditions:
          - condition: time
            after: 05:00
            before: 07:54
        sequence:
          - scene: scene.morgenlys
      - conditions:
          - condition: time
            after: 07:55
            before: 09:15
        sequence:
          - scene: scene.formiddagslys
      - conditions:
          - condition: time
            after: 09:16
            before: '19:30'
        sequence:
          - scene: scene.dagslys
      - conditions:
          - condition: time
            after: '19:31'
            before: 03:00
        sequence:
          - service: light.turn_on
            data:
              transition: 300
              kelvin: 2200
              brightness_pct: 55
            target:
              entity_id:
                - light.stue_lights_zgrp
                - light.koekken_lights_zgrp
  mode: single
1 Like

Thank you for the replies. I think i get what you are saying.

I copied the code you posted @Didgeridrew - but i get the following error:

Logger: homeassistant.config
Source: config.py:454
First occurred: 20:40:52 (1 occurrences)
Last logged: 20:40:52

Invalid config for [automation]: expected a dictionary for dictionary value @ data['action'][0]['choose'][0]['sequence'][0]['target']. Got None. (See /config/configuration.yaml, line 9).

That’s due to a minor typo. Just indent this line with another two spaces:

entity_id: scene.morgenlys
2 Likes

Thank you.
I’m trying to understand it.
Why are these different if you don’t mind?

  action:
    - choose:
      - conditions:
        - condition: time
          after: 05:00
          before: 07:54
        sequence:
         - service: scene.turn_on
           target:
             entity_id: scene.morgenlys ## <-- here 
      - conditions:
        - condition: time
          after: 07:55
          before: 09:15
        sequence:
         - scene: scene.formiddagslys ## <-- and here

That’s just two ways of doing the same thing. If you wish, both can use the same style.

Awesome. I like having the option do to a transition with the service option. I’ll go with that.
Thank you all!

If Didgeridrew’s example solved your problem, don’t forget to mark it with the Solution tag. For more information, refer to guideline 21 in the FAQ.

You should mark Didgeridrew’s post with the Solution tag, not my post (which only identifies a minor error and doesn’t contain the entire solution). Only one post in the entire thread can be marked as the Solution.