List is overwritten again and again instead of being expanded

following code with a lot of debugging.
In the loop there is a hit for the respective tag.
This is also added to the list.
Unfortunately not + but overwritten.

So the list is empty in the end.

It is only due to this line:
{% set today_values = today_values + [[ts_int | timestamp_custom(‘%H:%M’, false), values[0]]] %}

What is wrong here?

{% set start_of_today = as_timestamp(now().replace(hour=0, minute=0, second=0, microsecond=0)) | int %}
{% set end_of_today = as_timestamp(now().replace(hour=23, minute=59, second=59, microsecond=0)) | int %}
{% set today_values = [] %}
{% set data = state_attr('sensor.solarprognose_raw_json_hourly', 'data') %}
Start of Today: {{ start_of_today }}
End of Today: {{ end_of_today }}
Data: {{ data }}

{% if data %}
  {% for ts, values in data.items() %}
    {% set ts_int = ts | int %}
    Prüfe Timestamp: {{ ts_int }} ({{ ts_int | timestamp_custom('%d.%m.%Y %H:%M', false) }})
    {% if ts_int >= start_of_today and ts_int <= end_of_today %}
      Treffer: {{ ts_int | timestamp_custom('%H:%M', false) }} mit Wert: {{ values[0] }}
      {% set today_values = today_values + [[ts_int | timestamp_custom('%H:%M', false), values[0]]] %}
      Füge in Liste hinzu: {{ today_values }}
    {% else %}
      Kein Treffer: {{ ts_int | timestamp_custom('%H:%M', false) }}
    {% endif %}
  {% endfor %}
{% endif %}
Finale Liste: {{ today_values }}
Start of Today: 1736204400
End of Today: 1736290799
Data: {'1736233200': [0, 0], '1736236800': [0.111, 0.111], '1736240400': [0.812, 0.923], '1736244000': [2.177, 3.1], '1736247600': [3.568, 6.668], '1736251200': [3.87, 10.538], '1736254800': [3.835, 14.373], '1736258400': [2.66, 17.033], '1736262000': [0, 17.033], '1736319600': [0, 0], '1736323200': [0.223, 0.223], '1736326800': [1.522, 1.745], '1736330400': [3.266, 5.011], '1736334000': [4.659, 9.67], '1736337600': [5.5, 15.17], '1736341200': [5.041, 20.211], '1736344800': [3.749, 23.96], '1736348400': [0, 23.96], '1736409600': [0, 0], '1736413200': [0.304, 0.304], '1736416800': [0.99, 1.294], '1736420400': [1.586, 2.88], '1736424000': [1.935, 4.815], '1736427600': [1.972, 6.787], '1736431200': [1.572, 8.359], '1736434800': [0, 8.359], '1736492400': [0, 0], '1736496000': [0.111, 0.111], '1736499600': [0.913, 1.024], '1736503200': [1.781, 2.805], '1736506800': [2.478, 5.283], '1736510400': [3.259, 8.542], '1736514000': [2.959, 11.501], '1736517600': [2.177, 13.678], '1736521200': [0, 13.678], '1736578800': [0, 0], '1736582400': [0.111, 0.111], '1736586000': [0.913, 1.024], '1736589600': [2.078, 3.102], '1736593200': [2.974, 6.076], '1736596800': [3.667, 9.743], '1736600400': [3.506, 13.249], '1736604000': [2.66, 15.909], '1736607600': [0, 15.909]}


  
    
    Prüfe Timestamp: 1736233200 (07.01.2025 07:00)
    
      Treffer: 07:00 mit Wert: 0
      
      Füge in Liste hinzu: [['07:00', 0]]
    
  
    
    Prüfe Timestamp: 1736236800 (07.01.2025 08:00)
    
      Treffer: 08:00 mit Wert: 0.111
      
      Füge in Liste hinzu: [['08:00', 0.111]]
    
  
    
    Prüfe Timestamp: 1736240400 (07.01.2025 09:00)
    
      Treffer: 09:00 mit Wert: 0.812
      
      Füge in Liste hinzu: [['09:00', 0.812]]
    
  [..] + 20 mor  rows
 


    
    Prüfe Timestamp: 1736319600 (08.01.2025 07:00)
    
      Kein Treffer: 07:00
    

  [..] + 20 mor  rows
  

Finale Liste: []

Ergebnistyp: string

Dieses Template wird zu Beginn jeder Minute aktualisiert.

Dieses Template abonniert die folgenden Ereignisse zur Zustandsänderung:

    Entität: sensor.solarprognose_raw_json_hourly

Hi the list needs to be defined before the FOR in namespace.
for example:

set ns = namespace(today_values =[])
for
...
set ns.today_values  = ns.today_values  + ...

edit: NOW I have understood it

{% set today_values = [] %}
vs.
{% set ns = namespace(today_values=[]) %}

That’s how it works.

THANKS

{% set start_of_today = as_timestamp(now().replace(hour=0, minute=0, second=0, microsecond=0)) | int %}
{% set end_of_today = as_timestamp(now().replace(hour=23, minute=59, second=59, microsecond=0)) | int %}
{% set ns = namespace(today_values=[]) %}
{% set data = state_attr('sensor.solarprognose_raw_json_hourly', 'data') %}

Start of Today: {{ start_of_today }}
End of Today: {{ end_of_today }}
Data: {{ data }}

{% if data %}
  {% for ts, values in data.items() %}
    {% set ts_int = ts | int %}
    Prüfe Timestamp: {{ ts_int }} ({{ ts_int | timestamp_custom('%d.%m.%Y %H:%M', false) }})
    {% if ts_int >= start_of_today and ts_int <= end_of_today %}
      Treffer: {{ ts_int | timestamp_custom('%H:%M', false) }} mit Wert: {{ values[0] }}
      {% set ns.today_values = ns.today_values + [[ts_int | timestamp_custom('%H:%M', false), values[0]]] %}
    {% else %}
      Kein Treffer: {{ ts_int | timestamp_custom('%H:%M', false) }}
    {% endif %}
  {% endfor %}
{% endif %}
Finale Liste: {{ ns.today_values }}

ok, nice :slight_smile:

yes… sorry. i understood it (later) and edited my post…,

thank you very much. Works now

P.s. You are better than ChatGPT… I asked them for advice out of desperation. But that was mega rubbish :wink: