None for dictionary value @ data['xy_color']

Hi All,

I can’t get my finger on. Many times this part of automation is working great. Sometimes I get the following error see below the yaml part:

  action:
    - if:
        - "{{ is_state('binary_sensor.kitchen_detection', 'on') }}"
      then:
        - service: light.turn_on
          target:
            entity_id: light.kitchen_neopixel_all
          data:
            xy_color: [0.14, 0.19] # LIGHT BLUE
            brightness_pct: "{{ 20 if is_state('input_boolean.scene_goodnight', 'on') else 100 }}"

      else:
        - service: light.turn_on
          target:
            entity_id: light.kitchen_neopixel_all
          data:
            xy_color: >-
              {% if is_state('input_boolean.scene_daytime', 'on') %}
                [0.70,0.30] 
              {% elif is_state('input_boolean.scene_dinner', 'on') %}
                [0.70,0.30]
              {% elif is_state('input_boolean.scene_evening', 'on') %} 
                [0.70,0.30]
              {% elif is_state('input_boolean.scene_appletv', 'on') %} 
                [0.44,0.52]
              {% elif is_state('input_boolean.scene_tv', 'on') %} 
                [0.14,0.19]
              {% elif is_state('input_boolean.scene_nintendo', 'on') %} 
                [0.22,0.08]
              {% elif is_state('input_boolean.scene_goodnight', 'on') %} 
                [0.70,0.30]
              {% endif %}
            brightness_pct: "{{ 30 if is_state('input_boolean.scene_goodnight', 'on') else 100 }}"

development tool shows me this result: (input_boolean.scene_daytime is on)

[
  0.7,
  0.3
]

When add manual a color to automation its look like this:

xy_color: [0.14, 0.04]

Can this be the problem, because of format output?

Error:

2023-01-31 19:25:59.255 ERROR (MainThread) [homeassistant.components.automation.motion_detection_kitchen_on_off] Motion Detection - Kitchen on/off: If at step 1: Error executing script. Invalid data for call_service at pos 1: None for dictionary value @ data['xy_color']

2023-01-31 19:25:59.260 ERROR (MainThread) [homeassistant.components.automation.motion_detection_kitchen_on_off] Motion Detection - Kitchen on/off: Error executing script. Invalid data for if at pos 1: None for dictionary value @ data['xy_color']

2023-01-31 19:25:59.267 ERROR (MainThread) [homeassistant.components.automation.motion_detection_kitchen_on_off] Error while executing automation automation.motion_detection_kitchen_on_off: None for dictionary value @ data['xy_color']

Can someone help me with this?

Sometimes you are calling the service without providing a value for xy_color.

Try to add an else in the end of your if..elif.. statement and put an default value for when all the options are false (like during a startup when almost everything have unknown state?).

Something like this:

action:
    - if:
        - "{{ is_state('binary_sensor.kitchen_detection', 'on') }}"
      then:
        - service: light.turn_on
          target:
            entity_id: light.kitchen_neopixel_all
          data:
            xy_color: [0.14, 0.19] # LIGHT BLUE
            brightness_pct: "{{ 20 if is_state('input_boolean.scene_goodnight', 'on') else 100 }}"

      else:
        - service: light.turn_on
          target:
            entity_id: light.kitchen_neopixel_all
          data:
            xy_color: >-
              {% if is_state('input_boolean.scene_daytime', 'on') %}
                [0.70,0.30] 
              {% elif is_state('input_boolean.scene_dinner', 'on') %}
                [0.70,0.30]
              {% elif is_state('input_boolean.scene_evening', 'on') %} 
                [0.70,0.30]
              {% elif is_state('input_boolean.scene_appletv', 'on') %} 
                [0.44,0.52]
              {% elif is_state('input_boolean.scene_tv', 'on') %} 
                [0.14,0.19]
              {% elif is_state('input_boolean.scene_nintendo', 'on') %} 
                [0.22,0.08]
              {% elif is_state('input_boolean.scene_goodnight', 'on') %} 
                [0.70,0.30]

              {% else %} 
                [0.70,0.30]

              {% endif %}
            brightness_pct: "{{ 30 if is_state('input_boolean.scene_goodnight', 'on') else 100 }}"

yes!! that’s what it is… I didn’t saw this for long time…

The service is fired already but none of if’s fit and there is no else…

Thanks for pointing me to this. I was forgotten this ‘else’

Thanks

1 Like

I now also see that I can shorten this whole thing:

              {% if is_state('input_boolean.scene_appletv', 'on') %} 
                [0.44,0.52]
              {% elif is_state('input_boolean.scene_tv', 'on') %} 
                [0.14,0.19]
              {% elif is_state('input_boolean.scene_nintendo', 'on') %} 
                [0.22,0.08]
              {% else %} 
                [0.70,0.30]
              {% endif %}
1 Like