OK.
After digging deeper and playing around with the provided solution I possibly can now better explain what I would like to do and how:
IMHO the main sensor should be the full dataset.
From that I want to derive in template sensors;
- the market prices in one list to find the minimum and 2, 3, 4 hours of minimum price (most probably individual template sensors), including the respective timestamp of the starting hour of 1, 2, 3, 4 hours time frame)
- the count of available values.
- at least for the 4 hour range I would like to see the range before 6 a.m. of the next day (charging my EV over night, takes some hours).
What I found so far was a small mistake in petros solution. Please see the orig post and my changes here. In the template sensor the set index line needs to be changed:
Orig from petro
- platform: template
sensors:
lowest_awattar:
friendly_name: "Lowest awattar"
value_template: >-
{% set index = states('sensor.awattar_table') | int %}
changed
- platform: template
sensors:
lowest_awattar:
friendly_name: "Lowest awattar"
value_template: >-
{% set index = states('sensor.awattar') | int %} #changed the sensor name
So with this I perfectly get as individual sensors:
- the index of the lowest value including the price reading and the timestamp as templates
- the same for the two lowest values in a row.
With all my playing around I confused myself into deep dark mess.
Here is what I crafted as additional sensor (keeping the other two untouched for the time being):
#aWattar Strompreise
- platform: rest
resource: https://api.awattar.de/v1/marketdata
name: awattar_all_values
json_attributes:
- data
scan_interval: 60
value_template: >
{%- set awattar_all_list = value_json.data | list %}
{{ awattar_all_list }}
- platform: template
sensors:
awattar_count:
friendly_name: "Count of available prices"
value_template: >-
{% set count = state_attr('sensor.awattar_all_values', 'data') | list | length %}
{{ count }}
awattar_values:
friendly_name: "All aWattar values"
value_template: >-
{%- set awattar_all_list = value_json.data | map(attribute='marketprice') | list %}
{%- set values_all = namespace(all=[]) %}
{% for i in range(awattar_all_list | length) %}
{%- set v = (awattar_all_list[i] | float * 100/1000 * 1.19) | round(2) %}
{%- set values_all.all = values_all.all + [ v ] %}
{%- endfor %}
{{ values_all.all }}
Totally unexpected at all I don’t get a sensor with the name “awattar_all_values” at all in my entities list.
As this sensor is not there the two template sensors give the reading “unavailable”.
As I said before, my programming skills are really not great and from a long time ago.
Maybe digging deeper here can help other people later on as I expect this power provider to become more popular in the future.