How to make sensors in Home Assistant to display consumption in kWh (day, week, month) and calculate the financial cost per device?
To get a similar look:
ore this:
This ended up to be (one, not the only) the working solution for me:
I would like to calculate the cost of a particular device (in this case, Shelly, Zigbee and Tuya "energy monitor device"). My goal is to have a sensor that shows the total cost according to the use of the device and the corresponding daily, weekly and monthly price of electricity consumption.
For my household/background information:
My example (Slovenian language)
Me = energy meter
Tm = temperature gauge
Bo = boiler
Na = daughter's room
Different manufacturers call entities differently!
2.) Create one sensor that will determine the price/kWh of electricity and the monthly fixed cost of the electrical grid connection.
The entity/sensor to use is in W
Be careful
, because some manufacturers also show how much the device consumes without a consumer. Choose the right entity in W˛
Enter the following code in the sensors.yaml file by changing the amount:
"Electricity price €/kWh"
value_template:
and
"Fixed monthly electricity price"
value_template:
to match your costs.
WRITE THIS TWO SENSORS:
#================================================
# Electricity billing
#================================================
- platform: template
sensors:
electricity_kwh_unit_price:
friendly_name_template: "Electricity price €/kWh"
value_template: "0.27808" # (Electricity ET, Network charge ET, Contribution for the operation of the market operator, Contribution for energy efficiency and Excise duty)
unit_of_measurement: EUR/kWh
unique_id: ?
electricity_standing_charge_price:
friendly_name_template: "Fixed monthly electricity price"
value_template: "16.3113" # (Accounting power, Contribution for CHP and RES, Flat cost of business and minus E-discount)
unit_of_measurement: EUR
unique_id: ?
For "unique_id:" use (https://www.guidgenerator.com/online-guid-generator.aspx) to generate it.
If you don't know what I'm writing about, take a look: https://youtu.be/kgFwhYInzfA
, or something similar.
After the system restarts, you should see something like this:
and this:
Now we have the sensor we created "Electricity price €/kWh" and "Fixed monthly electricity price", and we can continue to the next point.
3.) Then, from the device entity in W, create the , from which we will later obtain the desired data.
You will need Integration - Riemann sum integral for the next step.
If you don't have it installed, see: (https://www.home-assistant.io/integrations/integration/)
Simply click on the `add integration to' button. Follow the instructions. Restart the system if necessary!
Go and click on settings, then on devices & services and then on helpers
. Click on:
then choose:
and then select the desired entity in W:
then select marked values:
Repeat the process for all desired entities. After the process is complete, you should get something like this:
If the appearance of the icons bothers you (like me), follow the instructions. Click on the helper whose icon you want to change:
Click on settings (as indicated in the image):
The end result should be something like this:
Now we have the sensor we created for each entity we wanted to create the accumulation entity in kWh, and we can continue to the next point.
4.) Then create a day, week, month (if you want you can also do for hourly) utility sensor from the accumulation sensor.
You will need Utility Meter integral for the next step.
If you don't have it installed, see: (https://www.home-assistant.io/integrations/utility_meter/)
Simply click on the `add integration to' button. Follow the instructions. Restart the system if necessary!
Go and click on settings, then on devices & services and then on helpers
. Click on:
then choose:
select the previously made sensor accumulation entity in kWh, and select the time period (day, week, month) repeat each time separately.
The end result should be something like this:
and for the device
Now we have the sensor we created for each entity we wanted to create the accumulation entity for day, week, month in kWh, and we can continue to the next point.
Enter the following code in the sensors.yaml file:
WRITE THIS THREE SENSORS:
#================================================ ================================================= ================================================= ====
# Electricity billing by consumer
#================================================ ================================================= ================================================= ====
#1 Shelly
- platform: template
sensors:
consumption_me_will_be_daily:
friendly_name_template: "Daily boiler consumption"
unit_of_measurement: "€"
value_template: "{{ (states('sensor.me_bo_poraba_kwh_dnevno') | round (2)) * (states('sensor.electricity_kwh_unit_price') | round (2))}}"
icon_template: mdi:currency-eur
unique_id: ?
- platform: template
sensors:
spending_me_will_be_weekly:
friendly_name_template: "Weekly boiler consumption"
unit_of_measurement: "€"
value_template: "{{ (states('sensor.me_bo_poraba_kwh_tendensko') | round (2)) * (states('sensor.electricity_kwh_unit_price') | round (2))}}"
icon_template: mdi:currency-eur
unique_id: ?
- platform: template
sensors:
spending_me_will_be_monthly:
friendly_name_template: "Monthly boiler consumption"
unit_of_measurement: "€"
value_template: "{{ (states('sensor.me_bo_poraba_kwh_mesecno') | round (2)) * (states('sensor.electricity_kwh_unit_price') | round (2))}}"
icon_template: mdi:currency-eur
unique_id: ?
For "unique_id:" use (https://www.guidgenerator.com/online-guid-generator.aspx) to generate it. It can generate multiple numbers at once!
The end result should be something like this:
7.) look for more (https://www.youtube.com/results?search_query=homeassistant+calculating+electricity+price)
and much more