Page 1 of 1

DzVents + counter incremental

Posted: Monday 27 May 2019 17:05
by kimot
I build tank level sensor, which sends water level in cm to Domoticz.
In Domoticz I created dummy volume and percent sensors and calculate volume in m3 and percent.
It works fine.
I try calculate "incoming" and "outcoming" volume of water in m3 too.
So I created two dummy counter incremental sensors.
But update ( better say increment ) its values using domoticz object is a bit chalenge.
I use this type of counter with ESPeasy and JSON api previously without any problem, but DzVents update do not works.
So I build testing counters "Counter_http" with Domoticz IDX=65 and "Counter_script" and make some experiments.

I call DzvVents script every minute to try add fixed value "10" to both counters:

Code: Select all

domoticz.devices('Counter_script').updateCounter(10)

local url= 'http://192.168.1.2:8080/json.htm?type=command&param=udevice&idx=65&svalue=10'
print(url)
domoticz.openURL(url)
After a couple a minutes I can see this:
2019-05-27-150011_1920x1080_scrot.png
2019-05-27-150011_1920x1080_scrot.png (94.06 KiB) Viewed 1674 times
JSON updates counter correctly, but updateCounter() function do not add value, but simply store value into counter.

Ok - I try something different:

Code: Select all

local aktual = domoticz.devices('Counter_script').counter  + 10
domoticz.devices('Counter_script').updateCounter(aktual)
Now I obtain error message, that I cannot store floating point number in to counter.
But where I obtain this floating? Only from updateCounter function...

Ok- I send values in liters, and water counter counts in m3, so my counter divider is set to 1000.
It seems, that you cannot send floating point to counter, but if you get counter value by devices().counter, you obtain floating point number - super.

So last and finally functional solution:

Code: Select all

local aktual = domoticz.devices('Counter_script').counter * 1000 + 10   --recalculate to liters and add new value
domoticz.devices('Counter_script').updateCounter(aktual)                   -- store new value in liters to counter
I think this behavior of counter incremental should be mentioned in the documentation.

Re: DzVents + counter incremental

Posted: Monday 27 May 2019 21:47
by waaren
kimot wrote: Monday 27 May 2019 17:05 .. But update ( better say increment ) its values using domoticz object is a bit challenge.
Ithe dzVents updateCounter does what the name implies; it updates the counter. It would be nice if there was also an incrementCounter method but it's not part of dzVents yet. It is on my todo list.
it seems, that you cannot send floating point to counter, but if you get counter value by devices().counter, you obtain floating point number - super.
I cannot replicate this is in latest stable or latest Beta. What is the errormessage you see ?
I think this behavior of counter incremental should be mentioned in the documentation.
You have a point here. Should be clear in the documentation