[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

snauth
Posts: 1
Joined: Wednesday 05 February 2014 21:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MQTT Support

Post by snauth »

Hi all!
I have just switched from FHEM to domoticz (and so far I like very much what I see). MQTT support is an attractive feature for me as I use mqttitude and a little flukso electricity meter that speaks MQTT. I got the mqttitude example to run just fine (thanks!) but the result is not quite usable (e.g. to check against in if-blocks), is it? Do we need a new dtype (lat+long+distance) and where can I implement or request it?
Alexvalois
Posts: 3
Joined: Sunday 02 March 2014 23:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MQTT Support

Post by Alexvalois »

Hi,

thanks for the work already performed with MQTT and Domoticz! It seems really encouraging.
I am quite new to Domoticz as I was building everything by my own until now (partially with MQTT).

I did follow the instructions of http://www.domoticz.com/wiki/Setup_MQTT ... al_devices page.
The only difference is that I have already a MQTT server running on an other box and I would like to use it. Therefore, I have modified accordingly the domotics.js file (BrokerHost variable).

However, when I run "node mqtt/server.js", I get the following message:

pi@domoticzpi ~ $ node mqtt/server.js

module.js:340
throw err;
^
Error: Cannot find module 'mqtt'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/pi/mqtt/domoticz.js:9:12)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)

I have put .js scripts (server, domotics and devices in /home/pi/mqtt). Not sure it has any importance but I prefer to notify it just in case it makes any difference.

Thanks in advance for your help.

Alex
Raspberry Piet
Posts: 158
Joined: Saturday 11 January 2014 16:21
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: NL
Contact:

Re: MQTT Support

Post by Raspberry Piet »

I think i had the same sort of missing module issue.
Try

Code: Select all

npm config set ca ""
npm cache clean
npm update
ofi31
Posts: 1
Joined: Wednesday 19 February 2014 19:27
Target OS: -
Domoticz version:
Location: Blagnac
Contact:

Re: MQTT Support

Post by ofi31 »

Hi,
First, excuse my English.
I tested the solution "domotics / node.js / MQTT" and it works very well, congratulations to all.

Actually i am able to:
read temperature from 1-Wire sensor and put it in virtual sensor
and drive relay from virtual switch.

I found a MQTT library for lua. could it be used with domoticz?
https://github.com/geekscape/mqtt_lua
i suppose it must be re-compile with this library.

could it be a solution to interface domoticz with MQTT ? (without node.js)
What do you think about that?

i am not programer but if somebody think it could work, i will try it
thanks for response
olivier
Alexvalois
Posts: 3
Joined: Sunday 02 March 2014 23:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MQTT Support

Post by Alexvalois »

Hi Piet,

thanks for the advise. However, it didn't work and I still have the same message:
pi@domoticzpi:~$ node mqtt/server.js

module.js:340
throw err;
^
Error: Cannot find module 'mqtt'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/pi/mqtt/domoticz.js:9:12)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
maxtrash
Posts: 106
Joined: Tuesday 06 August 2013 1:31
Target OS: -
Domoticz version:
Contact:

Re: MQTT Support

Post by maxtrash »

Hi Alexvalois

did you try npm install mqtt
or
npm install -g mqtt url request
?
Alexvalois
Posts: 3
Joined: Sunday 02 March 2014 23:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MQTT Support

Post by Alexvalois »

Hi,

it seems that the installation has to be done with "npm install mqtt url request" without "-g" even if it is what is said in the wiki page. I don't have anymore the error message.

Thanks

Alex
maxtrash
Posts: 106
Joined: Tuesday 06 August 2013 1:31
Target OS: -
Domoticz version:
Contact:

Re: MQTT Support

Post by maxtrash »

Good to hear.

I think I also installed without -g before. Not sure why -g was supposed to be used.
evgeny_boger
Posts: 1
Joined: Saturday 15 March 2014 3:38
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [90] MQTT Support

Post by evgeny_boger »

Hi folks!

It's great to have MQTT supported by Domoticz!

However the current approach (node.js + lua + virtual devices/switches) looks a bit weird to me.
After all, both MQTT and Domoticz meant to be lightweight and so on and this node.js thing doesn't seem to fit it at all.


I checked out the Domoticz internals and it looks like it should be possible to implement another native hardware "driver"
which talks to MQTT using native C++ client, exports proper Domoticz devices and so on.

So, what do you think?
Haven't this kind of thing been done before?

