DzVents + counter incremental

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

Moderator: leecollings

Post Reply
kimot
Posts: 113
Joined: Saturday 25 November 2017 17:18
Target OS: Raspberry Pi / ODroid
Domoticz version: v3.8153
Location: Czech Rep.
Contact:

DzVents + counter incremental

Post 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 1672 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.
RPi2 Domoticz v 4.10717
10 x Sonoff Basic - ESPeasy
1 x Wemos D1 - ESPeasy
1 x Shelly Plus Plug S
1 x Sonoff S26 - ESPeasy
1 x Shelly 1
1 x MySensors HC-SR04
1 x MySenosrs wifi gateway
1 x RFLink
4x Cam IPC-T240H
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: DzVents + counter incremental

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest