Templating: element has length 1; 2 is required

Hey all,

Slowly I am getting the hang of templating and automations. I do have a interesting item though. I programmed the following code. Well, I made it smaller to make sure that I could find the issue.

Anyway I’m getting the following feedback from the debug log:

Error: dictionary update sequence element #0 has length 1; 2 is required

But why? Where? How?

- id: beweging_gang
  alias: Beweging gang
  description: ''
  trigger:
    platform: state
    entity_id: 
      - binary_sensor.motion_sensor_gang_1_home_security_motion_detection
      - binary_sensor.motion_sensor_gang_2_home_security_motion_detection
    to: 'on'
  action:
    service: scene.turn_on
    target: >
      {%- if is_state('input_boolean.night_switch', 'on') -%}
        entity_id: scene.gang_nachtlampje
      {%- elif is_state('input_boolean.night_switch', 'off') -%}
        entity_id: scene.gang_helder
      {%- else -%}
        entity_id: scene.gang_helder
      {% endif %}

Like this:

  action:
    service: scene.turn_on
    target: 
      entity_id: >
        {%- if is_state('input_boolean.night_switch', 'on') -%}
          scene.gang_nachtlampje
        {%- elif is_state('input_boolean.night_switch', 'off') -%}
          scene.gang_helder
        {%- else -%}
          scene.gang_helder
        {% endif %}

Or you can reduce it to this:

  action:
    service: scene.turn_on
    target: 
      entity_id: "scene.gang_{{ 'nachtlampje' if is_state('input_boolean.night_switch, 'on') else 'helder' }}"

Hey Taras,

Sorry for the late reply! Thank you! This really helps me a lot!

1 Like