Hello,
How to write sensor output template so that it looks like “raw_today” in the screenshot?
Those are the electricity prices provided by the Nordpool sensor. My intention is to read those prices, perform a few calculations, and then output similar object that is provided by the Nordpool sensors. I have managed to read the values and perform computations based on them using the code below.
{% set today = state_attr("sensor.nordpool_kwh_fi_eur_3_095_024","raw_today")%}
{% set uusi=namespace(value=[]) %}
{% for i in range(3) %}
{% set x = today[i] %}
{% if x.value < 5 %}
{% set y=100 %}
{% else %}
{% set y=0 %}
{% endif %}
{% set x = dict(x,value=y) %}
{% set uusi.value=uusi.value+ [x] %}
{% endfor%}
{{ uusi.value }}
[{‘start’: datetime.datetime(2022, 12, 29, 0, 0, tzinfo=zoneinfo.ZoneInfo(key=‘Europe/Helsinki’)), ‘end’: datetime.datetime(2022, 12, 29, 1, 0, tzinfo=zoneinfo.ZoneInfo(key=‘Europe/Helsinki’)), ‘value’: 0}, {‘start’: datetime.datetime(2022, 12, 29, 1, 0, tzinfo=zoneinfo.ZoneInfo(key=‘Europe/Helsinki’)), ‘end’: datetime.datetime(2022, 12, 29, 2, 0, tzinfo=zoneinfo.ZoneInfo(key=‘Europe/Helsinki’)), ‘value’: 0}, {‘start’: datetime.datetime(2022, 12, 29, 2, 0, tzinfo=zoneinfo.ZoneInfo(key=‘Europe/Helsinki’)), ‘end’: datetime.datetime(2022, 12, 29, 3, 0, tzinfo=zoneinfo.ZoneInfo(key=‘Europe/Helsinki’)), ‘value’: 0}]
The type of output is a string. How to write the attribute_templates -section in the sensor specification so that the daily start, end, and value fields are accessible like in the Nordpool sensor?