Energy: Cost for the individual devices

I’m sorry but I’m unclear on what you mean - you’re saying we could add individual devices to the grid menu as well as to the individual devices menu? I tried doing that and it doesn’t work. When you add a sensor to the grid you cannot add it to the individual devices menu

Not the grid section, the gas section. On the Settings->Dashboards->Energy page, there is a section about Gas Consumption. You can actually add your electric devices there and they will display individually on the Energy dashboard.

If you want to track your gas consumption then this is a no-go.

If I understand correctly, one of the challenges with this request is that while it seems straightforward. It is only straightforward for those without solar or home-batteries. If you have solar and/or batteries then the cost of electricity in any time period is more difficult to determine - when an individual device consumes electricity, what is the cost of that combination of grid/solar/battery at that moment?

However, “difficult” is not the same as “impossible”. Having thought this through, here’s how it can be done.

3 sources of electricity:

  • Grid (cost given by electrical supplier - can often change every half hour)
  • Solar (cost is “free”, similarly for Wind, etc)
  • Battery storage (cost depends on the cost of electricity used to charge the battery, with a round-trip efficiency factor applied).

For any short period of time (e.g. every 5 minutes), we can observe and measure:

  • EP_grid (the kWh provided by the grid) (zero if off-grid or exporting…)
  • EP_solar (the kWh provided by solar) (zero at night, etc)
  • EP_battery (the kWh provided by the battery) (zero if we are charging the battery)

Here ‘EP’ = Energy Provided. And then EP_total is the sum of all 3: EP_grid + EP_solar + EP_battery

And similarly when charging the battery, there is a

  • EP_solar_charging (the kWh used from solar to charge the battery)
  • EP_grid_charging (the kWh used from the grid to charge the battery).

At any moment in time we have electricity being consumed and electricity being provided. Grid can provide and consume (if you are exporting). Solar panels only provide. Battery can provide and consume.

The cost of electricity in any interval of time is the weighted cost of the electricity from each provider. So the real-time cost per kWh for any device consuming electricity then, is:

Cost of electricity in any interval ‘C_elec’ = C_grid * EP_grid/EP_total + C_solar * EP_solar/EP_total + C_battery * EP_battery/EP_total. (where, as above, EP_xxx is zero if that provider is not currently providing electricity, so if the battery is not discharging, EP_battery is zero).

How do we calculate each of C_grid, C_solar, C_battery? C_solar is easy (it is zero). C_grid is also easy - it is the cost per kWh charged by the grid in that time period. C_battery needs to be calculated.

To do that we must maintain a total cost (money) that has been stored in the battery. This is updated any time that the grid is used to charge the battery at all:

  • Total_cost_in_battery = Last_period_total_cost_in_battery + EP_grid_charging * C_grid + EP_solar_charging * C_solar.
    Again C_solar is zero.

C_battery is then Total_cost_in_battery/Total_kWh_in_battery - in units of money/kWh obviously. Note that the kWh in battery is required here - it will presumably be slightly less than the kWh used to charge the battery (since that process is not 100% efficient). So need to have battery monitoring to tell you the kWh stored. If the battery has been mostly charged with solar and/or cheap overnight electricity, then the C_battery will be low. We may also need to directly apply an inefficiency factor to C_battery to account for the outbound inefficiency. i.e. when our battery drops from 20kWh to 15kWh, we may only have consumer 4.95kWh of electricity - the final 0.05kWh is lost. We should account for that by adjusting C_battery. Or we could separately measure accumulated “battery losses” and attribute a cost to that. But I think better to adjust C_battery so that the consumers of the electricity are more accurately costed.

So, using the above we can calculate ‘C_elec’, and hence know the cost of electricity in our system in the current time interval. That is the cost that should be applied to any consumer of electricity in this time interval: mostly that is all of your household devices. If you are exporting to the grid, then it is also your supply cost for that export (so the grid should be paying you more than C_elec if you are choosing to export!).

[Note: edited to correct power/energy confusion]

Thank you for the in depth response Vince.

I wonder if it can be done in stages though? I appreciate it might not be a perfect number for those with solar/batteries, but wouldn’t step 1 be to drive the cost from an entity? That would allow people to handle it however they want. They could go through all the process you outlined above to drive the cost from an accurate number.

I very much agree! (I don’t yet have solar or battery… - although am planning to add in the next 6 months). I’d love to see the basic version first…

Perhaps with the vision that the basic version could be later expanded to be a fully complete/correct version, someone might consider working on this.

I totally agree that cost of energy (for a device or home) has now become far more important than the measure of energy used.

In my case I have solar, grid charges for Peak and Off Peak, and grid ‘rewards’ for Solar Export. I calculate some key device costs mainly from ESPHome code, with some help from Home Assistant and house solar, grid import/export measurements.

To give a simple example, I have a device that consumes around 73watts continuously. Here is a graph for cost accumulation yesterday.

The flat orange line is sun shine power, the steep section is Peak power

In simple terms, the logic is:

Home Assistant:

  • has set $ values for Grid Peak, Off Peak, Export
  • has a schedule definition for Peak TimeOf Day
  • is receiving every 20 secs whole house grid and solar values.
  • constantly updates ‘current cost of energy’ using ratio of grid, solar values

ESPHome energy monitor devices:

  • constantly receives ‘current cost of energy’ from HAssistant
  • measures how much energy is used every 20secs,
  • accumulates cost per device

And here is a graph of the calculated ‘current cost of energy’

1 Like

I think a simplyfied version which only multiplies percentage of total consumption with total cost wouldn’t be that wrong. While an entity running only during times with good solar production doesn’t have direct cost, it still consumes energy that otherwise could be consumed by other entities (at least if you have a battery that would be charged). So while the direct costs are zero, it increases the cost of other entities consumption.
If there is no battery or it can’t be charged (is already full) then you loose the income from exporting the energy. So the costs are (usually) lower but they are still there.

Correct. In my case my calculated cost of energy for only solar use with no grid import is equal to the export rate I normally receive. At the moment that export rate here is a paltry 1c/kWh ! !

As pointed out, best to deploy this feature over stages. Maybe in the first iteration they can leave out individual device costs if there’s a battery. Then with user feedback they can work on bettering subsequent versions.

I honestly believe it’s best to keep things simple - if the grids not connected (aka grid kWh equals 0 over any given duration), then individual device cost should show zero, battery or no battery. I, personally, wouldn’t want to be looking at my dashboard wondering why I’m paying to run each appliance with the grid disconnected - at least that’ll be my first impression and I’m sure it’s going to scare many others as well.

On a lighter note, what also scared me was Vince’s use of Power Provided (PP) when referencing Energy (ie. kWh) values.