Calculate total power used / generated

Hi everyone,

I have a smart meter that keeps track of how much power is generated, used from grid and total used by the house. This meter however keeps this information as “now” not in terms of daily/weekly/monthly usages.

In Home Assistant we have the Energy Dashboard that automatically calculates the kW’s for these on hourly basis. How would I be able to do the same in OpenHab… would I run a script that every second / minute adds the current “NOW” value into a total value? If there an “average” I can use with hourly intervals (or seconds) on the actual NOW value?

Ideas?

Hi,

you could use bar charts and select Aggregation → Difference of lasts. Thats what I use for my Smart meter kWh and my gas meter.

If you want to use a rule to fill an item with your aggregated value it would be best to use persistence functions like deltaSince().

thanks for the quick response…

Ideally I want to have a fixed value per minute that states if I’m using from the supplier (paid) versus my credit.

To give an example,

During the day - I generate more than my house uses and so I supply back to the grid. This goes into credit and in HA this is Export.

During the night I use from the grid solely - and this is Import.

Now at the beginning of the night, the Export value is higher than Import value, and at some point those are equal and then Import is higher.

I want to be able to view when Export-Import <0 - and be able to switch on that…

So I would need to know much total I export and import in an aggregate value

So I guess the formula needs to be

When item WattsImport Changed

  • Get current time
  • Get Old value
  • Get Start time (old value)
    #Calculate
    $ToAdd=Old Value * (end time(seconds) - start time(seconds) / 60
    AggregateValue=AggregateValue + $ToAdd
  • Get new value
  • Set new value as old value

or something like this…

Or - I kick off an add every second

@EverySecond
AggregateValue=AggregateValue+(ImportValue/3600)

/3600 needs to be done to get to kW/h

Ok I think we need to state the facts first: Do you read your current power consumption, or do you read your energy consumption (kWh)?

I read current power