Page 1 of 1

MQTT Node-red water-meter

Posted: Sunday 20 December 2015 22:36
by plutonium
Hi.

I have a water meter with a webcam connected to a raspberry. The software in raspberry sends out a mqtt payload that I want node-red to translate and update a meter in domoticz.
But I cannot figure out how to get their values in node-red so its suits to a json.htm command.

This is the output:

Code: Select all

plutonium@slackware:~$ mosquitto_sub -v -t /#
/lusa/misc-1/WATER_METER_FLOW/status {"type":"METER_VALUE","update_time":1450629599000,"value":0.00,"unit":"l/m"}
/lusa/misc-1/WATER_METER_10MIN/status {"type":"METER_VALUE","update_time":1450629899000,"value":0.00,"unit":"l/10m"}
/lusa/misc-1/WATER_METER_TOTAL/status {"type":"METER_VALUE","update_time":1450629539000,"value":36049.50,"unit":"l"}
/lusa/misc-1/WATER_METER_DRAIN/status {"type":"METER_VALUE","update_time":1450629539000,"value":168.00,"unit":"l"}
The result that I looking for (do not think of the numbers in the meter, I experiment):
meter.jpg
meter.jpg (30.59 KiB) Viewed 3608 times
And here is my node-red
node.jpg
node.jpg (129.7 KiB) Viewed 3608 times
As you can see there is a lot of text, I'm just intrested in the values and to put the three drain/last 10min/total in my meter.

I'm stuck and do not know how I should proceed.

Code: Select all

var pwJSON = JSON.parse(msg.payload);
msg.url = "http://127.0.0.1/json.htm?type=command&param=udevice&idx=53&nvalue="+pwJSON.value;
return msg;
Thanks for answer.

Re: MQTT Node-red water-meter

Posted: Monday 21 December 2015 9:10
by gizmocuz
You have to only send the counter value (WATER_METER_TOTAL)
it should be in the sValue (nValue can be set to 0)

Re: MQTT Node-red water-meter

Posted: Monday 21 December 2015 12:22
by plutonium
Thank you gizmocuz.

Now I changed to total, but my meter in domoticz don't register the value. Have I done this right?

Code: Select all

[{"id":"f544e7d7.ee31a","type":"function","name":"Water meter 2 Domoticz","func":"var pwJSON = JSON.parse(msg.payload);\nmsg.url = \"http://127.0.0.1/json.htm?type=command&param=udevice&idx=56&nvalue=0&svalue=\"+pwJSON.value;\nreturn msg;","outputs":1,"valid":true,"x":1523,"y":175,"z":"bf7f4014.6c3678","wires":[["aac10481.41635"]]}]
Debug;

Code: Select all

/domoticz/in/WATER_METER_TOTAL/status : [msg] : object{ "topic": "/domoticz/in/WATER_METER_TOTAL/status", "payload": "<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>", "qos": 0, "retain": true, "_topic": "/domoticz/in/WATER_METER_TOTAL/status", "_msgid": "e91b8e77.16e47", "url": "http://127.0.0.1/json.htm?type=command&param=udevice&idx=56&nvalue=0&svalue=37503", "statusCode": 401, "headers": { "content-length": "91", "content-type": "text/html" } }

Re: MQTT Node-red water-meter

Posted: Saturday 02 January 2016 12:06
by maxtrash
Hi

you can also use MQTT to interface with domoticz! This example should work or can be a good start:

Code: Select all

[{"id":"86f0c28c.790f4","type":"mqtt-broker","broker":"localhost","port":"1883","clientid":""},{"id":"6e84dcfc.917b24","type":"function","name":"Water meter 2 Domoticz","func":"var msg_out = {};\nmsg_out.payload = {};\nmsg_out.payload.idx = 260;\nmsg_out.payload.svalue = \"\" + msg.payload.value;\nreturn msg_out;","outputs":1,"valid":true,"x":484,"y":81,"z":"85da255.f7a25d8","wires":[["46c4783a.b93b88","a0100125.5ff"]]},{"id":"da20b6c7.25df48","type":"inject","name":"","topic":"","payload":"{\"type\":\"METER_VALUE\",\"update_time\":1450629539000,\"value\":36049.50,\"unit\":\"l\"}","payloadType":"string","repeat":"","crontab":"","once":false,"x":147,"y":74,"z":"85da255.f7a25d8","wires":[["2a14285b.d5ebd8"]]},{"id":"46c4783a.b93b88","type":"mqtt out","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"86f0c28c.790f4","x":714,"y":71,"z":"85da255.f7a25d8","wires":[]},{"id":"2a14285b.d5ebd8","type":"json","name":"","x":288,"y":79,"z":"85da255.f7a25d8","wires":[["6e84dcfc.917b24"]]},{"id":"a0100125.5ff","type":"debug","name":"","active":true,"console":"false","complete":"payload","x":703,"y":132,"z":"85da255.f7a25d8","wires":[]}]