Template code works differently

Hello there, I am anewbie with home assistant and would appriciate some help from more seasoned folks… I tested home assistant in a virtual environment and managed to do integrations etc… Now I moved to dedicated PI environment and was moving my integrations (mainly temlate sensors)…

My problem is that old environment (ha junkeys) nordpool integration results
attribute:
times: 2024-04-19 00:00:00, 2024-04-19 01:00:00, 2024-04-19 02:00:00, 2024-04-19 03:00:00, 2024-04-19 04:00:00, 2024-04-19 05:00:00, 2024-04-19 06:00:00, 2024-04-19 07:00:00, 2024-04-19 08:00:00, 2024-04-19 09:00:00, 2024-04-19 10:00:00, 2024-04-19 11:00:00, 2024-04-19 12:00:00, 2024-04-19 13:00:00, 2024-04-19 14:00:00, 2024-04-19 15:00:00, 2024-04-19 16:00:00, 2024-04-19 17:00:00, 2024-04-19 18:00:00, 2024-04-19 19:00:00, 2024-04-19 20:00:00, 2024-04-19 21:00:00, 2024-04-19 22:00:00, 2024-04-19 23:00:00
prices: 13.45872, 11.98172, 12.34572, 12.14972, 11.86672, 11.83172, 11.96972, 13.33872, 19.44672, 17.672719999999998, 15.95972, 13.480720000000002, 12.98672, 12.35172, 11.91872, 11.634720000000002, 11.74972, 12.19672, 12.945720000000001, 13.32872, 13.244720000000001, 12.35172, 12.04872, 11.54072
unit_of_measurement: €
icon: mdi:currency-eur
friendly_name: NordPool Energyprices_2

and same code in PI
unit_of_measurement: €
icon: mdi:currency-eur
friendly_name: NordPool Energyprices

SO the code that fetches the times and costs does not work… nordpool integration itself works and the state of the integration is correct…

I am baffled…

the only thing between the instances that I can see is the time format

so can this piese of code :
{%- set ns.times = ns.times + [as_local((hours.start)).strftime(“%Y-%m-%d %H:%M:%S”)] -%}
work differently if time format is different?
and how can I go from 12h to 24h time

Your question is not clear.

The template provided needs hours.start to return datetime objects. If that is not what it is returning, then you will need to modify the template.

Just to note - this is not my code but I pasted part of the sensor code…
times: >
{% set ns = namespace(times=) -%}
{%- set today = state_attr(‘sensor.nordpool_hinta’,‘raw_today’) -%}
{%- for hours in today -%}
{%- set ns.times = ns.times + [as_local((hours.start)).strftime(“%Y-%m-%d %H:%M:%S”)] -%}
{%- endfor -%}
{%- set tomorrow = state_attr(‘sensor.nordpool_hinta’,‘raw_tomorrow’) -%}
{%- for hours in tomorrow -%}
{%- set ns.times = ns.times + [as_local((hours.start)).strftime(“%Y-%m-%d %H:%M:%S”)] -%}
{%- endfor -%}
{{ ns.times }}

This code gives in my virtual box all the times to the state attribute like this
times:

  • “2024-04-19 00:00:00”
  • “2024-04-19 01:00:00”
  • “2024-04-19 02:00:00”
  • “2024-04-19 03:00:00”
  • “2024-04-19 04:00:00”
  • “2024-04-19 05:00:00”
  • “2024-04-19 06:00:00”
  • “2024-04-19 07:00:00”
  • “2024-04-19 08:00:00”
  • “2024-04-19 09:00:00”
  • “2024-04-19 10:00:00”
  • “2024-04-19 11:00:00”
  • “2024-04-19 12:00:00”
  • “2024-04-19 13:00:00”
  • “2024-04-19 14:00:00”
  • “2024-04-19 15:00:00”
  • “2024-04-19 16:00:00”
  • “2024-04-19 17:00:00”
  • “2024-04-19 18:00:00”
  • “2024-04-19 19:00:00”
  • “2024-04-19 20:00:00”
  • “2024-04-19 21:00:00”
  • “2024-04-19 22:00:00”
  • “2024-04-19 23:00:00”
    But in my PI environment it does NOTHING…

times: null
prices: null
unit_of_measurement: €
icon: mdi:currency-eur
friendly_name: NordPool Energyprices

Is sensor.nordpool_hinta providing equivalent data in both the the Virtual Box and Pi instances?

Yes - exactly same data.

timeformat on virtualbox:
[20 April 2024 at 00:00:00]
and on the Pi
[April 20, 2024 at 12:00:00 AM]

Just wondering if this could be the cause…

Time formats in strftime MUST be exact, or else you won’t get a match. Most likely, the date that is coming in on the Pi is in the wrong format for some reason.

now I have modified the code so that it is working in the development tool template editor. How do I make sure the sensor gets updated for example hourly? My nordpool integtation updates hourly but the template sensor has not updated itself in last 6 hours…
tried this with templates:

  • trigger:
    • platform: time_pattern
      minutes: /15

No luck…