DzVents + counter incremental
Posted: Monday 27 May 2019 17:05
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:
After a couple a minutes I can see this:
JSON updates counter correctly, but updateCounter() function do not add value, but simply store value into counter.
Ok - I try something different:
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:
I think this behavior of counter incremental should be mentioned in the documentation.
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¶m=udevice&idx=65&svalue=10'
print(url)
domoticz.openURL(url)
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)
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