[SOLVED] Using sumSince when values of item might be the same on every update?

I want to calculate total power used for given day. I have this kind of data comming in via mqtt every minute:


My item config:

Number ComfoAir_POW_Period "ComfoAir power usage Since Last Period" (gPersistEveryChange){ mqtt="<[mosquitto:pow/hrv1/status:state:JSONPATH($.Data.Period)]" }

And my rule:

rule "Update ComfoAir POW Totals for the day"
  Item ComfoAir_POW_Period received update

gPersistEveryChange is a group that has everyChange strategy hooked up for influxdb

Now since the power usage is quite stable, I usually get the same value (0.250), so changed event is not fired on ComfoAir_POW_Period I somehow though that received update would help me here, but no - ComfoAir_POW_Daily only changes when ComfoAir_POW_Period gets a different value than before. I must be misunderstanding some basic concept here - but how do I use that sumSince ? Should I use saving every minute instead of everyChange, would sum work?

Or maybe I should just do a manual sum in my rule, and the do a reset to zero for ComfoAir_POW_Daily with cron at midnight?

You need to use everyX where X is how often the ComfoAir reports a value. This will only work if it reports on a fixed schedule.

sumSince literally just adds up all the values in the database since the time given. So the entries in the DB need to make sense. If you save every minute but the device only reports every 10 minutes, your sumSince will be 10x too large.

For the Rule trigger or for the persistence strategy? If you just changed the Rule that doesn’t do anything. You have to make sure that the values get saved to the DB on the update.You will also want to fire your Rule on every update too, but if the persistence strategy doesn’t save every update then your Rule will always generate the wrong answer.

With both the persistence strategy and the Rule working on every update it should work.

Ok, so the unit is seding updates every minute. So with save on everyMinute I should be fine until the unit goes down. Then my math gets totally wrong - because the unit is down, power usage is 0 but with persist on everyMinute I will be persisting last known value.

So afaik I’m better off with manual Math in my rule with received update ?

Sounds like a job for expire binding, if no updates come in for two minutes reset the instantaneous power Item to zero.

how do you measure the power for this item? if it’s a Sonoff POW, you can easily just take it’s calculated Overall power measurement:
[mosquitto:pow/hrv1/status:state:JSONPATH($.ENERGY.Total)] (for using Tasmota)
The POW already sums up the measured power and you don’t need to do that again in rules and persistence and stuff…?

Thanks, never knew those existed

Yes, all is fine with tasmota, but this is a custom made python script that runs on remote raspberry and calculates impulses via impulse output on the 3 phase meter

For now I have reverted to this kind of logic, and it seems to be working fine

rule "Update ComfoAir POW Totals At midnight"
  Time cron "0 0 0 * * ? *"

rule "Update ComfoAir POW Totals for the day"
  Item ComfoAir_POW_Period received update
  val period = ComfoAir_POW_Period.state as DecimalType
  val forToday = ComfoAir_POW_Daily.state as DecimalType

Many bindings will set an Item to UNDEF in the event of communications failure.
That’s a bit harder when you are relying on incoming unsolicited messages, like MQTT.
Expire binding was invented for this (but has a lot of other uses!)

But MQTT itself does have a feature that you should be able to exploit, LWT.
Example -