Just in case I'm missing something :)
andriej
Posts: 46
Joined: Tuesday 10 December 2013 22:27
Target OS: Linux
Domoticz version: beta
Contact:

Re: [90] MQTT Support

Post by andriej »

Yeah, it does look weird and it works... weird.
I mean - the delay is even bigger than with JSON queries, that's why I didn't go further inside with implementantion.
Orange Pi (@ Debian) / MySensors Serial / GPIO / Custom Serial 433 MHz Transmitter (for plug switches and livolo wall switches) / JSON&Bash API scripts
maxtrash
Posts: 106
Joined: Tuesday 06 August 2013 1:31
Target OS: -
Domoticz version:
Contact:

Re: [90] MQTT Support

Post by maxtrash »

Hi

yes, it feels a bit clumsy. It's also an architectural discussion, how (if) Domoticz should support stuff like mqtt and/or node.js

In my opinion home automation is about connecting. In its essence there are devices sending and receiving messages. The message is received by some hardware (e.g. rfxcom, ip-based etc.) which in turn is connected to a computer. The computer should be running some software that allows you to setup rules (e.g. if temperature > 10 then switch on heating). Other main functionality is visualising the messages and storing them in a database (which allows you to also visualize (aggregated) messages from the past). Last but not least it should provide a GUI so you can manually trigger messages (e.g. swichting on a device).

Now the approach for Domoticz is like a star topology. For any different message type different code has been developed. The idea of an mqtt broker would be that next to the possibility of directly interfacing with domoticz, there would be also be an indirect way using the broker. However, just the broker doesn't cut it. Even if messages are sent through the MQTT interface there is still a need for mapping. Domoticz will only understand certain types of messages, depending on the devicetypes that it can visualize. So there you either need support in LUA (to parse the MQTT-messages and do something useful with them), or something like node.js (which could parse any message and interface with Domoticz using the JSON-interface).

anyway, I'm playing a little with node-red, just for the fun of it. We'll see what comes out of it. Would be interesting to hear what you think of all this
asjmcguire
Posts: 71
Joined: Saturday 13 July 2013 2:45
Target OS: Linux
Domoticz version: 3.5877
Location: Scotland
Contact:

Re: [90] MQTT Support

Post by asjmcguire »

I'm glad to see work is being done with MQTT -

I have been using MQTT for a while to create a bridge between Domoticz and Tellstick.
My machine running Tellstick is in a different building - but connected to the same network.
My Domoticz machine has mosquitto installed, and I am simply using the main script file to send this out over MQTT for every device change:

Code: Select all

mosquitto_pub -h 192.168.2.12 -t "nptohc/domoticz/${devname}/status/${device_id}" -m "{\"device_id\":${device_id},\"status\":\"${status}\",\"device_name\":\"${devname}\",\"hardware_id\":${hardware_id}}"
On my Tellstick machine, I have a Python script running subscribed to "/nptohc/domoticz/#" that parses the JSON from the MQTT message and checks what "hardware_id" is - 2 is my dummy hardware in Domoticz - which I use for virtual switches, and this is what the Python script is interested in.

In the event that hardware id is 2, it then runs

Code: Select all

tdtool --on devicename
or

Code: Select all

tdtool --off devicename
and then reports success or failure over MQTT.

Further - the the person above who was talking about issues getting

Code: Select all

mosquitto_sub -t # 
to work correctly, you have to have it in quotes -

Code: Select all

mosquitto_sub -t "#"
will work correctly.
AEOTEC ZStick, 11 ZWave Nodes, RFXCOMM, 50ish Byron Sockets.. HE851 (PIR), 2x HE852 (DoorContact)
WS2300, CM180, CC128, 2xTHGR122NX, 2xPiZeroW w/DS18B20, 8Ch 1W Relay Board.
8 Panasonic IP Cams, 1 16ch CCTV DVR + 15 CCTV Cams
GlenC
Posts: 1
Joined: Friday 18 April 2014 12:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [90] MQTT Support

Post by GlenC »

This thread seems to have gone very quiet of late.

I'm really interested in an mqtt implementation and have been reading the thread with interest.

Are there any updates?

Cheers

Glen.
maxtrash
Posts: 106
Joined: Tuesday 06 August 2013 1:31
Target OS: -
Domoticz version:
Contact:

Re: [90] MQTT Support

Post by maxtrash »

