I get 2 different electricity prices from my electricity provider. Between Monday to Friday 8 a.m. to 8 p.m. I pay €0.3. In the rest of the time I only pay 0.2€. How can I create an automation or an entity in HA to be able to calculate the electricity price correctly.
I managed to create an entity which shows me the current electricity price. How can I now calculate the HA calculated the current electricity consumption in euros for the day with the consumption of my heat pump.
I created one to create 2 different electricity prices according to the time of day. When I test the template in the developer options it works, but when I paste it into yaml it doesn’t work.
Code:
– sensor:
– name: ‘Strompreis’
unique_id: Strompreis
unit_of_measurement: ‘EUR/kWh’
device_class: “energy”
#state_class: “total_increasing”
state: >
{{% set tariff = { “Tag”: 0.4060, “Nacht”: 0.3395 } %}
{% set time = { “month”: (now().strftime(‘%m’) | int), “hour”: (now().strftime(‘%H’) | int), “weekday”: (now().weekday() | int ) } %}
{% if ((time.weekday <5) and (time.hour >= 8) and (time.hour < 20)) %}
{{ tariff.Tag }}
{%else%}
{{ tariff.Nacht }}
{%endif%}
Where is the mistake?..
- remove first
{
from line 1 in state template - replace all
“
with"
- replace all
’
with'
{% set tariff = { "Tag": 0.4060, "Nacht": 0.3395 } %}
{% set time = { "month": (now().strftime('%m') | int), "hour": (now().strftime('%H') | int), "weekday": (now().weekday() | int ) } %}
{% if ((time.weekday <5) and (time.hour >= 8) and (time.hour < 20)) %}
{{ tariff.Tag }}
{%else%}
{{ tariff.Nacht }}
{%endif%}
You may also consider using the utility_meter integration for this: Utility Meter - Home Assistant