I’m trying to make my “car charging based on electricity prices” slightly more user friendly. Currently it looks like:
…where columns are the electricity price, the line is prediction of the price for tomorrow (real prices coming somewhere in the afternoon), and the white area is the scheduled car charging time. Note that I have asked the charging to be ready by 23:00, in real life I’d ask the charging be ready by 8am tomorrow, but then there is no feedback on when charging would occur (no white area), until the new prices come out. Wanted to illustrate here what the problem looks like.
What I would like to do is that the EV charging controller would use the real prices if they exist, and prediction if the real prices don’t exist. I.e. able the show the white area even if there is no certainty on the tomorrow prices (the charging controller will fine tune that anyway when the prices come out). For this I’m trying to create a sensor that would get the attributes conditionally depending on the existence of the real prices.
Here’s the nordpool sensor format:
And here’s the prediction sensor format:
Little extra challenge from the fact that the needed prediction values are attributes number 49-72 (the prediction includes yesterday (1-24), today (25-48), which are not interesting).
My code, that doesn’t work:
- platform: template
sensors:
nordpool_prices_real_and_estimate:
unique_id: nordpool_prices_real_and_estimate
friendly_name: 'Nordpool prices real and estimate'
value_template: > #Not really relevant
{{ states('sensor.nordpool_kwh_fi_eur_3_095_0255') }}
attribute_templates:
time: > #Just take the date/time from the prediction sensor attributes prediction-timestamp
{% set prediction = state_attr('sensor.nordpool_prediction', 'prediction') %}
{% set attributes = [] %}
{% for i in range(25, 72) %}
{% set attributes = attributes + [prediction[i][0]] %}
{% endfor %}
{{ attributes }}
price: > #Conditional depending on tomorrow_valid
{% set raw_today = state_attr('sensor.nordpool_kwh_fi_eur_3_095_0255', 'raw_today') %}
{% set raw_tomorrow = state_attr('sensor.nordpool_kwh_fi_eur_3_095_0255', 'raw_tomorrow') %}
{% set tomorrow_valid = state_attr('sensor.nordpool_kwh_fi_eur_3_095_0255', 'tomorrow_valid') %}
{% set prediction = state_attr('sensor.nordpool_prediction', 'prediction') %}
{% set attributes = [] %}
{% for i in range(0, 24) %}
{% set attributes = attributes + [raw_today[i][2]] %}
{% endfor %}
{% if tomorrow_valid %}
{% for i in range(0, 24) %}
{% set attributes = attributes + [raw_tomorrow[i][2]] %}
{% endfor %}
{% else %}
{% for i in range(49, 72) %}
{% set attributes = attributes + [prediction[i][1]] %}
{% endfor %}
{% endif %}
{{ attributes }}
The sensor value is ok, but attributes are null. I really don’t know if the syntax raw_today[i][2] makes any sense, but have no idea how to point to attribute list items. Indeed, I’m no programmer, so in the mercy of google here, but appreciating even more help of humans.