Skip to content

How to make sensors in Home Assistant to display consumption in kWh (day, week, month) and calculate the financial cost per device?

Notifications You must be signed in to change notification settings

Trzinka/Home-Assistant-SOLVED---Calculate-cost-for-individual-device-cost-kWh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 

Repository files navigation

Home Assistant-SOLVED - Calculate cost for individual device cost/kWh

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:

Poraba gretja

ore this:

Poraba ostalo

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:

1.) First, name the device in a way that is understandable to you!


My example (Slovenian language)
    Me = energy meter
    Tm = temperature gauge
    Bo = boiler
    Na = daughter's room

#1-Shelly-Privzeto Different manufacturers call entities differently!

#2-Shelly-Spremenjeno #2-Shelly-Spremenjeno2 #2-Tuya-Spremenjeno #2-Zigbee-Spremenjeno

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˛

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:

Cena elektrike €-kWh

and this:

Fiksna cena elektrike mesečno

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: #3-Helper

then choose:

#4-Integration

and then select the desired entity in W:

#5-Select

then select marked values:

#6-Setings

Repeat the process for all desired entities. After the process is complete, you should get something like this:

#7a-Change icon

If the appearance of the icons bothers you (like me), follow the instructions. Click on the helper whose icon you want to change: #7a-Change icon

Click on settings (as indicated in the image): #7b-Change icon

Change to the desired icon: #7c-Change icon

The end result should be something like this: #8a-Utility

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:

#3-Helper

then choose:

#8b-Utility

select the previously made sensor accumulation entity in kWh, and select the time period (day, week, month) repeat each time separately.

#8c1-Utility #8c2-Utility #8c-Utility

The end result should be something like this:

Meritve

and for the device

Me-Bo

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.

5.) Then multiply the price/kwh-sensor with the utility sensor in the sensors.yaml file.


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: Me-Bo EUR

6.) Now you can make a Lovelace card.


Please click on the star at the top right if you like the git!

and much more

(https://www.google.com/search?sca_esv=591524815&sxsrf=AM9HkKmIuV66qLgKD2uXqiGiF19H7qV4_w:1702746085001&q=home+assistant+calculating+electricity+price&spell=1&sa=X&ved=2ahUKEwjN2ae8t5SDAxWYSfEDHUV6BpwQBSgAegQICBAC&biw=1366&bih=645&dpr=1)

About

How to make sensors in Home Assistant to display consumption in kWh (day, week, month) and calculate the financial cost per device?

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published