I am fairly new to HA. I have set it up to limit large consumers in our house to only operate during the cheapest hours based on prices from Nordpool (using GitHub - custom-components/nordpool: nordpool sensor for ha.). These prices do not take the variable tariff, charged by the infrastructure supplier, into account. The documentation suggests this should be possible, but I cannot figure out how. From another post I learnt that something like the below code should do the trick (in place of “{{0.0|float}}” in the Additional cost field [see documentation in the above link]). I don’t fully understand what the code does, but I imagine that it should update all hourly prices. Has anyone done this or can anyone figure out what I am doing wrong? (the approach suggested in the documentation involves some scripting and I am not sure how to handle that, perhaps it is the same this macro approach…). Thanks in advance!
"{% macro calc(v) -%}
{%set d = {
"tariff_night": 12,
"tariff_day": 70 } %}
{%set day_price = v + ((d.tariff_day) | float ) | round(4)%}
{%set night_price = v + ((d.tariff_night) | float ) | round(4)%}
{% if now().timetuple().tm_isdst == 1%}
{{night_price}}
{% else %}
{% if now().hour >= 6 and now().hour < 22 and now().weekday() >= 0 and now().weekday() < 5%}
{{day_price}}
{% else %}
{{night_price}}
{% endif %}
{% endif %}
{%- endmacro %}
{{calc(0)}}"