Choose sequence - missing key not provided

Hi Folks,
pretty new to HA, I want to program an automation which switches two areas of light to on-off, off-on, on-on, off-off using choose sequence syntax and do not find the error.
Enclosed the first part of the choose:

alias: Gartenbleuchtung Ein
description: “”
triggers:

  • domain: mqtt
    device_id: 04b8c76654e541c8174599eda39832b0 #“Ikea Styrbar”
    type: action
    subtype: “on”
    trigger: device
    actions:
  • choose:
    • conditions:
      • condition: “{{ is_state(‘light.gartenlicht_kirschbaum’, ‘off’) and is_state(‘light.terrassenlicht_wohnzimmer’, ‘off’) }}”
        sequence:
        • action: light.turn_on
          target:
          area_id: terrasse

Any hints and tips for me?

Thanx
-Mike

First: format your code properly
f6be36681e0da431418ec7781fb6c62712941803

Second : show the whole automation

1 Like

Hello Francis,
thanx for the suggestions. Here’s the complete code.

The error message is: Message malformed: required key not provided @ data[‘actions’][0][‘choose’][0][‘sequence’]

alias: Gartenbleuchtung Ein
description: ""
triggers:
  - domain: mqtt
    device_id: 04b8c76654e541c8174599eda39832b0 #"Ikea Styrbar"
    type: action
    subtype: "on"
    trigger: device
actions:
  - choose:
    - conditions: 
      - condition: "{{ is_state('light.gartenlicht_kirschbaum', 'off') and is_state('light.terrassenlicht_wohnzimmer', 'off') }}"
        sequence:
        - action: light.turn_on
          target: 
            area_id: terrasse
    - conditions: >
       " {{ is_state ('light.gartenlicht_kirschbaum', 'off') and
           is_state('light.terrassenlicht_wohnzimmer', 'on') }}"
      sequence:
        - action: light.turn_on
          data: {}
          target:
            area_id: gartenlicht
    - conditions: >
        "{{ is_state ('light.gartenlicht_kirschbaum', 'on') and
           is_state('light.terrassenlicht_wohnzimmer', 'on') }}"
      sequence:
        - action: light.turn_off
          data: {}
          target:
            area_id: terrasse
    - conditions: >
        "{{ is_state ('light.gartenlicht_kirschbaum', 'on') and
           is_state('light.terrassenlicht_wohnzimmer', 'off') }}"
      sequence:
        - action: light.turn_off
          data: {}
          target:
            area_id: terrasse
        - action: light.turn_off
          data: {}
          target:
            area_id: gartenlicht
mode: single

You have an indentation error. The three lines below the first sequence line need two more spaces at the beginning of each of them.

As @atlflyer mentioned, the first option has an indentation error that makes sequence a child of condition instead of conditions. But, that condition key is also extraneous, and will throw a different error once you fix the indentation of sequence.

All the other conditions entries are using both multi-line quote indicators, >, and quote marks, " … so the templates are not being rendered, they are being treated as literal strings. Use one or the other, not both.


Since you are new to HA, it might be better for you to establish a base of knowledge by using the Automation Editor and basic components like State conditions before you jump into the more nuanced methods like short-hand template condition format.

...
actions:
  - choose:
      - conditions: 
          - condition: state
            entity_id: 
              - light.gartenlicht_kirschbaum
              - light.terrassenlicht_wohnzimmer
            state: 'off'
        sequence:
          - action: light.turn_on
            target: 
              area_id: terrasse
....

Thank you for the analysis and advices.
Later I’ll get in the pc and try to fix it.
-Mike

Thanx again,
your hints and tips did help me, fix the automation. Here’s the final code:
-Mike

alias: Gartenbleuchtung Ein
description: "Durchschalten der Gerätegruppe Terrasse und Gartenlicht"
triggers:
  - domain: mqtt
    device_id: 04b8c76654e541c8174599eda39832b0 #"Ikea Styrbar"
    type: action
    subtype: "on"
    trigger: device
actions:
  - choose:
    - conditions: 
      - condition: state
        entity_id: light.gartenlicht_kirschbaum
        state: 'off'
      - condition: state
        entity_id: light.terrassenlicht_wohnzimmer
        state: 'off'
      sequence:
        - action: light.turn_on
          target: 
            area_id: terrasse
    - conditions: 
      - condition: state
        entity_id: light.gartenlicht_kirschbaum
        state: 'off'
      - condition: state
        entity_id: light.terrassenlicht_wohnzimmer
        state: 'on'
      sequence:
        - action: light.turn_on
          target:
            area_id: gartenlicht
    - conditions: 
      - condition: state
        entity_id: light.gartenlicht_kirschbaum
        state: 'on'
      - condition: state
        entity_id: light.terrassenlicht_wohnzimmer
        state: 'on'
      sequence:
        - action: light.turn_off
          target:
            area_id: terrasse
    - conditions: 
      - condition: state
        entity_id: light.gartenlicht_kirschbaum
        state: 'on'
      - condition: state
        entity_id: light.terrassenlicht_wohnzimmer
        state:  'off'
      sequence:
        - action: light.turn_off
          target:
            area_id: terrasse
        - action: light.turn_off
          target:
            area_id: gartenlicht
mode: single