I’m having a problem calculating energy consumption values. I am an a dual electricity tariff. My smart meter will tell me (via MQTT) how much energy I have consumed in the day but it doesn’t divide it into peak and off peak. To do this, I will store the meter reading (in Wh) at the start of the period and each time the meter is updated, I will subtract the current reading from the value at the start of the period.
I have these items:
Number:Energy elecSop "Electricity Import Meter Reading at start of period [%.0f Wh]"
Number:Energy elecInMeter "Electricity Import Meter Reading [%.0f Wh]" { channel="mqtt:topic:SmartMeters:elecInMeter" }
Number:Energy elecPeakToday "Peak time electricity usage today [%.0f Wh]"
Using a cron rule, I copy the current meter reading from elecInMeter
to the elecSop
item. For example, this is what it is currently showing:
When I use this rule:
rule ConsumptionMeasurement
when Item elecInMeter received update
then
var Reading = elecInMeter.state as Number
var StartOfPeriod = elecSop.state as Number
var UsedEnergy = Reading-StartOfPeriod
logWarn("rules.energy", "Peak time, Meter Reading: "+elecInMeter.state.toString+" SoP: "+ elecSop.state.toString+" Period: "+UsedEnergy.toStrin$
elecPeakToday.postUpdate(UsedEnergy)
end
I get this:
2021-05-23 14:41:34.408 [WARN ] [enhab.core.model.script.rules.energy] - Peak time, Meter Reading: 1103043.0 Wh SoP: 1102987.0 Wh Period: 226800.0
In other words, despite the items both being scoped in Wh and the start of period value being a copy of the meter reading, the calculation is producing a result in Watt Seconds