Hi folks,
after a long time of stability in my config I’m trying to do a new move.
As I’m changing my power supplier to aWattar I can read the hourly prices of electricity. So far, so good.
Now I want to put a part of the values to a simple list like this:
{"data":[21.2,22.3,17.5,...]}
I want to use this list as JSON table in Node-Red later on.
I have all the single values and the calculation model is right.
It’s just a problem in building the list…
#aWattar Strompreise
- platform: rest
resource: https://api.awattar.de/v1/marketdata
name: "awattar"
value_template: "{{ (value_json.data[0]) }}"
json_attributes:
- data
scan_interval: 60
- platform: template
sensors:
awattar_json:
friendly_name: "aWattar JSON table"
value_template: >-
{% set awattar_json =
{"data":
{
((((state_attr('sensor.awattar', 'data')[0].marketprice)|float*100)/1000) | multiply(1.19) + 19.22) |round(2),
((((state_attr('sensor.awattar', 'data')[1].marketprice)|float*100)/1000) | multiply(1.19) + 19.22) |round(2),
((((state_attr('sensor.awattar', 'data')[2].marketprice)|float*100)/1000) | multiply(1.19) + 19.22) |round(2),
((((state_attr('sensor.awattar', 'data')[3].marketprice)|float*100)/1000) | multiply(1.19) + 19.22) |round(2),
((((state_attr('sensor.awattar', 'data')[4].marketprice)|float*100)/1000) | multiply(1.19) + 19.22) |round(2)
}}
%}
I’ve been fiddeling around with this now for two days in a row but I only get any result if I build up the list like this:
{"0":"22.3",'"1":"23.8","2":"17.5",...}
This format I can’t get my head around in Node-Red for further processing. Basically I want to search for minima, 2 hours in a row minima, 3 hours in a row minima, …
With the current extract from my config I get the following error message (not unexpected):
Failed config
sensor.template:
- Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: expected token ':', got ',') for dictionary value @ data['sensors']['awattar_json']['value_template']. Got '{% set awattar_json =\n {"data":\n {\n ((((state_attr(\'sensor.awattar\', \'data\')[0].marketprice)|float*100)/1000) | multiply(1.19) + 19.22) |round(2),\n ((((state_attr(\'sensor.awattar\', \'data\')[1].marketprice)|float*100)/1000) | multiply(1.19) + 19.22) |round(2),\n ((((state_attr(\'sensor.awattar\', \'data\')[2].marketprice)|float*100)/1000) | multiply(1.19) + 19.22) |round(2),\n ((((state_attr(\'sensor.awattar\', \'data\')[3].marketprice)|float*100)/1000) | multiply(1.19) +.... (See ?, line ?).
Any simple example in how to build a list is highly appreciated, I’ve read the doc on templates over and over again now. When the list is filled I’ll probably have to use the “to_json” filter. But that’s part two of the cake…
Best regards
Ralf