I played with node red a couple of weeks ago, which was very nice. Other than that it's kindof quiet and I'm doing other stuff (mainly work) at the moment. I guess I'll pick up the topic later this year, who knows. It also depends on the developments going on with Domoticz. If proper (virtual) devices for thermostats (multi-state whatever), geo-locating, etc. are added it would be more interesting to continue with node-red/mqtt.
andreas.aahlin
Posts: 4
Joined: Wednesday 07 May 2014 9:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [90] MQTT Support

Post by andreas.aahlin »

Hello.
First off, thanks for a superb support to get MQTT to work with domoticz.
I have used the lua, server.js and domoticz.js created by maxtrash. they all seams to work.
The trouble I'm having is when i try to run the test script:
mosquitto_pub -t /actions/domoticz/xyz -m '{"SensorType":"Temperature","svalue":"21.1"}'

I can see the that the server.js sends the JSON request but nothing happens in Domoticz.
From terminal window i got this

Received: /actions/domoticz/xyz {"SensorType":"Temperature","svalue":"21.1"}
JSON Payload
Sending request
http://127.0.0.1:8080/json.htm?type=com ... value=21.1
NULL

If i use the same JSON request (exepts the IP number) in a browser on my Windows machine the response is as expected.

http://192.168.160.210:8080/json.htm?ty ... value=21.1
The browser will display: { "status" : "OK", "title" : "Update Device" } and the device is updated in Domoticz.

Any suggestions or hints on how to solve this problem?

Best regards
Andreas Åhlin
maxtrash
Posts: 106
Joined: Tuesday 06 August 2013 1:31
Target OS: -
Domoticz version:
Contact:

Re: [90] MQTT Support

Post by maxtrash »

Thanks. Not sure I would call the support superb but anyway.
So you did change the ip variable in the script to 192.168.1.210?
andreas.aahlin
Posts: 4
Joined: Wednesday 07 May 2014 9:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [90] MQTT Support

Post by andreas.aahlin »

Hello. I would say its superbe when I got a response after less then an hour.
I didn't change the IP in the script, the scripts and domoticz are run on a raspberry pi.
I did change the IP when testing if the http request worked from my windows machine in a browser.
So when the script server.js makes the request nothing happens in domoticz.

Is there a way to test the http request direct in the ssh terminal, to we if it works from the pi?

Best regards
Andreas Åhlin
maxtrash
Posts: 106
Joined: Tuesday 06 August 2013 1:31
Target OS: -
Domoticz version:
Contact:

Re: [90] MQTT Support

Post by maxtrash »

I'm sure you can test http requests using curl.
You might also want to try changing the ip address in the script to 192.168.1.210. Although I don't see why 127.0.0.1 shouldn't work it's worth a try.
I'm no Linux expert though so just suggesting a couple of things here
brijoco
Posts: 3
Joined: Thursday 19 September 2013 10:23
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [90] MQTT Support

Post by brijoco »

Hi,

I am installing Mosquitto support but seeing the following error in the Domoticz log ...

Thu May 15 22:33:30 2014 Hardware Monitor: Fetching data (System sensors)
Thu May 15 22:33:30 2014 LUA: 127.0.0.1:5001/PI-DOMO%20-%20CPU%20Temp/Temperature?54.099998474121
Thu May 15 22:33:30 2014 LUA: LUA MQTT - Trigger: PI-DOMO - CPU Temp now
Thu May 15 22:33:30 2014 Fetching url...
Thu May 15 22:33:30 2014 Script event triggered: /home/pi/domoticz/scripts/lua/script_device_mqtt.lua
Thu May 15 22:33:30 2014 (System) Temperature (PI-DOMO - CPU Temp)
Thu May 15 22:33:31 2014 Error: Error opening url: 127.0.0.1:5001/PI-DOMO%20-%20CPU%20Temp/Temperature?54.099998474121

I have been back through the Wiki install instructions and the Foum 'MQTT Support' topic without success.

Any pointers or suggestions very much welcomed.
Regards
--------------------------------------------------------------------------------------
Multiple RPI mod B running ...
Domoticz (RFXtrx433, various RC sockets, lights, switches, PIR, sensors)
Intranet (Internal web site to TV, Mosquitto, XBMC, NAS
andreas.aahlin
Posts: 4
Joined: Wednesday 07 May 2014 9:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [90] MQTT Support

Post by andreas.aahlin »

Hello brijoco.
These errors are because there are no node.js script listening.
Start the server.js script and where will hopefully not be anny errors any more.

Best regards
Andreas Åhlin
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest