I want to count the number of defrost in a day in a counter. I found an example of a swith count in the manual like ths:
Code: Select all
return {
on = {
devices = { 'MySwitch' }
},
data = {
counter = { initial = 0 }
},
execute = function(domoticz, switch)
if (domoticz.data.counter == 5) then
domoticz.notify('The switch was pressed 5 times!')
domoticz.data.counter = 0 -- reset the counter
else
domoticz.data.counter = domoticz.data.counter + 1
end
end
}Code: Select all
return {
on = {
devices = { 55 }
},
execute = function(domoticz,device )
local numberDefrosts = domoticz.devices(78)
numberDefrosts.updateCounter(numberDefrosts.counter + 1)
end
}In my opinion simple and should work. It works BUT the numbers are not correct. I had 2 defrosts this night and the counter now is at 9. This morning it was 4. The switch logging looks like this:
Code: Select all
2020-05-15 07:03:07 Off MQTT
2020-05-15 06:58:08 Off MQTT
2020-05-15 06:53:07 Off MQTT
2020-05-15 06:48:08 Off MQTT
2020-05-15 06:47:21 Off MQTT
2020-05-15 06:43:07 On MQTT
2020-05-15 06:41:05 On MQTT
2020-05-15 06:38:08 Off MQTT
2020-05-15 06:33:08 Off MQTT
2020-05-15 06:28:07 Off MQTT
2020-05-15 06:23:07 Off MQTT
2020-05-15 06:18:07 Off MQTT
2020-05-15 06:13:08 Off MQTT
2020-05-15 06:08:08 Off MQTT
2020-05-15 06:03:09 Off MQTT
I us version 2020.1 on a Pi