Page 1 of 2
MQTT integration
Posted: Thursday 18 February 2016 11:33
by Andrex
Hi guys,
I'm going crazy!
I'm starting in these days with Domoticz so I'm not a master, but I've looked all around and I can't find a way to have him to talk with MQTT.
I've created a "MQTT Client Gateway with LAN interface" and in the log I see that it connects.
I've created the dummy hardware and a virtual Switch. But how can I tell Domoticz to react to certain MQTT command that he receives?
How can I tell the switch to send a command in MQTT to switch on/off a device?
Thanks in advance!
Andrea
Re: MQTT integration
Posted: Thursday 18 February 2016 14:18
by daandamhuis
Hi Andrex!
Did you read the Wiki about MQTT?
http://domoticz.com/wiki/MQTT
Re: MQTT integration
Posted: Thursday 18 February 2016 17:18
by Andrex
Hi daandamhuis!
I've read that wiki and I've seen this:
Code: Select all
Communication from and to Domoticz works via JSON. Default MQTT topics of the Domoticz for incoming and outcoming messages are:
domoticz/in
domoticz/out
But where should I put that direction?
I've also seen the examples like this one for Domoticz to MQTT:
Code: Select all
{
"idx" : 5,
"name" : "Internal Temperature",
"id" : "00080A",
"unit" : 1
"dtype" : "Temp",
"stype" : "TFA 30.3133",
"nvalue" : 0,
"svalue1" : "41.2",
"Battery" : 100,
"RSSI" : 12,
}
and this one for MQTT to Domoticz:
Code: Select all
{
"idx" : 7,
"nvalue" : 0,
"svalue" : "90;2975.00"
}
But where do I put this code???
Thanks a lot!
Re: MQTT integration
Posted: Thursday 18 February 2016 20:30
by nayr
use a mqtt client library to connect to Mosquitto and subscribe to domoticz/out..
check out my node-domoticz-mqtt module, all the code is written you just have to make it do something.
Re: MQTT integration
Posted: Thursday 18 February 2016 21:14
by Andrex
But how do I subscribe to domoticz in/out?
Sorry for the silly question but...where do I see your module?
Re: MQTT integration
Posted: Thursday 18 February 2016 21:19
by nayr
thats part of the MQTT protocol, you have to write your own client to to implement the protocol.. most popular programing languages have MQTT Client libraries that have most of the protocol work done for you..
https://www.npmjs.com/package/node-domoticz-mqtt
this is for implementing MQTT with JavaScript, it was written against Domoticz's JSON API so you dont even have to make the json.. just call the functions you need.
Re: MQTT integration
Posted: Friday 19 February 2016 18:15
by Andrex
Nayr, thanks again for your patience answering me, but I really don't know where to use that code!
Re: MQTT integration
Posted: Friday 19 February 2016 20:08
by pepijn
What do you want to achieve using MQTT
Re: MQTT integration
Posted: Saturday 20 February 2016 7:37
by Andrex
Hi Pepijn,
I want to change the state of some switch when receiving certain messages and send some messages when the switches are pressed
MQTT integration
Posted: Saturday 20 February 2016 7:43
by pepijn
Domoticz only allows Domoticz/in and Domoticz/out topics with specific message formats as described above. So there are 2 options:
1) your device or application should publish (and subscribe) messages according the Domoticz standard
2) you use something in the middle that translates your messages to Domoticz and back. I use Node-RED for this matter, it's part of the Domoticz SD card
Re: MQTT integration
Posted: Saturday 20 February 2016 7:48
by Andrex
For that purpose I've installed nodered on the Raspberry Pi that manage the relays
Re: MQTT integration
Posted: Saturday 20 February 2016 7:50
by pepijn
And you build a flow to do this translation?
Re: MQTT integration
Posted: Saturday 20 February 2016 7:57
by Andrex
Well...I still have to do that (read the GPIO status and send it, and react on messages coming from Domoticz), but first I need to send those messages from Domoticz and be able to use the one that nodered will send, and this is an obscure part for me!
Re: MQTT integration
Posted: Saturday 20 February 2016 8:03
by pepijn
You also have to build a flow for this as well. There are some samples on the wiki but some basic knowledge on node-red is really needed. So yo might start reading on nodered.org
Re: MQTT integration
Posted: Saturday 20 February 2016 8:06
by Andrex
I'm doing that, but I need info on the Domoticz side to use that flow and to send something back
Re: MQTT integration
Posted: Saturday 20 February 2016 8:15
by pepijn
This is described in the wiki
https://www.domoticz.com/wiki/MQTT
To set a switch in Domoticz publish a message to MQTT to the domoticz/in topic with the following message payload:
Code: Select all
{"command": "switchlight", "idx": 2450, "switchcmd": "On", "level": 100 }
Domoticz will publish every device update to domoticz/out so you have to filter the messages you need and translate them to the destination message format,
Re: MQTT integration
Posted: Saturday 20 February 2016 8:29
by Andrex
But how do I tell Domoticz to listen on port 1883? And how do I tell Domoticz the IP where to send the send the updates?
Re: MQTT integration
Posted: Saturday 20 February 2016 9:05
by pepijn
Add the MQTT hardware on the device settings
Re: MQTT integration
Posted: Saturday 20 February 2016 10:17
by Andrex
You mean the "MQTT Client Gateway with LAN interface" on the Hardware section?
Because i don't see any setting in the device section
Re: MQTT integration
Posted: Saturday 20 February 2016 11:11
by Andrex
I got Domoticz to talk to Node-RED (i still have to "translate" the message passed to turn on/off GPIO)
and right now I got Node-RED to talk to Domoticz too!!!
Thanks!