Calculate energy cost for sensor, with hourly price (Utility meter?)

I have the following:

  • An EV charging station where I have a sensor for lifetime energy (used kWh over time, Easee).
  • A template sensor that shows current electricity price, per hour (Nordpool).

Now I want an entity that gives me cost over time based on this, i.e. the same thing that the Energy panel gives, but just for the charging station.

I have looked into the Utility Meter. The problem I can’t solve there is the fact that the price changes hourly. I don’t know how to take that into account.

I’ve also looked into creating an automation that saves the latest reading to a helper from the charging station, so that I can do some math:

cost = (current kWh level - helper kWh level) * current cost/kWh

…but it seems like a an unstable solution.

Anyone that can point me in the right direction? Some info about the sensors mentioned above:

sensor.laddbox_easee_lifetime_energy =>
state_class: total_increasing
name: xxx
id: yyy
unit_of_measurement: kWh
device_class: energy
icon: mdi:counter
friendly_name: Laddbox (Easee) Lifetime energy
nordpool_kwh_se3_sek_3_095_025 =>
current_price: 1.389
unit: kWh
currency: SEK
country: Sweden
region: SE3

I do something similar. An approach is to:

  • create a sensor that shows the current cost per watt * power (watt)
  • use the reimann sum integration using Left method (this will calculate your accumulated cost)
  • then attach to a utility meter

Sorry for the late reply :). I will test it, thanks.

Hmm…I’m doing something wrong, which probably has to do with that I don’t understand this correctly. The sensor itself seems to be correct, but I get very strange values in the Reimann sum integration (and the Utility meter that follows it.

I’ve probably messed up the units, since I don’t understand it correctly.

My source sensor is measuring in kW, which is a difference compared you your example, @PeteRage .


        friendly_name: "E-ON/Easee laddkostnad"
        unit_of_measurement: "SEK"
        value_template: "{{ states('sensor.eon_current_price_incl_vat_and_fee') | float * states('sensor.laddbox_easee_power') | float }}"

Reimann sum:

state_class: total
source: sensor.eon_easee_charge_cost_right_now
unit_of_measurement: kSEKh
icon: mdi:chart-histogram
friendly_name: E-ON/Easee laddkostnad, ackumulerad

Utility meter:

state_class: total_increasing
source: sensor.e_on_easee_laddkostnad_ackumulerad
status: collecting
last_period: '0'
meter_period: daily
cron pattern: 0 0 * * *
last_reset: '2022-05-10T22:00:00.075120+00:00'
unit_of_measurement: kSEKh
icon: mdi:counter
friendly_name: E-ON/Easee laddkostnad, dagligen

(Note: I also have a sensor that shows lifetime energy for the power source in kWh. Is it better to use this, and in that case, how?

state_class: total_increasing
name: xxx
id: yyy
unit_of_measurement: kWh
device_class: energy
icon: mdi:counter
friendly_name: Laddbox (Easee) Lifetime energy


1 Like

Since you have a spiky load try using the LEFT mode of the Reimann.


What happens otherwise is it integrates by “drawing” a line from the first zero to the first non zero. So let’s say to be turned off for 2 hour and when if is off it always reads zero. So since it’s not changing the first zero is two hours ago, Then it turns on and goes to 3. It’ll draw a line from that first zero to the first 3 and calculate the area.


Thank you for the info! Now it works much better, the values are now more in line with what to expect.

One question though, what units should I use? On the sensor (that multiplies SEK per kWh with used kWh) i’ve set SEK as unit_of_measurement, which I think makes sense. Though, the Riemann sum integration and the utility meter gets “SEKh”, which I don’t really understand.

You can override the unit of measure for the reimann sum. You do this in the customize section

      unit_of_measurement: G


@balloob how cool wouldn’t it be if you could have this build-in all devices(or entities) that has an energy sensor or attribute automatically instead of building this for each entity you want to track the cost of.
You press the entity, or device, and you see the todays cost or the total cost as well as in the energy dashboard of course.

Right now the energy dashboard supports that but only for you total consumption and not per tracked entity.


Here is a feature request for that: