I am on latest stable OH4.x and am struggling with a rule:
I have an number item which gets updated with a metering value every 5-10 sec. I want to keep track of the usage (here divided by 1000) since midnight and since noon.
Since midnight works - both since noon only keeps the right value until midnight - and then gets reset to 0 and stays 0 until noon. How can I mitigate this ? Do I need to add logic to swap the now.with(LocalTime to .MIN after midnight and LocalTime.NOON before? There must be a simpler way ?
var Number todayKWh
todayKWh = (wattslive_positive_active_energy.deltaSince(now.with(LocalTime.MIN), "rrd4j")) / 1000
electricity_meter_dailyTotalKWh.postUpdate(todayKWh)
var Number noonKWh
noonKWh = (wattslive_positive_active_energy.deltaSince(now.with(LocalTime.NOON), "rrd4j")) / 1000
electricity_meter_noonTotalKWh.postUpdate(noonKWh)
var noon = now.with(LocalTime.NOON)
if (now.isBefore(noon)) {
noon = noon.minusDays(1)
}
var noonKWh = wattslive_positive_active_energy.deltaSince(noon, "rrd4j") / 1000
electricity_meter_noonTotalKWh.postUpdate(noonKWh)
Additional note: rrd4j isn’t the best backend for doing these sorts of things. Pick influxdb or something, anything other than rrd4j (or mapdb). rrd4j is lossy.