Help on for each with jinja template

Hello,

I 'm trying to do a script to reconnect all my wifi devices. I think i am close to the result, but i have a remaining error : “Message malformed: required key not provided @ data[‘sequence’][0][‘repeat’][‘sequence’]”

alias: reconnect_all_wifi
sequence:
  repeat:
    for_each: >-
       {{ states.device_tracker | selectattr('attributes.ap_mac') | map(attribute='entity_id') | list }}"
  sequence:
    - service: unifi.reconnect_client
      data:
        device_id: "{{ device_id(repeat.item) }}"
mode: single

Help, i think i am so close.

Replying to myself : sequence must be at the same level than for_each !

i was looking for a problem in the template.