Error creating automation with nested IF actions

I have an automation that is intended to set the color of a scene controller button LED based on values of other switches.

I originally had it “mostly” working with just a series of if-thens for the actions using this config.

alias: Set Kitchen Zooz Scene 2 LED Color
description: ""
trigger:
  - platform: event
    event_type: set_zooz_scene2_color
condition: []
action:
  - if:
      - condition: state
        entity_id: switch.second_floor_lights
        state: "on"
    then:
      - device_id: 5416582252fbb94e976a1524c3ea804e
        domain: zwave_js
        type: set_config_parameter
        parameter: 8
        bitmask: null
        subtype: 8 (LED Indicator Color (Button 2))
        value: 3
  - if:
      - condition: state
        entity_id: switch.first_floor_lights
        state: "on"
    then:
      - device_id: 5416582252fbb94e976a1524c3ea804e
        domain: zwave_js
        type: set_config_parameter
        parameter: 8
        bitmask: null
        subtype: 8 (LED Indicator Color (Button 2))
        value: 2
  - if:
      - condition: state
        entity_id: switch.basement_lights
        state: "on"
    then:
      - device_id: 5416582252fbb94e976a1524c3ea804e
        domain: zwave_js
        type: set_config_parameter
        parameter: 8
        bitmask: null
        subtype: 8 (LED Indicator Color (Button 2))
        value: 1
mode: single

But this did not handle the condition if ALL of the switches are off. So I tried to nest these if-thens into another if-then which first checks if any of then are on, and then sets the color base don the floor, else (none of then are “on”) set the color to white.

alias: Set Kitchen Zooz Scene 2 LED Color
description: ""
trigger:
  - platform: event
    event_type: set_zooz_scene2_color
condition: []
action:
  - if:
      - condition: or
        conditions:
          - condition: state
            entity_id: switch.second_floor_lights
            state: "on"
          - condition: state
            entity_id: switch.first_floor_lights
            state: "on"
          - condition: state
            entity_id: switch.basement_lights
            state: "on"
    then:
      - if:
          - condition: state
            entity_id: switch.basement_lights
            state: "on"
        then:
          - device_id: 5416582252fbb94e976a1524c3ea804e
            domain: zwave_js
            type: set_config_parameter
            parameter: 8
            bitmask: null
            subtype: 8 (LED Indicator Color (Button 2))
            value: 1
      - if:
          - condition: state
            entity_id: switch.first_floor_lights
            state: "on"
        then:
          - device_id: 5416582252fbb94e976a1524c3ea804e
            domain: zwave_js
            type: set_config_parameter
            parameter: 8
            bitmask: null
            subtype: 8 (LED Indicator Color (Button 2))
            value: 2
      - if:
          - condition: state
            entity_id: switch.second_floor_lights
            state: "on"
        then:
          - device_id: 5416582252fbb94e976a1524c3ea804e
            domain: zwave_js
            type: set_config_parameter
            parameter: 8
            bitmask: null
            subtype: 8 (LED Indicator Color (Button 2))
            value: 3
    else:
      - device_id: 5416582252fbb94e976a1524c3ea804e
        domain: zwave_js
        type: set_config_parameter
        parameter: 8
        bitmask: null
        subtype: 8 (LED Indicator Color (Button 2))
mode: single

However, I am getting the following error trying to save this automation.

Message malformed: not a valid value for dictionary value @ data[‘type’]

If I am going about this all wrong (very likely), by all means please advise. But I would still like to understand this error message a little better, regardless.

Don’t nest If/Then actions, use the Choose action with a default action to handle when all switches are off.

action:
  - choose:
    - conditions:
        - condition: state
          entity_id: switch.second_floor_lights
          state: "on"
      sequence:
        - device_id: 5416582252fbb94e976a1524c3ea804e
          domain: zwave_js
          type: set_config_parameter
          parameter: 8
          bitmask: null
          subtype: 8 (LED Indicator Color (Button 2))
          value: 3
    - conditions:
        - condition: state
          entity_id: switch.first_floor_lights
          state: "on"
      sequence:
        - device_id: 5416582252fbb94e976a1524c3ea804e
          domain: zwave_js
          type: set_config_parameter
          parameter: 8
          bitmask: null
          subtype: 8 (LED Indicator Color (Button 2))
          value: 2
    - conditions:
        - condition: state
          entity_id: switch.basement_lights
          state: "on"
      sequence:
        - device_id: 5416582252fbb94e976a1524c3ea804e
          domain: zwave_js
          type: set_config_parameter
          parameter: 8
          bitmask: null
          subtype: 8 (LED Indicator Color (Button 2))
          value: 1
    default:
      - device_id: 5416582252fbb94e976a1524c3ea804e
        domain: zwave_js
        type: set_config_parameter
        parameter: 8
        bitmask: null
        subtype: 8 (LED Indicator Color (Button 2))
mode: single

Thank you. I tried that and got the same error. However, I believe I found the issue.

The “default” action I was going for (either with the “nested if” or the “choose”) was to set the LED color to white (value: 0), which is the default setting for that parameter. I was doing all of this in the WebUI rather than editing the YAML directly; and for some reason the WebUI was not setting a “value” if I set the color to white. I believe this is because white is the default (0) value.

Anyway, by manually adding a “value: 0” to the default action I was able to get it to accept the config; either with a nested if or with a choose.

So my final YAML using the Choose option looks like this:

alias: Set Kitchen Zooz Scene 2 LED Color
description: ""
trigger:
  - platform: event
    event_type: set_zooz_scene2_color
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: switch.basement_lights
            state: "on"
        sequence:
          - device_id: 5416582252fbb94e976a1524c3ea804e
            domain: zwave_js
            type: set_config_parameter
            parameter: 8
            bitmask: null
            subtype: 8 (LED Indicator Color (Button 2))
            value: 1
      - conditions:
          - condition: state
            entity_id: switch.first_floor_lights
            state: "on"
        sequence:
          - device_id: 5416582252fbb94e976a1524c3ea804e
            domain: zwave_js
            type: set_config_parameter
            parameter: 8
            bitmask: null
            subtype: 8 (LED Indicator Color (Button 2))
            value: 2
      - conditions:
          - condition: state
            entity_id: switch.second_floor_lights
            state: "on"
        sequence:
          - device_id: 5416582252fbb94e976a1524c3ea804e
            domain: zwave_js
            type: set_config_parameter
            parameter: 8
            bitmask: null
            subtype: 8 (LED Indicator Color (Button 2))
            value: 3
    default:
      - device_id: 5416582252fbb94e976a1524c3ea804e
        domain: zwave_js
        type: set_config_parameter
        parameter: 8
        bitmask: null
        subtype: 8 (LED Indicator Color (Button 2))
        value: 0  //     <<<<<<<-------------  I had to add this line
mode: single