"{{is_state( repeat.item.light)}}' from For Each in Automation results in error

Sorry for the title; I couldn’t think of a better one.

Can anyone explain to me why this:

repeat:
  sequence:
    - if:
        - condition: template
          value_template: "{{ is_state( repeat.item.light , 'on') }}"
      then:
        - action: light.turn_off
          metadata: {}
          data: {}
          target:
            entity_id: "{{repeat.item.light}}"
  for_each: "{{ label_entities('Kitchen Lights')  | select('is_state', 'on') | list }}" 

results in:

if/condition/0

Iteration 1

[If template renders a value equal to true]
Executed: January 14, 2025 at 3:57:09 PM

Error: In ‘template’ condition: UndefinedError: ‘str object’ has no attribute ‘light’ ??

I have a feeling it has to do with the fact that the error says ‘str object’.

thanks in advanced

Why do you even have that condition?

Isn’t repeat.item an entity ID, which doesn’t have a light attribute?

1 Like

Remove .light from repeat.item.light

     - if:
        - condition: template
          value_template: "{{ is_state(repeat.item , 'on') }}"
      then:

Better yet, replace the entire repeat with just this:

- action: light.turn_off
  target:
    entity_id: "{{ label_entities('Kitchen Lights') |  select('is_state', 'on') | list }}"

You are correct.

Thanks