Hi,
I want to display the Gas Usage from a smart meter (DSMR binding). However: the gas usage only updates once an hour and remains constant in between (for example: now it’s 1.000 and in an hour it’s 1.500). The actual usage can only be calculated as a usage per hour.
Now I am struggling with this calculation. I want some rule, which holds the changed value (in this example 1.5 minus 1 = 0.5) and displays that until the next change or at a max of 1 hour).
The DSMR binding is working flawlessly. The issue is how to hold the 0.5 when every 10 seconds the value from the binding is updated. (simple calculation only show 0.5 for 10 seconds and then 0 the remaining hour).
My items:
String P1_Gas_Device_Type “Gasmeter Device Type [%s]” {dsmr=“gDeviceType”}
String P1_Gas_EquipmentId “Gasmeter Equipment ID [%s]” {dsmr=“gEquipmentId”}
String P1_Gas_Timestamp “Gasmeter last measurement timestamp [%s]” {dsmr=“gValueTS”}
Number P1_Gas_Actual_Usage “Gasverbruik meterstand [%s]” {dsmr=“gValue”}
Number P1_Gas_Actual_Usage_Tmin1 “Gasverbruik meterstand T-1 [%s]” {dsmr=“gValue2”}
Number P1_Gas_Used "Gasverbruik actueel [%.3f m3]"
Number P1_Gas_Used_Chart
Number P1_Gas_Last_Value "Laatste gasmeter stand [%.3f m3]"
Switch P1_Gas_Last_Value_Reset “Reset Last Gas Value”
Number P1_Gas_Counter_last_change “P1 Gas Counter Last Change”
The P1_Gas_Counter_last_change should be counting since the last change.
The rules:
rule “Reset Last Gas Value”
// resetting the Last Gas Value and the counter based on a switch in the sitemap. This to be used on startup or as a test.
when
Item P1_Gas_Last_Value_Reset changed
then
var Number CurrentGasValue
var int ResetGasCounter = 0
CurrentGasValue = P1_Gas_Actual_Usage.state
postUpdate (P1_Gas_Counter_last_change,ResetGasCounter)
postUpdate (P1_Gas_Last_Value,CurrentGasValue)
end
rule “Lengthen Gas Usage”
// when the actual usage changes, counter is being resetted as a base to lengthen the display time
when
Item P1_Gas_Actual_Usage changed
then
var Number P1GasActualUsage
var int ResetGasCounter = 0
P1GasActualUsage=P1_Gas_Actual_Usage.state
if (P1GasActualUsage > 0) {
postUpdate(P1_Gas_Counter_last_change,ResetGasCounter)
postUpdate(P1_Gas_Used,P1GasActualUsage)
}
logInfo("PV-GET",P1GasActualUsage)
end
rule "Maintain Gas Usage Counter"
when
// cron for every 5 minutes, reset counter after 14*5 minutes (70 minutes) max. Also clear the actual gas usage (if the usage would be 0 for a longer time, so there wouldn’t be any change noted.
Time cron “0 0/5 * * * ?”
then
var Number P1GasCounterLastChange
var Number ResetValue = 0
P1GasCounterLastChange=P1_Gas_Counter_last_change.state
P1GasCounterLastChange=P1GasCounterLastChange+1
postUpdate(P1_Gas_Counter_last_change, P1GasCounterLastChange)
if (P1GasCounterLastChange > 14) {
postUpdate(P1_Gas_Counter_last_change,ResetValue)
postUpdate(P1_Gas_Used,ResetValue)
}
end
Hope my aim is clear and somebody is able to help