Set dynamic attributes to a var

Hello,

I’d want to set var attributes but their names must be dynamic : zonename: [‘person1’, ‘person2’].

My code :

action: variable.update_sensor
metadata: {}
data:
  replace_attributes: true
  attributes: >-
    {% set ns=namespace() %}
    {%for zone in states.zone|list%}
    {%set ns.liste=[]%}
      {%for personne in expand(states.person)|selectattr("state","eq",zone.name)|list%}
        {% set ns.liste=ns.liste+[personne.name]%}
      {%endfor%}
    {%set zone_name=zone.name%}
    {%if zone_name=="Maison"%}{%set zone_name="home"%}{%endif%}
    {{zone_name}}: {{ns.liste}}
    {%endfor%}
  value: test
target:
  entity_id: sensor.presence

It “works” in dev’ tools :

action: variable.update_sensor
metadata: {}
data:
  replace_attributes: true
  attributes: >-
    
    
    
      
        
      
        
      
    
    
    work: ['Fred', 'David']
    
    
      
    
    
    home: []
    
  value: test
target:
  entity_id: sensor.presence

But not in automation : expected dict for dictionary value @ data[‘attributes’]. Got None :confused:

Could you please help me ?

Are you using the Variables custom integration? If so, is it a forked version as the original hasn’t been updated in quite some time.

I’m using forked version : GitHub - enkama/hass-variables: Home Assistant variables component