Re: [90] MQTT Support
Posted: Thursday 11 June 2015 19:04
nope, because if i divide it by 1000 it seems like my meter counter... 

Thanks for your reply, I will setup a new test pi, to try and find out how the new node-red is working.maxtrash wrote:the old solution, using http-calls still works, so you can keep using that. The new mqtt-in interface is additional and uses idx as you mentioned.
Using node-red flows could be expanded to in lots of ways. Some form of autodiscover seems nice, I'll think try and think about or maybe you can suggest something?
Code: Select all
[{"id":"86f0c28c.790f4","type":"mqtt-broker","broker":"localhost","port":"1883","clientid":""},{"id":"9d6956ab.6296a8","type":"mqtt in","name":"","topic":"domoticz/in/json","broker":"86f0c28c.790f4","x":91,"y":461,"z":"8b1c06b3.74e3f8","wires":[["6241c43d.9dbe3c"]]},{"id":"6241c43d.9dbe3c","type":"json","name":"","x":231,"y":480,"z":"8b1c06b3.74e3f8","wires":[["293cfde8.d6c302"]]},{"id":"293cfde8.d6c302","type":"function","name":"","func":"var Domoticz_IP = '192.168.1.24';\nvar Domoticz_Port = '8080';\nvar Domoticz_HID = '3';\n\nvar url = 'http://' + Domoticz_IP + \n\t\t ':' + Domoticz_Port +\n\t\t '/json.htm?type=command¶m=udevice';\n\nif (msg.topic) {\n url = url + '&did=' + msg.topic;\n}\n\nif (msg.payload.hid) {\n url = url + '&hid=' + msg.payload.hid;\n}\nelse \n{\n url = url + '&hid=' + Domoticz_HID;\n}\n\nif (msg.payload.dunit) {\n url = url + '&dunit=' + msg.payload.dunit;\n}\n\nif (msg.payload.dtype) {\n url = url + '&dtype=' + msg.payload.dtype;\n}\n\nif (msg.payload.dsubtype) {\n url = url + '&dsubtype=' + msg.payload.dsubtype;\n}\n\nif (msg.payload.nvalue) {\n url = url + '&nvalue=' + msg.payload.nvalue;\n}\n\nif (msg.payload.svalue) {\n url = url + '&svalue=' + msg.payload.svalue;\n}\n\nmsg.url = url;\n\nreturn msg;","outputs":1,"x":376,"y":497,"z":"8b1c06b3.74e3f8","wires":[["3ad012da.c52fee","4f3e184f.b0c1e8"]]},{"id":"3ad012da.c52fee","type":"debug","name":"","active":true,"console":"false","complete":"false","x":639,"y":500,"z":"8b1c06b3.74e3f8","wires":[]},{"id":"30b8eaa5.cf4716","type":"inject","name":"","topic":"257","payload":"{\"dunit\":1,\"dtype\":80,\"dsubtype\":9,\"svalue\":\"21.1\"}","payloadType":"string","repeat":"","crontab":"","once":true,"x":91,"y":510,"z":"8b1c06b3.74e3f8","wires":[["6241c43d.9dbe3c"]]},{"id":"4f3e184f.b0c1e8","type":"http request","name":"","method":"GET","ret":"txt","url":"","x":509,"y":544,"z":"8b1c06b3.74e3f8","wires":[["e0becc4.f1f413"]]},{"id":"e0becc4.f1f413","type":"debug","name":"","active":true,"console":"false","complete":"true","x":706,"y":555,"z":"8b1c06b3.74e3f8","wires":[]}]
2554 Username/Password works, thanks!!gizmocuz wrote:new mqtt library implemented.... next i will do the username/password
(that will be another day)
Yes, that's much appreciated - now I am actually able to test without making changes to my broker setup!SweetPants wrote:2554 Username/Password works, thanks!!
Code: Select all
MQTT: Topic: domoticz/in, Message: {"idx":22,"nvalue":0}
MQTT: Topic: domoticz/in, Message: {"idx":240,"nvalue":0,"svalue":22.75}
MQTT: Topic: domoticz/in, Message: {"idx":161,"nvalue":0,"svalue":350.00}
MQTT: Topic: domoticz/in, Message: {"idx":22,"nvalue":1}
Code: Select all
MQTT: Topic: domoticz/in, Message: {"idx":237,"nvalue":0,"svalue":0,"svalue1":23.00,"svalue2":21.00}
Well that makes sensechrille wrote:Yes, that's much appreciated - now I am actually able to test without making changes to my broker setup!SweetPants wrote:2554 Username/Password works, thanks!!
It seems the parsing of MQTT messages is very sensitive when it comes to the correct format - I just discovered that sending "nvalue" : "1" instead of "nvalue" : 1 will crash domoticz. Also sending something that's not json formatted, also causes a crash. Still, it's great progress
- "svalue" should be of type string, like "svalue": "stringvalue"mvdbro wrote:I have the Domoticz MQTT gateway running and i'm sending MQTT JSON messages from an ESP8266 module. These messages are processed without any issues:but this one does not update the deviceCode: Select all
MQTT: Topic: domoticz/in, Message: {"idx":22,"nvalue":0} MQTT: Topic: domoticz/in, Message: {"idx":240,"nvalue":0,"svalue":22.75} MQTT: Topic: domoticz/in, Message: {"idx":161,"nvalue":0,"svalue":350.00} MQTT: Topic: domoticz/in, Message: {"idx":22,"nvalue":1}
idx 22 = switch deviceCode: Select all
MQTT: Topic: domoticz/in, Message: {"idx":237,"nvalue":0,"svalue":0,"svalue1":23.00,"svalue2":21.00}
idx 240 = temperature device
idx 161 = lux device
idx 237 = temperature + humidity device
when the message is send for idx 237, even the 'zero' values disappear from the "panel"
What could be wrong??
Ok, I understand now and that seems to work.gizmocuz wrote:- "svalue" should be of type string, like "svalue": "stringvalue"
- the svalue (and nvalue) should be in the same format as described on the wiki page (JSON api), for example "svalue": "21.3;65;2"
Code: Select all
{
"Battery" : 100,
"RSSI" : 12,
"dtype" : "Temp + Humidity",
"id" : "0",
"idx" : 237,
"name" : "DHT",
"nvalue" : 0,
"stype" : "WTGR800",
"svalue1" : "23.5",
"svalue2" : "34",
"svalue3" : "2",
"unit" : 0
}
Anyway, it's working here so I'm happy with it.gizmocuz wrote:correct, this saves a string split later on....
Code: Select all
{"command": "switchlight", "idx": 2450, "switchcmd": "On", "level": 100 }
Code: Select all
{"command": "switchscene", "idx": 24, "switchcmd": "On" }
Code: Select all
{"command": "setuservariable", "idx": 1, "value": "12.3" }
Code: Select all
{"command": "sendnotification", "subject": "My Subject", "body": "My Body", "priority": 0, "sound": "mysound" }
you could use this node red flow:sweetpants01 wrote:Great, going to test this today
Code: Select all
[{"id":"b8bfeb9b.474018","type":"mqtt-broker","broker":"127.0.0.1","port":"1883","clientid":""},{"id":"88e1cf6d.771e3","type":"inject","name":"Update Data","topic":"","payload":"{\"idx\": 123, \"nvalue\": 1, \"svalue\": \"123;456\" }","payloadType":"string","repeat":"","crontab":"","once":false,"x":156,"y":340,"z":"821a73e2.7de59","wires":[["9eb6c867.614938"]]},{"id":"9eb6c867.614938","type":"mqtt out","name":"Domoticz In","topic":"domoticz/in","qos":"0","retain":"false","broker":"b8bfeb9b.474018","x":366,"y":420,"z":"821a73e2.7de59","wires":[]},{"id":"6eec86f3.911378","type":"inject","name":"Switch Light","topic":"","payload":"{\"command\": \"switchlight\", \"idx\": 2450, \"switchcmd\": \"On\", \"level\": 100 }","payloadType":"string","repeat":"","crontab":"","once":false,"x":163,"y":380,"z":"821a73e2.7de59","wires":[["9eb6c867.614938"]]},{"id":"6f518b3d.90ae74","type":"inject","name":"Switch Scene","topic":"","payload":"{\"command\": \"switchscene\", \"idx\": 24, \"switchcmd\": \"On\" }","payloadType":"string","repeat":"","crontab":"","once":false,"x":160.5,"y":423,"z":"821a73e2.7de59","wires":[["9eb6c867.614938"]]},{"id":"1952b825.e6ad48","type":"inject","name":"Set User Variable","topic":"","payload":"{\"command\": \"setuservariable\", \"idx\": 1, \"value\": \"12.3\" }","payloadType":"string","repeat":"","crontab":"","once":false,"x":150,"y":468,"z":"821a73e2.7de59","wires":[["9eb6c867.614938"]]},{"id":"6bdca5b8.94235c","type":"inject","name":"Send Notification","topic":"","payload":"{\"command\": \"sendnotification\", \"subject\": \"My Subject\", \"body\": \"My Body\", \"priority\": 0, \"sound\": \"mysound\" }","payloadType":"string","repeat":"","crontab":"","once":false,"x":154,"y":511,"z":"821a73e2.7de59","wires":[["9eb6c867.614938"]]}]
Works great.gizmocuz wrote:Switch Light:
Optional: level (not when switchcmd = "Set Level")Code: Select all
{"command": "switchlight", "idx": 2450, "switchcmd": "On", "level": 100 }
What is the easiest way to get the 'idx' of a scene besides going into the database?gizmocuz wrote:Switch Scene:Code: Select all
{"command": "switchscene", "idx": 24, "switchcmd": "On" }