Hi,
I am trying to create a sensor in order to manage the injection price for the electricity in Spain.
Esios REE is providing us an API in order to be able to manage some published electricity variables.
So, according to this, first I am creating a sensor using the platform REST.
- platform: rest
name: PVPC Inyectado
method: GET
scan_interval: 600
unit_of_measurement: "cts/kWh"
resource: https://api.esios.ree.es/indicators/1739
headers:
Accept: application/json;application/vnd.esios-api-v1+json
Content-Type: application/json
Authorization: Token token=!secret esios_token
value_template: >
{%- set time = utcnow().replace(minute=0).replace(second=0).replace(microsecond=0) %}
{%- set time = time.strftime("%Y-%m-%dT%H:%M:%SZ") %}
{%- set selections = value_json.indicator.values | selectattr('datetime_utc','eq',time) | list %}
{{ selections[0].value | float / 10 | round(5) if selections | length > 0 else 0.0 }}
json_attributes_path: "$indicator.values"
json_attributes:
- value
Then I created another sensor using the platform TEMPLATE.
- platform: template
sensors:
pvpc_inyectado_hoy:
friendly_name: "PVPC Inyectado HOY"
value_template: "{{ states('sensor.pvpc_inyectado') | float }}"
unit_of_measurement: "cts/kWh"
attribute_templates:
pvpc_inyectado_00h: "{{ state_attr('sensor.pvpc_inyectado', 'value')[0].value | float }}"
pvpc_inyectado_01h: "{{ state_attr('sensor.pvpc_inyectado', 'value')[1].value | float }}"
# Repeat for every day hour up to 23h ...
pvpc_inyectado_23h: "{{ state_attr('sensor.pvpc_inyectado', 'value')[23].value | float }}"
The new sensor “PVPC Inyectado HOY” is getting the state OK. So it is showing the correct value for the current hour.
But the sensor “PVPC Inyectado HOY” is saving the attribute with null values.
If I use a http node at Node Red … I am getting the following paths for
payload.indicator.values[0].value / This is the path for "pvpc_inyectado_00h" attribute
payload.indicator.values[1].value / This is the path for "pvpc_inyectado_01h" attribute
...
payload.indicator.values[23].value / This is the path for "pvpc_inyectado_23h" attribute
Is there anything wrong at the REST platform sensor?
json_attributes_path: "$indicator.values"
json_attributes:
- value