Page 1 of 1

Reset incremental counter does not work

Posted: Thursday 07 January 2021 10:04
by Delfuego
I have created a water meter in Domoticz using an inductieve NPN sensor on a GPIO of my Pi. The puls from the NPN increments an incremental counter and for that I use dzVents. Everything works fine and the counter is in sync with the real water meter.

Now I want to monitor the water usage of one day. So I created a second incremental counter. This counter I want to reset to zero at 0:00 h. Only problem is that it does not reset to zero.

Code: Select all

return {
	on = { timer = {'at 0:00'},
		   devices = { 'Waterpuls' },
	     },
	execute = function(domoticz, device)
        if (device.trigger == 'at 0:00') then
            domoticz.devices('Waterverbruik dag').updateCounter(0)
            print ('Reset Waterverbruik dag')
        end
        if (device.name == 'Waterpuls' and device.state == 'On') then
            domoticz.devices('Waterverbruik').incrementCounter(1)
            domoticz.devices('Waterverbruik dag').incrementCounter(1)
        end
	end
}
For what I understand from the dzVents documentation the updateCounter statement should overwrite the value of the counter. But nothing seems to happen. So as an experiment I changed the updateCounter(0) with updateCounter(1) and to my surprise the counter got incremented.
Schermafbeelding 2021-01-07 om 09.44.41.png
Schermafbeelding 2021-01-07 om 09.44.41.png (77.37 KiB) Viewed 1784 times
What I want is the 0.285 value in the image above to reset to zero at midnight. I want to use this value in Dashticz to present today's water usage.

Can anybody help?

Re: Reset incremental counter does not work

Posted: Thursday 07 January 2021 14:12
by waaren
Delfuego wrote: Thursday 07 January 2021 10:04 I have created a water meter in Domoticz using an inductieve NPN sensor on a GPIO of my Pi. The puls from the NPN increments an incremental counter and for that I use dzVents. Everything works fine and the counter is in sync with the real water meter.

Now I want to monitor the water usage of one day. So I created a second incremental counter. This counter I want to reset to zero at 0:00 h. Only problem is that it does not reset to zero.

For what I understand from the dzVents documentation the updateCounter statement should overwrite the value of the counter.
Thx for reporting.

The updateCounter method does not overwrite the value of an incremental counter but increments just like the incrementCounter method.
The wiki is not clear on this and will be updated.

There are two options to code your requirement.

1st. Remove current day incremental counter because this has now long term history in the database and recreate it.

Code: Select all

if (device.trigger == 'at 23:54') then -- 23:54 to ensure dayvalue does not go to long term history  
   local dagVerbruik = domoticz.devices('Waterverbruik dag')
   local counterDivider = 1000 -- 1000 is depending on the counter divider set for the device
   dagVerbruik.incrementCounter( -1 * dagVerbruik.counter * counterDivider ) -- actual decrement
2nd. Use new standard Counter

Code: Select all

if (device.trigger == 'at 23:54') then -- 23:54 to ensure dayvalue does not go to long term history  
    local dagVerbruik = domoticz.devices('Waterverbruik dag')
    dagVerbruik.updateCounter(0)

Re: Reset incremental counter does not work  [Solved]

Posted: Thursday 07 January 2021 16:40
by Delfuego
Thank you for your respons. Very helpful.

I replaced the second incremental counter with a standard counter. Everything now works as wanted!

For the record; The counter divider gave me some extra headache. So other enthusiasts using these counters must be aware of this divider as you pointed out.

Re: Reset incremental counter does not work

Posted: Monday 03 October 2022 14:20
by Biiiiino
Hello, is there any update how to reset Reset incremental counter please ? I have no other option, just this one and i need to reset whole datas from the counter.

Thanks in advance