I will also have a separate script on two separate virtual GAS devices that just increments the value each minute for the first device and increments the value only on 2 minutes after the hour for the second device. The script will log the counter value.
This is the simple script used:
Code: Select all
return {
on = {
timer = {
'every minute', -- causes the script to be called every minute
}
},
logging = {
level = domoticz.LOG_INFO,
marker = 'device counter test',
},
execute = function(domoticz, timer)
domoticz.log('Timer event was triggered by ' .. timer.trigger, domoticz.LOG_INFO)
-- update every minute
local currentvalue=domoticz.devices(88).counter
domoticz.log('Current counter value for device 88 is ' .. currentvalue, domoticz.LOG_INFO)
domoticz.log('Current counterToday value for device 88 is ' .. domoticz.devices(88).counterToday, domoticz.LOG_INFO)
newvalue=currentvalue+1
domoticz.devices(88).updateGas(newvalue*1000)
domoticz.log('Device 88 updated to ' .. newvalue, domoticz.LOG_INFO)
-- only update 2 minutes past the hour
currentvalue=domoticz.devices(89).counter
domoticz.log('Current counter value for device 89 is ' .. currentvalue, domoticz.LOG_INFO)
domoticz.log('Current counterToday value for device 89 is ' .. domoticz.devices(89).counterToday, domoticz.LOG_INFO)
if domoticz.time.minutes==2 then
newvalue=currentvalue+1
domoticz.devices(89).updateGas(newvalue*1000)
domoticz.log('Device 89 updated to ' .. newvalue, domoticz.LOG_INFO)
end
end
}
And this was the result in the log file. Errors highlighted in red. It is clear that counter value for the GAS device 88 was incorrectly set to 0 even before the first update after 00:00 at 00:01. Also counterToday shows a strange value.
The update of the other GAS device (nr 89) at 00:02 however is done correctly.
2022-09-10 00:00:00.473 Status: dzVents: Info: device counter test: ------ Start internal script: Script #2:, trigger: "every minute"
2022-09-10 00:00:00.473 Status: dzVents: Info: device counter test: Timer event was triggered by every minute
2022-09-10 00:00:00.475 Status: dzVents: Info: device counter test: Current counter value for device 88 is 432.0
2022-09-10 00:00:00.475 Status: dzVents: Info: device counter test: Current counterToday value for device 88 is 432.0
2022-09-10 00:00:00.475 Status: dzVents: Info: device counter test: Device 88 updated to 433.0
2022-09-10 00:00:00.476 Status: dzVents: Info: device counter test: Current counter value for device 89 is 6.0
2022-09-10 00:00:00.476 Status: dzVents: Info: device counter test: Current counterToday value for device 89 is 6.0
2022-09-10 00:00:00.476 Status: dzVents: Info: device counter test: ------ Finished Script #2
2022-09-10 00:00:01.174 Status: EventSystem: reset all events...
2022-09-10 00:01:00.477 Status: dzVents: Info: device counter test: ------ Start internal script: Script #2:, trigger: "every minute"
2022-09-10 00:01:00.477 Status: dzVents: Info: device counter test: Timer event was triggered by every minute
2022-09-10 00:01:00.495 Status: dzVents: Info: device counter test: Current counter value for device 88 is
0.0
2022-09-10 00:01:00.495 Status: dzVents: Info: device counter test: Current counterToday value for device 88 is 0.0
2022-09-10 00:01:00.496 Status: dzVents: Info: device counter test: Device 88 updated to 1.0
2022-09-10 00:01:00.497 Status: dzVents: Info: device counter test: Current counter value for device 89 is 6.0
2022-09-10 00:01:00.497 Status: dzVents: Info: device counter test: Current counterToday value for device 89 is 6.0
2022-09-10 00:01:00.497 Status: dzVents: Info: device counter test: ------ Finished Script #2
2022-09-10 00:02:00.488 Status: dzVents: Info: device counter test: ------ Start internal script: Script #2:, trigger: "every minute"
2022-09-10 00:02:00.488 Status: dzVents: Info: device counter test: Timer event was triggered by every minute
2022-09-10 00:02:00.506 Status: dzVents: Info: device counter test: Current counter value for device 88 is
1.0
2022-09-10 00:02:00.506 Status: dzVents: Info: device counter test: Current counterToday value for device 88 is
1.8446744073709e+16
2022-09-10 00:02:00.507 Status: dzVents: Info: device counter test: Device 88 updated to 2.0
2022-09-10 00:02:00.508 Status: dzVents: Info: device counter test: Current counter value for device 89 is 6.0
2022-09-10 00:02:00.508 Status: dzVents: Info: device counter test: Current counterToday value for device 89 is 6.0
2022-09-10 00:02:00.508 Status: dzVents: Info: device counter test: Device 89 updated to 7.0
2022-09-10 00:02:00.508 Status: dzVents: Info: device counter test: ------ Finished Script #2
2022-09-10 00:03:00.501 Status: dzVents: Info: device counter test: ------ Start internal script: Script #2:, trigger: "every minute"
2022-09-10 00:03:00.501 Status: dzVents: Info: device counter test: Timer event was triggered by every minute
2022-09-10 00:03:00.520 Status: dzVents: Info: device counter test: Current counter value for device 88 is
2.0
2022-09-10 00:03:00.520 Status: dzVents: Info: device counter test: Current counterToday value for device 88 is
1.8446744073709e+16
2022-09-10 00:03:00.520 Status: dzVents: Info: device counter test: Device 88 updated to 3.0
2022-09-10 00:03:00.521 Status: dzVents: Info: device counter test: Current counter value for device 89 is 7.0
2022-09-10 00:03:00.521 Status: dzVents: Info: device counter test: Current counterToday value for device 89 is 1.0
2022-09-10 00:03:00.521 Status: dzVents: Info: device counter test: ------ Finished Script #2
2022-09-10 00:04:00.512 Status: dzVents: Info: device counter test: ------ Start internal script: Script #2:, trigger: "every minute"
2022-09-10 00:04:00.513 Status: dzVents: Info: device counter test: Timer event was triggered by every minute
2022-09-10 00:04:00.532 Status: dzVents: Info: device counter test: Current counter value for device 88 is
3.0
2022-09-10 00:04:00.532 Status: dzVents: Info: device counter test: Current counterToday value for device 88 is
1.8446744073709e+16
2022-09-10 00:04:00.532 Status: dzVents: Info: device counter test: Device 88 updated to 4.0
2022-09-10 00:04:00.533 Status: dzVents: Info: device counter test: Current counter value for device 89 is 7.0
2022-09-10 00:04:00.534 Status: dzVents: Info: device counter test: Current counterToday value for device 89 is 1.0
2022-09-10 00:04:00.534 Status: dzVents: Info: device counter test: ------ Finished Script #2
2022-09-10 00:05:00.530 Status: dzVents: Info: device counter test: ------ Start internal script: Script #2:, trigger: "every minute"
2022-09-10 00:05:00.530 Status: dzVents: Info: device counter test: Timer event was triggered by every minute
2022-09-10 00:05:00.548 Status: dzVents: Info: device counter test: Current counter value for device 88 is
4.0
2022-09-10 00:05:00.548 Status: dzVents: Info: device counter test: Current counterToday value for device 88 is
1.8446744073709e+16
2022-09-10 00:05:00.548 Status: dzVents: Info: device counter test: Device 88 updated to 5.0
2022-09-10 00:05:00.549 Status: dzVents: Info: device counter test: Current counter value for device 89 is 7.0
2022-09-10 00:05:00.549 Status: dzVents: Info: device counter test: Current counterToday value for device 89 is 1.0
2022-09-10 00:05:00.549 Status: dzVents: Info: device counter test: ------ Finished Script #2
2022-09-10 00:06:00.536 Status: dzVents: Info: device counter test: ------ Start internal script: Script #2:, trigger: "every minute"
2022-09-10 00:06:00.536 Status: dzVents: Info: device counter test: Timer event was triggered by every minute
2022-09-10 00:06:00.554 Status: dzVents: Info: device counter test: Current counter value for device 88 is
5.0
2022-09-10 00:06:00.554 Status: dzVents: Info: device counter test: Current counterToday value for device 88 is
1.0
2022-09-10 00:06:00.554 Status: dzVents: Info: device counter test: Device 88 updated to 6.0
2022-09-10 00:06:00.556 Status: dzVents: Info: device counter test: Current counter value for device 89 is 7.0
2022-09-10 00:06:00.556 Status: dzVents: Info: device counter test: Current counterToday value for device 89 is 1.0
2022-09-10 00:06:00.556 Status: dzVents: Info: device counter test: ------ Finished Script #2
And below is the file domoticzData.lua dump. It show the same incorrect counter and counterToday value but a correct updated state and raw_date.
[58] = {
["signalLevel"] = 12;
["iconNumber"] = 200;
["switchType"] = "On/Off";
["data"] = {
["icon"] = "counter";
["customImage"] = 0;
["counterToday"] = "0.000 m3";
["_nValue"] = 0;
["unit"] = 1;
["counter"] = "0.000";
["hardwareName"] = "Gas usage";
["hardwareTypeValue"] = 15;
["protected"] = false;
["hardwareID"] = 7;
["_state"] = "433000.0";
["hardwareType"] = "Dummy (Does nothing, use for virtual switches only)";
};
["deviceID"] = "82088";
["switchTypeValue"] = 0;
["deviceType"] = "P1 Smart Meter";
["subType"] = "Gas";
["lastUpdate"] = "2022-09-10 00:00:00";
["rawData"] = {
[1] = "433000.0";
};
["timedOut"] = false;
["batteryLevel"] = 255;
["description"] = "";
["protected"] = false;
["baseType"] = "device";
["lastLevel"] = 0;
["changed"] = false;
["image"] = "";
["id"] = 88;
["name"] = "for testing only";
};