Page 1 of 2
Water Meter, sensor type
Posted: Tuesday 18 April 2023 19:57
by flhoest
Dear All,
I'm using Domoticz since 2008, but I don't know why, I only register to this forum today ... don't ask me why
I'm starting to do some more advanced stuff, that's probably the reason.
I'm busy collecting the water meter data, but this is not where I need support. Part of my workflow, I'm updating the data using Domoticz API.
Something similar to this :
Code: Select all
?type=command¶m=udevice&idx=5997&nvalue=0&svalue=45
The questions are :
- What type of virtual sensor is best for collecting water usage ? I've tried many : counter incremental, custom sensor, water flow ... I still cannot decide what's the best option.
- In the above API call, I need to understand what nvalue and svalue stands for. I understood svalue is the usage since the last measure. So, when I read my meter, I substrating the current value with the previous value, so I have my usage, and this is that value that I need to send to domoticz to see the usage per time interval. Am I right ?
Thanks for the support.
Take care,
Fred.
Re: Water Meter, sensor type
Posted: Wednesday 19 April 2023 10:03
by flhoest
Nobody ?
Re: Water Meter, sensor type
Posted: Wednesday 19 April 2023 19:41
by RedEarth
Re: Water Meter, sensor type
Posted: Wednesday 19 April 2023 20:32
by waltervl
What are you trying to measure?
A counter device can visualize the hourly, daily, monthly, yearly usage.
A waterflow device can visualize the current flow (if you send the data)
See also wiki for overview of all possible devices
https://www.domoticz.com/wiki/Dummy_for ... #Waterflow
Re: Water Meter, sensor type
Posted: Wednesday 19 April 2023 21:04
by flhoest
waltervl wrote: ↑Wednesday 19 April 2023 20:32
What are you trying to measure?
A counter device can visualize the hourly, daily, monthly, yearly usage.
A waterflow device can visualize the current flow (if you send the data)
See also wiki for overview of all possible devices
https://www.domoticz.com/wiki/Dummy_for ... #Waterflow
Hi,
Thanks for replying, I already checked indeed. Waterflow is not what I need, because I only measure a delta usage between 2 readings. At the end, it will give me a usage (in liter) for each hours, days, weeks, month ... I think the counter is the best option.
The question is more about the nvalue and svalue .... is there any official documentation explaining what it is ?
Thanks.
Re: Water Meter, sensor type
Posted: Wednesday 19 April 2023 21:06
by waltervl
See the wiki that redhearth already gave.
Re: Water Meter, sensor type
Posted: Wednesday 19 April 2023 21:07
by flhoest
Hi there,
Thanks for your reply, I was looking at it ... I saw this :
Code: Select all
json.htm?type=command¶m=udevice&idx=IDX&nvalue=0&svalue=COUNTER;USAGE
I have the feeling that I need to replace the value COUNTER by the total reading on the counter and USAGE seems to be the difference between actual value and previous measure, which is giving a "usage" or "consumption" ...
However it is still not clear what nvalue=0 means ...
Thanks again.
Re: Water Meter, sensor type
Posted: Wednesday 19 April 2023 21:30
by waltervl
For a water meter you can use counter with nvalue counter or incremental counter with nvalue is Incremental (delta).
It depends how you measure the watermeter. If you use pulse switch you better use incremental, if you can read the watermeter counter as if you take a snapshot of the watermeter counter every minute you can use the normal counter (in the wiki above the incremental). Nvalue=0 has no extra meaning then you have to supply it for this type of counter.
How do you read your watermeter?
Re: Water Meter, sensor type
Posted: Wednesday 19 April 2023 21:36
by flhoest
@waltervi,
I'm using AI on the Edge project with ESP32-CAM then I use a php script that maintain the virtual sensor.
I'm in the process of writing this script - this is why I'm asking those questions. I have a new value every 5 minutes and I'm recording current value and previous value which gives me a delta indeed.
So I guess I will go the above way when I was talking about CONTER;USAGE
Re: Water Meter, sensor type
Posted: Wednesday 19 April 2023 21:45
by waltervl
CONTER;USAGE is only for electricity, not for water.
If you see the whole total counter value every 5 minutes you only have to send that to Domoticz with
Code: Select all
/json.htm?type=command¶m=udevice&idx=IDX&svalue=COUNTER
No need to store the old value. Simplifies your AI application.
Domoticz will calculate hourly , Daily etc usage from the counter values it receives.
Re: Water Meter, sensor type
Posted: Wednesday 19 April 2023 21:47
by flhoest
Oh really ? this is awesome

