Reset incremental counter does not work  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
Delfuego
Posts: 32
Joined: Sunday 29 July 2018 16:18
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Netherlands
Contact:

Reset incremental counter does not work

Post 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 1783 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?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Reset incremental counter does not work

Post 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)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Delfuego
Posts: 32
Joined: Sunday 29 July 2018 16:18
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Netherlands
Contact:

Re: Reset incremental counter does not work  [Solved]

Post 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.
Biiiiino
Posts: 18
Joined: Monday 19 April 2021 18:15
Target OS: Linux
Domoticz version:
Contact:

Re: Reset incremental counter does not work

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest