I want to have a real time monitoring of the energy costs.
I’ve studied the detailed bill of my provider (ENEL Italy), with the fixed and the variable costs.
Here what you have to do.
A) Create the utility meter from user interface under Helpers.
Call it: Energy Tariff
Cycle: none
Net consumption: no
Delta values: no
Periodically resetting: no
and create 3 tariffs:
F1
F2
F2
Once done you should have 4 new entities:
select.energy_tariff
sensor.energy_tariff_f1
sensor.energy_tariff_f2
sensor.energy_tariff_f3
B) Create the binary sensor for the working days simply by adding native integration.
As exclusion just choose “Holidays”.
C) Create the automation that switches between the 3 tariffs (thanks to website indomus.it and to the user bremby)
D) Now you need to know how many days are there in the current month:
Create a command line with this code (thanks to user kartcon)
command_line.yaml
- sensor:
name: Days In Current Month
unique_id: days_in_current_month
command: cal $(date +"%m %Y") | awk 'NF {DAYS = $NF}; END {print DAYS}'
scan_interval: 60
E) Create a template sensor that calculates the progressive aggregate cost of your energy.
You need to check your bill details and adjust the values according to what you pay for each time slot and fixed costs.
E.G.: F3 is free for me, while F1 and F2 have the same cost. Also I have 8Kw contract.
template.yaml
- trigger:
- platform: time
at: "00:00:00"
sensor:
- name: Energy fixed costs
unique_id: energy_fixed_costs
device_class: "monetary"
unit_of_measurement: "EUR"
state_class: "total"
icon: mdi:cash
# commercializzazione al mese: 9.0-0.89765=8.10235
# quota fissa al mese: 1.72
# quota potenza impegnata al mese a Kw (8): 1.71*8
state: "{{
states('sensor.energy_fixed_costs') |float(0) +
8.10235 / states('sensor.days_in_current_month') |float(0) +
1.72 / states('sensor.days_in_current_month') |float(0) +
1.71*8 / states('sensor.days_in_current_month') |float(0)
}}"
- sensor:
- name: "Energy bill"
unique_id: 'sensor.energy_bill'
device_class: "monetary"
unit_of_measurement: "EUR"
state_class: "total"
icon: mdi:cash
# costo materia energia meno sconto del 30% a kwh in F1: 0.418 * 0.7
# costo materia energia meno sconto del 30% a kwh in F2: 0.418 * 0.7
# costo materia energia in F3: 0
# dispacciamento + sbilanciamento a kwh: 0.01541
# quota energia a kwh: 0.00848
# quota energia -meccanismi perequativi- a kwh: 0.00095
# Asos+Arim a kwh: 0.025014+0.003846=0.02886
# accisa su materia energia a kwh: 0.0227
# IVA al 10% sul totale: 1.1
state: "{{ ((
states('sensor.energy_fixed_costs') |float(0) +
states('sensor.energy_tariff_f1') |float(0) * 0.418 * 0.7 +
states('sensor.energy_tariff_f2') |float(0) * 0.418 * 0.7 +
states('sensor.energy_tariff_f3') |float(0) * 0 +
(states('sensor.energy_tariff_f1') |float(0) + states('sensor.energy_tariff_f2') |float(0) + states('sensor.energy_tariff_f3') |float(0)) * 0.01541 +
(states('sensor.energy_tariff_f1') |float(0) + states('sensor.energy_tariff_f2') |float(0) + states('sensor.energy_tariff_f3') |float(0)) * 0.00848 +
(states('sensor.energy_tariff_f1') |float(0) + states('sensor.energy_tariff_f2') |float(0) + states('sensor.energy_tariff_f3') |float(0)) * 0.00095 +
(states('sensor.energy_tariff_f1') |float(0) + states('sensor.energy_tariff_f2') |float(0) + states('sensor.energy_tariff_f3') |float(0)) * 0.02886 +
(states('sensor.energy_tariff_f1') |float(0) + states('sensor.energy_tariff_f2') |float(0) + states('sensor.energy_tariff_f3') |float(0)) * 0.0227) *
1.1) |round(2)
}}"
F) In the energy dashboard select sensor.energy_bill as the entity that tracks the Total cost
Hi @yashijoe, I’m Antonio and I write from Italy. Reading the article in InDomus, I’ve found your work and I’m trying it (some condition for F1, F2, F3). I’ve receive an error when I control the Configuration: The error is located in the last part (the cost): Home Assistant say this:
Configurazione non valida!
Invalid config for [sensor.template]: expected dictionary for dictionary value @ data[‘sensors’][‘device_class’]. Got ‘monetary’ expected dictionary for dictionary value @ data[‘sensors’][‘name’]. Got ‘Costo energia’ expected dictionary for dictionary value @ data[‘sensors’][‘state’]. Got '" {{ ((\n 7.471517 / states(‘sensor.giorni_nel_mese_corrente’) |float(0) * now().day |float(0) +\n 1.72 / states(‘sensor.giorni_nel_mese_corrente’) |float(0) * now().day |float(0) +\n 1.71*8 / states(‘sensor.giorni_nel_mese_corrente’) |float(0) * now().day |float(0) +\n states(‘sensor.consumo_mensile_f1’) |float(0) * 997 +\n states(‘sensor.consumo_mensile_f2’) |float(0) * 998 +\n states(‘sensor.consumo_mensile_f3’) |float(0) * 999 +\n (states(‘sensor.consumo_mensile_f1’)… expected dictionary for dictionary value @ data[‘sensors’][‘state_class’]. Got ‘total_increasing’ expected dictionary for dictionary value @ data[‘sensors’][‘unit_of_measurement’]. Got ‘€’. (See ?, line ?).
Can you help me?
P.S. I’ve put “997”, “998”, “999” only because, verifying the template, I received an error on “XXX”…
Thank you!!! I have already splatted configuration.yaml, but I haven’t create templates.yaml and I had put the “Energy cost” in sensors.yaml. Now I have the “bill”!
Surely I must study more, I’m at the beginning.
Again, thank you very much.
I thin that there is some missing conditions in the logic; I don’t understand how you managed sun, sat and holidays. if for sun/sat the easiest way I can imagine is to add a default action, you still need another condition to cover the holidays. so probably the logic should be:
Saturday and Sunday are already in the “fasce orarie energia” automation
About holidays you are right.
I’ve not considered holidays as in Italy we got just 8 days in a year. Not that much.
But I will think about that and adjust the code.
Thank you! Let me test your code for a week, once sure I’ll replace mine in the first post
Next week there will be 1 day of holiday so this is the perfet time to test it.
Few notes:
there is already an official integration for the working days
F3 holidays are just national holidays according to internet, but please let me know if you find something else
italian national holidays are 01.01, 06.01, monday after easter, 01.05, 02.06, 15.08, 01.11, 08.12, 25.12, 26.12