Always 19:00:00, why?

I’ve a sensor with attr, all days prices from Nord pool

data: 
- start: '2025-10-15 00:00:00'
  end: '2025-10-15 00:15:00'
  price: 172.234
- start: '2025-10-15 00:15:00'
  end: '2025-10-15 00:30:00'
  price: 159.116

one price for every 15 minutes, 00:00:00 → 23:45:00

I test in Template this code

{% for data in state_attr("sensor.electricity_prices","data") %}
{% if now().astimezone().date().isoformat() == data.start.split(' ')[0] %}
{{ data.start }} {{data.price}}
{% endif %}
{% endfor %}

and I get everything from 00:00:00 → 23:45:00, all days prices in 15 minutes interval

2025-10-15 00:00:00 172.234
2025-10-15 00:15:00 159.116
2025-10-15 00:30:00 145.338

Making a script that does this and send data to my influxdb through rest_command always starts with the time 19:00:00, never any time ahead :frowning_with_open_mouth:
Script (with debug output)

sequence:
  - variables:
      priser: "{{ state_attr('sensor.electricity_prices', 'data') }}"
  - repeat:
      for_each: "{{ priser }}"
      sequence:
        - action: system_log.write
          metadata: {}
          data:
            level: info
            message: NORDPOOL {{ repeat.item.start }} {{ repeat.item.price }}
alias: test
description: ""

checking my trace I get

Iteration 1
Executed: 15 October 2025 at 11:51:09
Result:
params:
  domain: system_log
  service: write
  service_data:
    level: info
    message: NORDPOOL 2025-10-15 19:00:00 214.289
  target: {}
running_script: false

all the way till 23:45:00, but nothing from 00:00:00

What I’m I doing wrong. I’ve tried every AI to help me but always the same, the loop start with 19:00:00.

Perhaps the attributes of your sensor contain datetime objects rather than strings for the values of start and stop.

Try eliminating the use of variables and instead use

for_each: "{{ state_attr('sensor.electricity_prices', 'data') }}"

my being stupid, I was looking in the trace and the trace buffer it isn’t that long and it only saves the last X steps. That is, the first steps was overwritten hence always starting with 19:00:00.

1 Like