I will continue testing ...
Thanks a lot for sharing your knowledge !
Re: Water Meter, sensor type
Posted: Wednesday 19 April 2023 23:44
by FireWizard
Hi @ flhoest,
I would recommend to use a "Counter". After you have created a "Counter" virtual device, you can edit the widget and select as "Type" water.
You send the value to the device as your Delta in liters.
See also the discussion at:
viewtopic.php?p=293538&hilit=water#p293538
And just for your information:
nvalue stands for Numerical value (Integer or Float) while svalue stands for String value.
The counter device needs a String value, so take care that you send a string (and not a number). So something like "1234".
You can safely omit nvalue, in this case.
Regards
Re: Water Meter, sensor type
Posted: Thursday 20 April 2023 8:55
by flhoest
FireWizard wrote: ↑Wednesday 19 April 2023 23:44
Hi @ flhoest,
I would recommend to use a "Counter". After you have created a "Counter" virtual device, you can edit the widget and select as "Type" water.
You send the value to the device as your Delta in liters.
See also the discussion at:
viewtopic.php?p=293538&hilit=water#p293538
And just for your information:
nvalue stands for Numerical value (Integer or Float) while svalue stands for String value.
The counter device needs a String value, so take care that you send a string (and not a number). So something like "1234".
You can safely omit nvalue, in this case.
Regards
Fantastic, I like your information, at last something straight forward. It's a bit a shame this is not clearly explained in the wiki ... or I missed it.
Re: Water Meter, sensor type
Posted: Thursday 20 April 2023 17:39
by waltervl
But for every device the content nValue and sValue could mean something else....
Looking back it is a very strange protocol for sending values and states to devices. But it is there and we have to deal with it

Re: Water Meter, sensor type
Posted: Thursday 20 April 2023 18:27
by Kedi
I use the same "AI-on-the-edge-device" project for my Water meter.
I use NodeRed with this function to get data to Domoticz
Code: Select all
var IDX = global.get('idxTable','memoryOnly')['Water'].idx;
var msg1 = {};
var msg2 = {};
if (msg.payload.error == 'no error') {
msg1.payload = { "command": "udevice", "idx": IDX, "svalue": msg.payload.value.toString()};
msg2.payload = { "command": "addlogmessage", "message": "Water value: "+msg.payload.value.toString()};
} else {
msg1.payload = { "command": "addlogmessage", "message": "Water ERROR: "+msg.payload.error};
// msg2.payload = { "command": "sendnotification", "subject": "WATER ERROR!", "subsystem": "pushover", "body": msg.payload.error, "priority": 0};
}
//return msg;
return [[msg1, msg2]];
and have this Device in Domoticz.

- 20.04.2023_18.26.11_REC.png (12.08 KiB) Viewed 3410 times
This works fine with a nice history.
Re: Water Meter, sensor type
Posted: Thursday 20 April 2023 19:44
by flhoest
Would you mind showing me the history graph?
Re: Water Meter, sensor type
Posted: Thursday 20 April 2023 21:24
by flhoest
I managed to create a php script that reads from the "AI-on-the-edge" and pushes to Domoticz. I have the feeling the logic is good, but I still need more hours to have complete confirmation it is working fine ...
Code: Select all
<?php
$espIP="192.168.x.x";
$domoticzIP="192.168.x.x";
$sensorIDX="xxxx";
// -------------------------------------------------------
// Function to retrieve the ESP32-CAM reading of the meter
// -------------------------------------------------------
function espGetValue($espIP)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Accept: application/json, text/plain, */*',
'Content-Type: application/json;charset=utf-8'
));
curl_setopt($curl, CURLOPT_URL, "http://".$espIP."/json");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
$result=json_decode($result);
if($result -> main -> error == "no error")
{
return $result -> main -> value;
}
else return FALSE;
}
// ------------------------------------------
// Function to push data to a Domoticz sensor
// ------------------------------------------
function sendToSensor($domoticzIP,$sensorIDX,$val)
{
/* API Reference : https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s#Electricity_.28instant_and_counter.29 */
$API=$domoticzIP;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Accept: application/json, text/plain, */*',
'Content-Type: application/json;charset=utf-8'
));
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_URL, "https://".$API."/json.htm?type=command¶m=udevice&idx=".$sensorIDX."&nvalue=0&svalue=".$val);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
if(json_decode($result)->status=="OK") return TRUE;
else return FALSE;
}
// =======================================================
// Entry point
// =======================================================
$res=espGetValue($espIP);
if($res)
{
print("-> Value is ".$res." m3\n");
print("=> Pushing data to Domoticz sensor...");
sendToSensor($domoticzIP,$sensorIDX,$res);
print("\nDone.\n\n") ;
}
else
{
print(">> Nothing to do.\n\n");
}
?>
Sorry, I'm a big fan of Php

Re: Water Meter, sensor type
Posted: Thursday 20 April 2023 22:30
by waltervl
Nice solution!
This would be an easy one in dzvents with openURL and item.json conversion.dzvents script is stored into the database so easy to maintain within the Domoticz application.
Re: Water Meter, sensor type
Posted: Thursday 20 April 2023 22:31
by flhoest
Thanks

Re: Water Meter, sensor type
Posted: Friday 21 April 2023 13:13
by Kedi
flhoest wrote: ↑Thursday 20 April 2023 19:44
Would you mind showing me the history graph?
No problem.
B.t.w. your Sig. states "Using Domoticz on Raspberry 3B+ since 2008" Are you sure? Release date of the 3B+ is 2018

- 21.04.2023_13.12.12_REC.png (175.38 KiB) Viewed 3361 times