[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.
deennoo
Posts: 897
Joined: Wednesday 10 December 2014 14:06
Target OS: Linux
Domoticz version: beta
Location: Bordeaux France
Contact:

Re: [90] MQTT Support

Post by deennoo » Monday 15 February 2016 22:42

@nayr, thanx your job.

I test some devices this morning with Android app you références on previous post to read mqtt flow, and it works on last beta.

It's look like you have a great expérience on MQTT.

Is this possible you update the wiki with an exemple showing how to get a dummy switch toggle true MQTT and send it to a device with node red ?

I want to use MQTT but wiki MQTT & wiki flows are very technic and not really accessible.
Domoticz stable 3.5877 for real & Domoticz beta for test
Rfxtrxe / RFLink / Milight / Yeelight / ESP8266 / MQTT / BLE
http://domo-attitude.fr

User avatar
nayr
Posts: 430
Joined: Tuesday 11 November 2014 19:42
Target OS: Linux
Domoticz version: github
Location: Denver, CO - USA
Contact:

Re: [90] MQTT Support

Post by nayr » Monday 15 February 2016 22:58

I have not played with Node-Red at all, well I take that back.. I followed the wiki my with my first foray into MQTT, and did not like the Node-Red component. Since then all my work with MQTT has been direct against the domoticz/in and domoticz/out.

I get the impression Node-Red is only needed to take existing MQTT clients and make them talk w/Domoticz without modification.. well all my MQTT clients are designed specifically for domoticz so they communicate natively without any Node-Red translation.

If your working on a new integration, ignore all the Node-Red crap and just use MQTT as a bi-directional JSON API.. it works much like the URL API except you send/receive the JSON via the MQTT Broker.

this is all you have to send in to set a Dimmer switch with IDX of 1 to level 50:

Code: Select all

{"command":"switchlight","idx":1,"switchcmd":"Set Level","level":50}
to set a binary switch with IDX of 1 to ON:

Code: Select all

{"command":"switchlight","idx":1,"switchcmd":"On"}
check out my node-domoticz-mqtt module, with it you can use Node JavaScript to spin out scripts/apps in much the same way as the internal Lua, Blocky and Python interpreters.
Debian Jessie: CuBox-i4 (Primary) w/Static Routed IP and x509 / BeagleBone with OpenSprinkler / BeagleBone Planted Aquarium / 3x Raspbery Pi2b GPIO Slaves
Elemental Theme - node-domoticz-mqtt - Home Theatre Controller - AndroidTV Simple OSD Remote - x509 TLS Auth

SchattenMann
Posts: 69
Joined: Friday 09 October 2015 19:14
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: [90] MQTT Support

Post by SchattenMann » Thursday 24 March 2016 13:13

Any chance we can get Kodi support?
I've just added Kodi to Domoticz but looks like we don't get any MQTT messages with status updates :-(
I'm happy to help in any way i can!

Lyubomyr
Posts: 31
Joined: Saturday 05 December 2015 1:24
Target OS: Windows
Domoticz version: 3.4834
Contact:

Re: [90] MQTT Support

Post by Lyubomyr » Tuesday 26 April 2016 22:55

I added a dummy humidity sensor and use this

Code: Select all

[{"id":"2543a541.b26dba","type":"mqtt-broker","broker":"127.0.0.1","port":"1883","clientid":""},{"id":"3086682d.a477a8","type":"inject","z":"7d53d511.239b3c","name":"Update Data","topic":"","payload":"{\"idx\": 161, \"nvalue\": 1, \"svalue\": \"456\" }","payloadType":"str","repeat":"1","crontab":"","once":false,"x":225,"y":363,"wires":[["e61556e0.5bd898"]]},{"id":"e61556e0.5bd898","type":"mqtt out","z":"7d53d511.239b3c","name":"Domoticz In","topic":"domoticz/in","qos":"","retain":"","broker":"2543a541.b26dba","x":435,"y":443,"wires":[]}]
But the value of the sensor is updated from the nvalue not from the svalue.

Why??

In this case value of dummy humidity is always equal 1%

Lyubomyr
Posts: 31
Joined: Saturday 05 December 2015 1:24
Target OS: Windows
Domoticz version: 3.4834
Contact:

Re: [90] MQTT Support

Post by Lyubomyr » Wednesday 27 April 2016 0:40

And another question:
Below my function for update temperature+humidity
(it is the same when I uncomment the commented line)

But when I look in the setup->Devices I see this
Hum2.png
Hum2.png (2.34 KiB) Viewed 2361 times
but not as in the non-MQTT version
Hum1.png
Hum1.png (3.55 KiB) Viewed 2361 times

Code: Select all

if (msg.nodeId == 25 & msg.payload !="\n" & msg.messageType == 1)
{
    var msg_new = {};
    msg_new.payload = {};
    
    msg_new.payload.idx = 162,
    msg_new.payload.nvalue = 0,    
        
    msg_new.payload.svalue = ""+context.global.temp+";"+context.global.hum+"";        
        
    //msg_new.payload = {"idx": 162, "nvalue": 1, "svalue": "4;1" }
return msg_new;
}
Last edited by Lyubomyr on Wednesday 27 April 2016 2:17, edited 1 time in total.

Lyubomyr
Posts: 31
Joined: Saturday 05 December 2015 1:24
Target OS: Windows
Domoticz version: 3.4834
Contact:

Re: [90] MQTT Support

Post by Lyubomyr » Wednesday 27 April 2016 2:16

And another question^

what is the difference between nvalue and svalue? Some sensors and actuators use nvalue others use svalue!

woody4165
Posts: 424
Joined: Monday 14 March 2016 14:55
Target OS: Linux
Domoticz version: beta
Location: Rome, Italy
Contact:

Re: [90] MQTT Support

Post by woody4165 » Monday 30 May 2016 19:17

Hi

I'm trying MQTT support, but I don't understand how to configure it.

I'm on latest beta, and as far as I understood from the Wiki, no additional SW have to be installed.

What about the configuration of a new MQTT Hw?

Image

What I have to put into Remote Address and Port? And where I can choose username and password in my configuration?

mosquitto is running since if I do

Code: Select all

ps -ef | grep mosq && netstat -tln | grep 1883
I get results

And what about CA Filename?
I haven't found these info on the Wiki, so I'm here to ask some help.

Thanks

woody4165
Posts: 424
Joined: Monday 14 March 2016 14:55
Target OS: Linux
Domoticz version: beta
Location: Rome, Italy
Contact:

Re: [90] MQTT Support

Post by woody4165 » Monday 30 May 2016 20:43

Got it working!
Just needed to make some config, I found these explanations easy and useful https://www.digitalocean.com/community/ ... -owntracks
and then put the info in the Domoticz panel.
CA is not needed, but maybe is useful for security.
I tried with a MQTT Chrome App to send something after subscribing to domoticz/in and domoticz/out and it seems to work.
I will explore more,sorry to post info request before searching more and more

Kouseri
Posts: 76
Joined: Sunday 04 January 2015 22:24
Target OS: Raspberry Pi
Domoticz version:
Location: Finland
Contact:

Re: [90] MQTT Support

Post by Kouseri » Monday 30 May 2016 20:45

woody4165 wrote: What I have to put into Remote Address and Port? And where I can choose username and password in my configuration?
If MQTT server is running in a same computer with the Domoticz then you should use following:
Remote address = 127.0.0.1
Port = 1883

Of course you need to create a virtual sensors (create a Dummy device first in Hardware page) that are used receive incoming MQTT data.

woody4165
Posts: 424
Joined: Monday 14 March 2016 14:55
Target OS: Linux
Domoticz version: beta
Location: Rome, Italy
Contact:

Re: [90] MQTT Support

Post by woody4165 » Tuesday 31 May 2016 7:57

What do you mean by virtual sensor that receive incoming Mqtt data?
Should I send instead mqtt message that contains what I can do with htto/json?

Kouseri
Posts: 76
Joined: Sunday 04 January 2015 22:24
Target OS: Raspberry Pi
Domoticz version:
Location: Finland
Contact:

Re: [90] MQTT Support

Post by Kouseri » Tuesday 31 May 2016 9:28

woody4165 wrote:What do you mean by virtual sensor that receive incoming Mqtt data?
Should I send instead mqtt message that contains what I can do with htto/json?
I meant that you should create a virtual sensor(s) first and use the IDX(s) of the created sensor(s) in MQTT messages.

woody4165
Posts: 424
Joined: Monday 14 March 2016 14:55
Target OS: Linux
Domoticz version: beta
Location: Rome, Italy
Contact:

Re: [90] MQTT Support

Post by woody4165 » Thursday 02 June 2016 10:56

Hi all

I'm having issue on let mosquito start at boot
If I run it by command line it's ok, but haven't found a way to let it start as service or during boot?
Can you help me also with some link or instructions?

Thanks

Madgeni
Posts: 400
Joined: Friday 25 March 2016 18:43
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: [90] MQTT Support

Post by Madgeni » Friday 29 July 2016 14:37

Hi all -
i'm interested in the concept of event-driven notifications, but i've a stupid Q (and the forum doesn't let me search on 3 letter-words!) - if i post an update from a 3rd party h/w to MQTT on say a switch state change (on/off), do I need to then write more code to identify and obtain the IDX for this?

I think the Wiki could do with some more info in it - i get the sense there's a lot if implied knowledge in it
Like my code? Want to buy me beer? https://paypal.me/madgeni
Like Controlicz? Want to help keep the lights on? https://paypal.me/madgeni :)

Native Alexa skill - register at http://www.controlicz.com

Kouseri
Posts: 76
Joined: Sunday 04 January 2015 22:24
Target OS: Raspberry Pi
Domoticz version:
Location: Finland
Contact:

Re: [90] MQTT Support

Post by Kouseri » Saturday 30 July 2016 14:05

Madgeni wrote:Hi all -
i'm interested in the concept of event-driven notifications, but i've a stupid Q (and the forum doesn't let me search on 3 letter-words!) - if i post an update from a 3rd party h/w to MQTT on say a switch state change (on/off), do I need to then write more code to identify and obtain the IDX for this?
I have done this by adding a virtual device to the Domoticz and using a IDX associated to the virtual device in my Arduino based devices. So you don't need to write more code in order to identify and obtain the IDX. You can find my implementations from the github.

Reley
Posts: 11
Joined: Wednesday 03 August 2016 8:25
Target OS: Raspberry Pi
Domoticz version: 3.4834
Location: Netherlands
Contact:

Re: [90] MQTT Support

Post by Reley » Wednesday 03 August 2016 8:49

Ok, call me a n00b but I am not getting MQTT to work to send data to Influxdb.
What I want to achieve:
Send gas meter (P1) data to influx so I can create cool graphics in Grafana.
The protocol from the gasmeter is not yet supported by Http-Link so I wanted to try something via MQTT.

I created the hardware device:
Image

And according to the log there is a connection:
2016-08-02 11:56:16.123 MQTT: Connecting to xxx.xxx.xxx.xxx:1883
2016-08-02 11:56:16.225 MQTT: connected to: xxx.xxx.xxx.xxx:1883
2016-08-02 11:56:16.325 MQTT: Subscribed

In Node-Red I imported the following:

Code: Select all

[{"id":"7b366043.74005","type":"mqtt-broker","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"verifyservercert":true,"compatmode":true,"keepalive":15,"cleansession":true,"willQos":"0","birthQos":"0"},{"id":"1be38963.6067a7","type":"mqtt in","z":"ecee940b.146508","name":"Domotic Out","topic":"domoticz/out","broker":"7b366043.74005","x":120,"y":158,"wires":[["962a6069.2b9c5"]]},{"id":"962a6069.2b9c5","type":"function","z":"ecee940b.146508","name":"ToInfluxDB","func":"var date = new Date(msg.payload);\ndata=JSON.parse(msg.payload);\n\nmsg.payload = {}; //null msg obj and create new properties\n\nvar influx_obj = \"[{\";\n\n\ninflux_obj += '\"name\": \"' + data.dtype.split(\" + \").join(\"\") + '\",';\nvar columns='\"columns\": [';\n\ncolumns+='\"idx\", \"nvalue\"';\n\nvar points='\"points\": [[';\n\npoints+= data.idx + ', ' + data.nvalue;\n\nfor (ii=0; ii<10; ii++)\n{\n    var vidx = (ii+1).toString();\n    var vname = \"svalue\" + vidx;\n    if (typeof data[vname] != 'undefined') {\n        columns+=', \"' + vname + '\"';\n        var vdata=data[vname];\n        if (!isNaN(vdata)) {\n            points+=', ' + parseFloat(vdata);\n        }\n        else {\n            points+=', \"' + vdata + '\"';\n        }\n    }\n}\n\n\ncolumns+=']';\npoints+=']]';\n\ninflux_obj+=columns+\",\" + points;\n\ninflux_obj+=\"}]\";\n\nmsg.payload=influx_obj;\n\nreturn msg;","outputs":1,"noerr":0,"x":225,"y":224,"wires":[["df17cf36.7a29f","19155261.c3e15e"]]},{"id":"df17cf36.7a29f","type":"debug","z":"ecee940b.146508","name":"","active":false,"console":false,"complete":false,"x":528.0833129882812,"y":223.08331298828125,"wires":[]},{"id":"19155261.c3e15e","type":"http request","z":"ecee940b.146508","name":"TEST","method":"POST","ret":"txt","url":"http://xxx.xxx.xxx.xxx:8086/db/domoticz/series?u=root&p=root","x":333.08331298828125,"y":317.08331298828125,"wires":[["4bab87f8.cc2218"]]},{"id":"4bab87f8.cc2218","type":"debug","z":"ecee940b.146508","name":"","active":false,"console":false,"complete":false,"x":529,"y":317,"wires":[]}]
Node-Red can deploy this without issues and has connection to Domoticz
Image

But still, no info in Influx...
What am I doing wrong??

Twinsen
Posts: 21
Joined: Wednesday 20 July 2016 22:39
Target OS: -
Domoticz version:
Contact:

Re: [90] MQTT Support

Post by Twinsen » Sunday 14 August 2016 22:39

How can I publish some information on domoticz/out when a device (Temperature and Humidity) is updated?
I search on wiki but without success ...

Kouseri
Posts: 76
Joined: Sunday 04 January 2015 22:24
Target OS: Raspberry Pi
Domoticz version:
Location: Finland
Contact:

Re: [90] MQTT Support

Post by Kouseri » Monday 15 August 2016 12:24

Twinsen wrote:How can I publish some information on domoticz/out when a device (Temperature and Humidity) is updated?
I search on wiki but without success ...
I'm using a lua script to publish needed events from the Domoticz. The script can be found from here.

SweetPants
Posts: 1477
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V3.8423
Location: The Netherlands
Contact:

Re: [90] MQTT Support

Post by SweetPants » Monday 15 August 2016 19:43

Twinsen wrote:How can I publish some information on domoticz/out when a device (Temperature and Humidity) is updated?.
On my system domoticz/out is updated every time my temp+hum sensors are updated:
{
"Battery" : 100,
"RSSI" : 12,
"dtype" : "Temp + Humidity",
"id" : "13825",
"idx" : 93,
"name" : "Badkamer",
"nvalue" : 0,
"stype" : "WTGR800",
"svalue1" : "22.5",
"svalue2" : "58",
"svalue3" : "1",
"unit" : 0
}

Twinsen
Posts: 21
Joined: Wednesday 20 July 2016 22:39
Target OS: -
Domoticz version:
Contact:

Re: [90] MQTT Support

Post by Twinsen » Tuesday 16 August 2016 7:15

Thank you for the answer.
I recheck the configuration and everything is working now

y1ann1s
Posts: 11
Joined: Wednesday 28 January 2015 23:16
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: [90] MQTT Support

Post by y1ann1s » Friday 14 October 2016 11:55

Hello
Anyone knows if I can get the list of devices through mqtt?
I am trying to build a home skill for ALexa using IoT
the send commands is pretty easy

The only thing I am missing is to get a list of all devices in MQTT

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests