I am trying to get dynamic gas and electricity prices into my Home Assistant so I can see this in a dashboard as such (link)
However, when I use the code below, I get the following graph:
Also, the state in developer tools give me the following:
So I am guessing it is only getting 1 price instead of all 24 prices for every hour.
These are the guides I have been following:
This is the code I have used in configuration.yaml (same like guide 1)
# Enever.nl stroomprijzen
- platform: rest
resource: https://enever.nl/api/stroomprijs_vandaag.php?token=EIGENTOKEN
name: Stroomprijs enever
scan_interval: 86400
value_template: "OK"
json_attributes:
- data
- platform: template
sensors:
stroomprijs_zp:
device_class: monetary
unit_of_measurement: €/kWh
unique_id: "stroomprijs"
value_template: >
{% set now_ts = as_timestamp(utcnow()) %}
{% set values = namespace() %}
{% set values.current = None %}
{% for row in states.sensor.stroomprijs_enever.attributes.data|reverse if not values.current %}
{% set row_timestamp = as_timestamp(row.datum) %}
{% if now_ts > row_timestamp %}
{% set values.current = row %}
{% endif -%}
{% endfor -%}
{% if values.current %}
{{ values.current.prijsZP }}
{% else %}
{{ states(entity_id) }}
{% endif %}
friendly_name: "Stroomprijs"
# Enever.nl gasprijzen
- platform: rest
resource: https://enever.nl/api/gasprijs_vandaag.php?token=EIGENTOKEN
name: Gasprijs
unique_id: Gasprijs
force_update: true
scan_interval: 86400
device_class: monetary
unit_of_measurement: €/m³
value_template: >
{% set now_ts = as_timestamp(utcnow()) %}
{% set values = namespace() %}
{% set values.current = None %}
{% for row in value_json.data|reverse if not values.current %}
{% set row_timestamp = as_timestamp(row.datum) %}
{% if now_ts > row_timestamp %}
{% set values.current = row %}
{% endif -%}
{% endfor -%}
{% if values.current %}
{{ values.current.prijsZP }}
{% else %}
{{ states(entity_id) }}
{% endif %}
This is the code I have been using in automations.yaml (same like guide 1)
- id: update_anwb_gasprijs_6uur
alias: Update zp gasprijs 6 uur
trigger:
- platform: time
at: 06:03:00
condition: []
action:
- service: homeassistant.update_entity
data: {}
target:
entity_id: sensor.gasprijs
- id: update_enever_zp_kwhprijs_0uur
alias: Update electricity price feed
description: Update electricity price feed
trigger:
- platform: time
at: 00:01:00
- platform: time
at: 00:02:00
- platform: time
at: 00:01:00
condition: []
action:
- service: homeassistant.update_entity
data: {}
target:
entity_id: sensor.stroomprijs_enever
mode: single
- id: update_enever_zp_kwhprijs_uur
alias: Update dynamische stroom tarieven
description: Update dynamische stroom tarieven
trigger:
- platform: time_pattern
minutes: '00'
seconds: '30'
condition: []
action:
- service: homeassistant.update_entity
data: {}
target:
entity_id:
- sensor.stroomprijs_zp
mode: single
Does anyone know what I am doing wrong? I have rebooted Home Assistant several times