#Calculate individual devices energy costs

1 messages Β· Page 1 of 1 (latest)

rotund chasm
#

So first we need to create a sensor that takes the product of the power and costs

template:
  - sensor:
    unique_id: ecc4d377-6e5e-4758-b570-549539525357
    name: Device costs
    state: >
      {{ states('sensor.device_power')|float(0) * states('sensor.brabander_electricity_price')|float(0) / 1000}}
    unit_of_measurement: "€/h"
    state_class: measurement

It is dividend by a factor of 1000 because my power sensor reports in W and my price sensor in $/kWh

hard tide
#

ok

#

(for me as well)

rotund chasm
#

This is a measurement in time and not a cumulative value.
Therefore we need a Integral helper.

hard tide
rotund chasm
#

Yep, put the newly created sensor into that helper and set it to hourly

hard tide
#

accuracy to 2 decimals

rotund chasm
#

If you have set the unit_of_measurement correctly in the created template sensor it will produce the right amount of costs

hard tide
#

sure!
What should be the intgration method of that riemann sum integrator? like "left Riemann sum"?

#

or "trapezoidal rule"?

rotund chasm
#

Yup left is the best

hard tide
#

ok

rotund chasm
#

Oh sorry reading the documentation the trapezoidal rule can be preferred depending on the power characteristics of the device. But I expect a charger to have a long continuous equal load so left will do the job

fresh bison
#

trapezoidal falls apart if the sensor is ever 0 for a long period of time

hard tide
#

the sensor will be like 7000 for hours πŸ˜„

rotund chasm
#

From there you can add utility meters to track the costs based on days/months/years etc

hard tide
#

So this integral helper counts the price during the charge

#

then I add a utility meter and reset it daily, weekly etc?

hard tide
#

can this method also improve my "per charge" cost counter?

rotund chasm
#

Yes, what I do to calculate the costs for a run is create an input number and store the current value of the costs sensor into that input number at the start

#

At the end you can simply substract the state of the input number from the cost sensor

hard tide
#

do you do this with an automation? (like from the blueprint "Appliance has finished")

Or how do you track "the end"

rotund chasm
#

With an automation, but can also work with any blueprint that has options to add start and end actions

hard tide
#

ok, for one run you:
created 2 helpers of input number
#1 is for storing the current value of the riemann sum integrator
#2 is for storing the cost value of the last run

right?

rotund chasm
#

Yes, that would work. I personally dont store the cost value of a run, but send it in a notification to me

hard tide
#

when the charging starts, you store the value to #1 and reset #2

When the charging finishes you calculate the rieman helper value minus the #1 value to get #2 value?

#

ahh yeah.. also possible

rotund chasm
#

It will also work if you update #2 only at the end

hard tide
#

that makes it clear

#

yes you are right ^^

#

thanks a lot @rotund chasm πŸ™ πŸ‘

#

well... wait^^

#

this calculates the cost of the run... but it doesnt take solar production into account πŸ˜„

rotund chasm
#

That's true

#

You can combat that by adding conditions in the first template sensor I guess

#
{#only solar is used so no costs#}
{% if sensor.grid_power | float(0) <= 0 %} 
  0
{%else%}
  {{ states('sensor.device_power')|float(0) * states('sensor.brabander_electricity_price')|float(0) / 1000}}
{%endif%}

Not sure yet when you have both grid and solar usage at the same time how you can determine what goes to the charger, but if you do you can subtract the solar power first from the device_power.

hard tide
#

I thought about something like this:

  - sensor:
    unique_id: ecc4d377-6e5e-4758-b570-549539525357
    name: Device costs
    state: >
      {{ 
          states('sensor.device_power')|float(0) * states('sensor.brabander_electricity_price') / 100 * 
    (100 * states('sensor.grid_power') / ( states('sensor.grid_power') + states('sensor.solar_power') - states('sensor.grid_feed_power')))
    / 1000 
    }}
      states('sensor.device_power')|float(0) * states('sensor.brabander_electricity_price')|float(0) / 1000}}
    unit_of_measurement: "€/h"
    state_class: measurement```
#

that takes also parts of the produced energy into that calculation

#

yours assume, that all of the energy/power is 100% used by the car

#

I think this method should work there

rotund chasm
hard tide
#

yeah, but I will never have this case ^^

#

My solar produces about 2000W peak

#

the char charges with something like 3000-7000W

#

so the "mixed power" is exactly the case I want to catch

#

but I think I can make it from here

rotund chasm
#

Yeah I think the calculation you mentioned above does a good estimate, you can use that in the template. The real problem is to allocate exactly how many of each power type is used by that circuit

hard tide
#

its only math πŸ™‚

#

yes... it can only be a mathematical approach. I dont assume to get the real value and it doesnt have to be