Water Meter, sensor type

Moderator: leecollings

User avatar
flhoest
Posts: 18
Joined: Tuesday 18 April 2023 19:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Belgium
Contact:

Water Meter, sensor type

Post 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&param=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.
Fred
Using Domoticz on Raspberry 3B+ since 2018
Fan of automation, API and PhP.
User avatar
flhoest
Posts: 18
Joined: Tuesday 18 April 2023 19:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Belgium
Contact:

Re: Water Meter, sensor type

Post by flhoest »

Nobody ?
Fred
Using Domoticz on Raspberry 3B+ since 2018
Fan of automation, API and PhP.
RedEarth
Posts: 23
Joined: Monday 31 October 2016 11:16
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Water Meter, sensor type

Post by RedEarth »

User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Water Meter, sensor type

Post 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
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
flhoest
Posts: 18
Joined: Tuesday 18 April 2023 19:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Belgium
Contact:

Re: Water Meter, sensor type

Post 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.
Fred
Using Domoticz on Raspberry 3B+ since 2018
Fan of automation, API and PhP.
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Water Meter, sensor type

Post by waltervl »

See the wiki that redhearth already gave.
RedEarth wrote: Wednesday 19 April 2023 19:41 have you tried the wiki?

https://www.domoticz.com/wiki/Domoticz_ ... ncremental
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
flhoest
Posts: 18
Joined: Tuesday 18 April 2023 19:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Belgium
Contact:

Re: Water Meter, sensor type

Post by flhoest »

RedEarth wrote: Wednesday 19 April 2023 19:41 have you tried the wiki?

https://www.domoticz.com/wiki/Domoticz_ ... ncremental
Hi there,

Thanks for your reply, I was looking at it ... I saw this :

Code: Select all

json.htm?type=command&param=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.
Fred
Using Domoticz on Raspberry 3B+ since 2018
Fan of automation, API and PhP.
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Water Meter, sensor type

Post 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?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
flhoest
Posts: 18
Joined: Tuesday 18 April 2023 19:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Belgium
Contact:

Re: Water Meter, sensor type

Post 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
Fred
Using Domoticz on Raspberry 3B+ since 2018
Fan of automation, API and PhP.
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Water Meter, sensor type

Post 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&param=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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
flhoest
Posts: 18
Joined: Tuesday 18 April 2023 19:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Belgium
Contact:

Re: Water Meter, sensor type

Post by flhoest »

Oh really ? this is awesome ;)
I will continue testing ...

Thanks a lot for sharing your knowledge !
Fred
Using Domoticz on Raspberry 3B+ since 2018
Fan of automation, API and PhP.
User avatar
FireWizard
Posts: 1745
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Water Meter, sensor type

Post 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
User avatar
flhoest
Posts: 18
Joined: Tuesday 18 April 2023 19:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Belgium
Contact:

Re: Water Meter, sensor type

Post 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.
Fred
Using Domoticz on Raspberry 3B+ since 2018
Fan of automation, API and PhP.
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Water Meter, sensor type

Post 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 ;)
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Kedi
Posts: 536
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: Water Meter, sensor type

Post 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
20.04.2023_18.26.11_REC.png (12.08 KiB) Viewed 1830 times
This works fine with a nice history.
Logic will get you from A to B. Imagination will take you everywhere.
User avatar
flhoest
Posts: 18
Joined: Tuesday 18 April 2023 19:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Belgium
Contact:

Re: Water Meter, sensor type

Post by flhoest »

Would you mind showing me the history graph?
Fred
Using Domoticz on Raspberry 3B+ since 2018
Fan of automation, API and PhP.
User avatar
flhoest
Posts: 18
Joined: Tuesday 18 April 2023 19:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Belgium
Contact:

Re: Water Meter, sensor type

Post 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&param=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 ;)
Fred
Using Domoticz on Raspberry 3B+ since 2018
Fan of automation, API and PhP.
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Water Meter, sensor type

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
flhoest
Posts: 18
Joined: Tuesday 18 April 2023 19:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Belgium
Contact:

Re: Water Meter, sensor type

Post by flhoest »

Thanks ;)
Fred
Using Domoticz on Raspberry 3B+ since 2018
Fan of automation, API and PhP.
Kedi
Posts: 536
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: Water Meter, sensor type

Post 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
21.04.2023_13.12.12_REC.png (175.38 KiB) Viewed 1781 times
Logic will get you from A to B. Imagination will take you everywhere.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest