[90] MQTT Support

Use this forum to discuss possible implementation of a new feature before opening a ticket.
A developer shall edit the topic title with "[xxx]" where xxx is the id of the accompanying tracker id.
Duplicate posts about the same id. +1 posts are not allowed.

Moderators: leecollings, remb0

User avatar
gizmocuz
Posts: 2485
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: [90] MQTT Support

Post by gizmocuz »

nope, because if i divide it by 1000 it seems like my meter counter... ;)
Quality outlives Quantity!
maxtrash
Posts: 106
Joined: Tuesday 06 August 2013 1:31
Target OS: -
Domoticz version:
Contact:

Re: [90] MQTT Support

Post by maxtrash »

yes, I think this was a bug in the node-red flow. I've put a new version in the wiki which divides by 1000
rtenklooster
Posts: 36
Joined: Tuesday 23 December 2014 16:20
Target OS: Linux
Domoticz version:
Contact:

Re: [90] MQTT Support

Post by rtenklooster »

I see mqtt implementation has developed since the last time i installed a the lua script using the old tutorial.
Used it so receive my sensors data, witch worked great.

I have a question about the new approach, is it true you need an idx before being able to publish messages / sensor values to domoticz?

The "old" implementation allowed to publish to domoticz/livingroom/temperature, the temperature was listed as new hardware, witch allowed me to add it. The id was: living room/temperature.
This method allowed to add new sensors without hardcoding any idx's in arduino sketches. I guess this is not possible anymore, or am i missing something?

It would be great to have some kind of option to auto generate a idx when a new device publishes to the broker. Am i missing something or is this just not possible, and do i net to create a new dummy device, add this idx to the sketch, and use that?
maxtrash
Posts: 106
Joined: Tuesday 06 August 2013 1:31
Target OS: -
Domoticz version:
Contact:

Re: [90] MQTT Support

Post by maxtrash »

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?
rtenklooster
Posts: 36
Joined: Tuesday 23 December 2014 16:20
Target OS: Linux
Domoticz version:
Contact:

Re: [90] MQTT Support

Post by rtenklooster »

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?
Thanks for your reply, I will setup a new test pi, to try and find out how the new node-red is working.
Maybe we can find a useful way of auto discovering, or just integrate the part of the old method in the new one, as that appears to be working.
Anyway thumbs up for the great work of all you developers!
maxtrash
Posts: 106
Joined: Tuesday 06 August 2013 1:31
Target OS: -
Domoticz version:
Contact:

Re: [90] MQTT Support

Post by maxtrash »

making a node-red version to create devices didn't turnout to be too complicated. I have some ideas to improve on this, stay tuned

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&param=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":[]}]
SweetPants

Re: [90] MQTT Support

Post by SweetPants »

gizmocuz wrote:new mqtt library implemented.... next i will do the username/password
(that will be another day :lol: )
2554 Username/Password works, thanks!!
jongerenchaos
Posts: 1
Joined: Thursday 26 September 2013 10:27
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [90] MQTT Support

Post by jongerenchaos »

Is there also a way to use the USER DEFINED variables? For now every IDX (from user variables) what i use is wrong.
chrille
Posts: 8
Joined: Monday 08 June 2015 15:18
Target OS: Linux
Domoticz version: Beta
Location: Horsens, Denmark
Contact:

Re: [90] MQTT Support

Post by chrille »

SweetPants wrote:2554 Username/Password works, thanks!!
Yes, that's much appreciated - now I am actually able to test without making changes to my broker setup!
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
Beaglebone Black, Raspberry Pi (A and B)
Multiple ESP8266 (DIY - temperature, humidity, light, door sensors)
USR-HTW (MQTT), HA7net, 2x Kankun wifi plug (MQTT)
WH1090 weatherstation + weewx (MQTT)
Hikvision IP cameras
KD101 fire alarms
RFXTRX433e + RFlink
mvdbro
Posts: 24
Joined: Saturday 31 January 2015 19:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [90] MQTT Support

