How to calculate hourly energy cost

Hello…

I have managed to create two APEX graphs.
One pulls the data from NordPool (Energy Price today) and the second data is Energy Consumption per hour (kWh)

Now, I would like to have third graph that basically shown the COST per hour. Practically multiplying those two graph value each hour.

So

Energy Price (EUR/hour) * Energy Consumption (kWh) = Hourly Cost

But don’t know HOW?

Config: Energy Price (EUR/hour)

type: custom:apexcharts-card
graph_span: 24h
header:
  title: Energy price today (snt/kWh)
  show: true
span:
  start: day
now:
  show: true
  label: Now
series:
  entity: sensor.nordpool_kwh_fi_eur_3_10_024
    type: column
    data_generator: |
      return entity.attributes.raw_today.map((start, index) => {
        return [new Date(start["start"]).getTime(), entity.attributes.raw_today[index]["value"]];
      });

Config: Energy Consumption (kWh)

type: custom:apexcharts-card
graph_span: 24h
span:
  start: day
header:
  title: Energy Consumption (kWh)
  show: true
apex_config:
  legend:
    position: top
    fontSize: 14px
    itemMargin:
      horizontal: 10
      vertical: 5
now:
  show: true
  label: Now
all_series_config:
  type: column
  unit: Wh
  float_precision: 0
  opacity: 0.7
  show:
    legend_value: false
  group_by:
    func: avg
    duration: 1h
    fill: zero
series:
  entity: sensor.power_mains
    name: Mains

I did configure the “Energy” tab as well with the same input data.

But for some reason the Cost is 180.88€ when it suppose to be around 6-7€ for 31kWh?
The energy price is per hour (NordPool)r and changed constantly. That’s why I was planning to do this in the first place

The consumption is correct. NordPool hourly price input (Use an entity with current price)
is also correct.

However, the total cost is way off!!
Real price is 6.52€ and HA shows 188,80€

Firstly, you should surround code with “```” (three back-ticks) so it formats correctly. Without the indentation preserved it is very hard to read.

You would multiply two entities by creating a template sensor entity that multiplies the two together. However, the timing of arrival of your data might cause problems, as the template will recalculate when either entity changes value. Looking at the Nord website, it appears you get the price data a day ahead, so that would resolve the problem if you loaded all of the price data into an attribute - which is what you appear to be doing.

Also, your “sensor.power_mains” sounds more like it is “power” (kW) rather than “energy” (kWh), espcially given you have “units: kW”. If your entity does not already have an energy sensor, you can use an Integration helper to calculate it. However, looking at the data, it appears to behave like energy but reset to zero every hour. But assuming the “shape” is accurate, something else is wrong:

  • The energy price is let’s say on average 23, but the units are unclear - your header says “snt” is this Euro cents? This would be US$0.24 per kWh, but this site says the price in Norway is equivalent to US$0.141 per kWh.

  • The energy consumption shows values over 4000kWh used in a 1 hour period. This is an extraordinary amount of power that would cost about $1000 just for that hour. Even if it should be W rather than kW, a total of ~30,000W in the first half of a day is much more than I would have thought (my house uses 10-20kWh per day varying from Summer to Winter). And what is consuming so much power at 3am, but virtually nothing at midday?

Firstly, you should surround code with “```” (three back-ticks) so it formats correctly. Without the indentation preserved it is very hard to read.

Done. Thanks for the tip.Actually the editor suggested this already, but I somehow I managed to ignored the warning.

Also, your “sensor.power_mains” sounds more like it is “power” (kW) rather than “energy” (kWh), espcially given you have “units: kW”. If your entity does not already have an energy sensor, you can use an Integration helper to calculate it. However, looking at the data, it appears to behave like energy but reset to zero every hour. But assuming the “shape” is accurate, something else is wrong:

I thought about this. The sensor input is power in kW, It’s pulled from Energomonitor API. However, since the measurement is over 1 hour perion, should’n it be kW per hour so kWh?

    duration: 1h
    fill: zero
series:
  entity: sensor.power_mains

But interesting, since the energy is exactly the same as in the original Energomonitor.
I need to take a moment and think about this

The energy price is let’s say on average 23, but the units are unclear - your header says “snt” is this Euro cents? This would be US$0.24 per kWh, but this site says the price in Norway is equivalent to US$0.141 per kWh.

Energy price is not static it’s changing hourly.

The energy consumption shows values over 4000kWh used in a 1 hour period. This is an extraordinary amount of power that would cost about $1000 just for that hour. Even if it should be W rather than kW, a total of ~30,000W in the first half of a day is much more than I would have thought (my house uses 10-20kWh per day varying from Summer to Winter). And what is consuming so much power at 3am, but virtually nothing at midday?

My bad. The header is wrong. It’s Wh…not kWh

It’s correct in the code

header:
title: Energy Consumption (kWh)

unit: Wh

I got the “Energy” working once I changed the price from cents to EURos

thanks

i need the same for a single device :/. Do you have an idea?

I’d be keen to do this as well. I have an Electricity tariff that changes every 30 minutes, and individual consumption from devices. I would love to show on the Energy Dashboard the cost of each device for the day.

(For context: I try and utilise my heat pump when the energy price is lowest, so I’d like to see how much that individual appliance has truly cost)

Hi, I’m searching en trying the same about calculating hourly energy cost. Do you have it working for now? If yes, could you share how you managed to do this?
Regards Ronald