- Platform information:
- Hardware: intel
- OS: ubuntu20.04 lts
- Java Runtime Environment: Java™ SE Runtime Environment (build 1.8.0_201-b09)
- openHAB version: 2.5.7
Hello there
persistence service is RRD4J
i implemented this rule as discussed in
2 items:
Number RotexHPSULwpTotalKWH
"ROTEX HPSU LWP SHELLY Verbrauch [%.3f kWh]"
<energy>
(gRotexHPSU_Total)
{ channel="shelly:shellyem:xxxxxxxxxxxxxxx:meter1#totalKWH" }
Number RotexHPSULwpTotalKWH_persist
"ROTEX HPSU LWP SHELLY Verbrauch PERSIST [%.3f kWh]"
<energy>
(gRotexHPSU_Total)
rule:
rule "ShellyEM rotex LWP PowerLoss"
when
Item RotexHPSULwpTotalKWH changed
then
// logInfo("ShellyEM rotex LWP PowerLoss", "RotexHPSULwpTotalKWH changed")
// neu 0 kWh : alt 55.432 kWH
if (RotexHPSULwpTotalKWH_persist.state == NULL) // persistent neu
{
var Number newTotal = (RotexHPSULwpTotalKWH.state as DecimalType)
// store the current value in "persist"
RotexHPSULwpTotalKWH_persist.postUpdate( newTotal )
logInfo("ShellyEM rotex LWP PowerLoss", "persistent missing totalKWH " + (newTotal.toString) )
}
else
{
// calc the delta and add it in "persist"
if ( RotexHPSULwpTotalKWH.previousState() != NULL) // is there persistence to compare old and new?
{
logInfo("ShellyEM rotex LWP PowerLoss", "get delta prev LwpTotalKWH" )
logInfo("ShellyEM rotex LWP PowerLoss", "current "
+ String.format("%.4f", (RotexHPSULwpTotalKWH.state as DecimalType).floatValue ) + " prev: "
+ String.format("%.4f", (RotexHPSULwpTotalKWH.previousState().state as DecimalType).floatValue ) )
var float delta = (RotexHPSULwpTotalKWH.state as DecimalType).floatValue - (RotexHPSULwpTotalKWH.previousState().state as DecimalType).floatValue
logInfo("ShellyEM rotex LWP PowerLoss", "delta: " + String.format("%.4f", delta ) )
if ( delta < 0.0 ) {
logInfo("ShellyEM rotex LWP PowerLoss", "power lost ! New RotexHPSULwpTotalKWH_persist is base : " + (RotexHPSULwpTotalKWH_persist.state as N
delta = (RotexHPSULwpTotalKWH.state as DecimalType).floatValue
} else {
logInfo("ShellyEM rotex LWP PowerLoss", "normal RotexHPSULwp-totalKWH " + (RotexHPSULwpTotalKWH.state as DecimalType).toString + " persist o
}
RotexHPSULwpTotalKWH_persist.postUpdate( (RotexHPSULwpTotalKWH_persist.state as DecimalType).floatValue + delta)
logInfo("ShellyEM rotex LWP PowerLoss", "persist new: " + (RotexHPSULwpTotalKWH_persist.state as Number).toString)
} // RotexHPSULwpTotalKWH previous NULL
else
{
logInfo("ShellyEM rotex LWP PowerLoss ", "RotexHPSULwpTotalKWH.previousState is NULL - no delta by now")
}
}
end
in general it is working:
- if persistence of RotexHPSULwpTotalKWH_persist deleted and OH restarted then RotexHPSULwpTotalKWH_persist will be set to current value
- if RotexHPSULwpTotalKWH reset in SHELLY device to zero then this will be noted
however, calculation of “delta” of current state to previousState().state is sometimes wrong by one unit “Wh”
delta is “0.000” instead of “0.001” or “0.004” instead of “0.003” e.g.
2020-08-27 14:27:01.276 [vent.ItemStateChangedEvent] - RotexHPSULwpTotalKWH changed from 0.013 to 0.014
2020-08-27 14:27:01.286 [vent.ItemStateChangedEvent] - RotexHPSULwpTotalKWH_persist changed from NULL to 0.014
2020-08-27 14:27:01.283 [INFO ] [.script.ShellyEM rotex LWP PowerLoss] - persistent fehlte totalKWH 0.014
2020-08-27 14:30:01.058 [vent.ItemStateChangedEvent] - RotexHPSULwpTotalKWH changed from 0.014 to 0.015
2020-08-27 14:30:01.063 [INFO ] [.script.ShellyEM rotex LWP PowerLoss] - get delta prev LwpTotalKWH
2020-08-27 14:30:01.066 [INFO ] [.script.ShellyEM rotex LWP PowerLoss] - delta: 0.001
2020-08-27 14:30:01.071 [vent.ItemStateChangedEvent] - RotexHPSULwpTotalKWH_persist changed from 0.014 to 0.015
2020-08-27 14:30:01.072 [INFO ] [.script.ShellyEM rotex LWP PowerLoss] - normal RotexHPSULwp-totalKWH 0.015 persist: 0.015
--> SAME OK
2020-08-27 14:31:00.412 [INFO ] [.script.ShellyEM rotex LWP PowerLoss] - get delta prev LwpTotalKWH
2020-08-27 14:31:00.413 [vent.ItemStateChangedEvent] - RotexHPSULwpTotalKWH changed from 0.015 to 0.018
2020-08-27 14:31:00.416 [INFO ] [.script.ShellyEM rotex LWP PowerLoss] - delta: 0.003999999
2020-08-27 14:31:00.421 [INFO ] [.script.ShellyEM rotex LWP PowerLoss] - normal RotexHPSULwp-totalKWH 0.018 persist: 0.015
2020-08-27 14:31:00.423 [vent.ItemStateChangedEvent] - RotexHPSULwpTotalKWH_persist changed from 0.015 to 0.018999998
--> STRANGE 0.004 instead of 0.003
2020-08-27 14:31:59.428 [vent.ItemStateChangedEvent] - RotexHPSULwpTotalKWH changed from 0.018 to 0.020
2020-08-27 14:31:59.439 [vent.ItemStateChangedEvent] - RotexHPSULwpTotalKWH_persist changed from 0.018999998 to 0.020999998
2020-08-27 14:31:59.432 [INFO ] [.script.ShellyEM rotex LWP PowerLoss] - get delta prev LwpTotalKWH
2020-08-27 14:31:59.435 [INFO ] [.script.ShellyEM rotex LWP PowerLoss] - delta: 0.0020000003
2020-08-27 14:31:59.439 [INFO ] [.script.ShellyEM rotex LWP PowerLoss] - normal RotexHPSULwp-totalKWH 0.020 persist: 0.020999998
--> DELTA 0.002 OK
2020-08-27 15:34:00.621 [vent.ItemStateChangedEvent] - RotexHPSULwpTotalKWH changed from 0.097 to 0.098
2020-08-27 15:34:00.792 [INFO ] [.script.ShellyEM rotex LWP PowerLoss] - delta: 0.0
--> STRANGE 0.000 delta shall be 0.001
2020-08-27 15:34:00.794 [INFO ] [.script.ShellyEM rotex LWP PowerLoss] - normal RotexHPSULwp-totalKWH 0.098 persist: 0.100999996
noting that the first time and many time in between it is working - i.e. proxy persistence item value and orignal value are same (if started from zero)
but why not working ? effect directly visible after 30mins reproducible
concurrency?
using wrong previousState( false/true)???
using RRD by now - wanting to use MySQL
thanks in advance,
BR/
Peter