Post by mvdbro »

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:

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}
but this one does not update the device

Code: Select all

MQTT: Topic: domoticz/in, Message: {"idx":237,"nvalue":0,"svalue":0,"svalue1":23.00,"svalue2":21.00}
idx 22 = switch device
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"
DHT.png
DHT.png (11.24 KiB) Viewed 4307 times
What could be wrong??
User avatar
gizmocuz
Posts: 2485
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: [90] MQTT Support

Post by gizmocuz »

chrille wrote:
SweetPants wrote:2554 Username/Password works, thanks!!
Yes, that's much appreciated - now I am actually able to test without making changes to my broker setup!
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
Well that makes sense
- nvalue = integer, not a string
- we expect json

But i will add some safety checks
Quality outlives Quantity!
User avatar
gizmocuz
Posts: 2485
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: [90] MQTT Support

Post by gizmocuz »

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:

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}
but this one does not update the device

Code: Select all

MQTT: Topic: domoticz/in, Message: {"idx":237,"nvalue":0,"svalue":0,"svalue1":23.00,"svalue2":21.00}
idx 22 = switch device
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??
- "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"
Quality outlives Quantity!
mvdbro
Posts: 24
Joined: Saturday 31 January 2015 19:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [90] MQTT Support

Post by mvdbro »

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"
Ok, I understand now and that seems to work.
But then there is a slight inconsistency between input/output messages as Domoticz sends out MQTT/JSON messages like this:

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
}
Using svalue1, svalue2, etc
User avatar
gizmocuz
Posts: 2485
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: [90] MQTT Support

Post by gizmocuz »

correct, this saves a string split later on....
Quality outlives Quantity!
mvdbro
Posts: 24
Joined: Saturday 31 January 2015 19:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [90] MQTT Support

Post by mvdbro »

gizmocuz wrote:correct, this saves a string split later on....
Anyway, it's working here so I'm happy with it.
Thanks for building the MQTT client gateway! Very promising add-on to Domoticz!
User avatar
gizmocuz
Posts: 2485
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: [90] MQTT Support

Post by gizmocuz »

#2560, added support for "commands" (Also updated the wiki)

Switch Light:
Optional: level (not when switchcmd = "Set Level")

Code: Select all

{"command": "switchlight", "idx": 2450, "switchcmd": "On", "level": 100 }
Switch Scene:

Code: Select all

{"command": "switchscene", "idx": 24, "switchcmd": "On" }
Set User Variable:

Code: Select all

{"command": "setuservariable", "idx": 1, "value": "12.3" }
Send Notification:
Optional: priority, sound

Code: Select all

{"command": "sendnotification", "subject": "My Subject", "body": "My Body", "priority": 0, "sound": "mysound" }
Quality outlives Quantity!
sweetpants01
Posts: 2
Joined: Saturday 16 May 2015 22:05
Target OS: -
Domoticz version:
Contact:

Re: [90] MQTT Support

Post by sweetpants01 »

Great, going to test this today
User avatar
gizmocuz
Posts: 2485
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: [90] MQTT Support

Post by gizmocuz »

sweetpants01 wrote:Great, going to test this today
you could use this node red flow:

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"]]}]
it contains all the possible commands
Quality outlives Quantity!
SweetPants

Re: [90] MQTT Support

Post by SweetPants »

gizmocuz wrote:Switch Light:
Optional: level (not when switchcmd = "Set Level")

Code: Select all

{"command": "switchlight", "idx": 2450, "switchcmd": "On", "level": 100 }
Works great.
gizmocuz wrote:Switch Scene:

Code: Select all

{"command": "switchscene", "idx": 24, "switchcmd": "On" }
What is the easiest way to get the 'idx' of a scene besides going into the database?
For switches/sensors you can look into 'setup->devices'
Maybe add an option to show the idx in the dashboard?
Selection_146.png
User avatar
gizmocuz
Posts: 2485
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: [90] MQTT Support

Post by gizmocuz »

Quality outlives Quantity!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest