Page 4 of 19
Re: MQTT Support
Posted: Thursday 13 February 2014 11:05
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?
Re: MQTT Support
Posted: Sunday 02 March 2014 23:36
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
Re: MQTT Support
Posted: Monday 03 March 2014 0:11
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
Re: MQTT Support
Posted: Monday 03 March 2014 18:59
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
Re: MQTT Support
Posted: Monday 03 March 2014 22:14
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)
Re: MQTT Support
Posted: Monday 03 March 2014 22:47
by maxtrash
Hi Alexvalois
did you try npm install mqtt
or
npm install -g mqtt url request
?
Re: MQTT Support
Posted: Monday 03 March 2014 23:38
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
Re: MQTT Support
Posted: Tuesday 04 March 2014 0:05
by maxtrash
Good to hear.
I think I also installed without -g before. Not sure why -g was supposed to be used.
Re: [90] MQTT Support
Posted: Saturday 15 March 2014 3:49
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
Re: [90] MQTT Support
Posted: Saturday 15 March 2014 8:46
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.
Re: [90] MQTT Support
Posted: Saturday 15 March 2014 10:39
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
Re: [90] MQTT Support
Posted: Tuesday 08 April 2014 16:04
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
or
and then reports success or failure over MQTT.
Further - the the person above who was talking about issues getting
to work correctly, you have to have it in quotes -
will work correctly.
Re: [90] MQTT Support
Posted: Sunday 27 April 2014 21:38
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.
Re: [90] MQTT Support
Posted: Monday 28 April 2014 1:47
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.
Re: [90] MQTT Support
Posted: Thursday 15 May 2014 21:28
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
Re: [90] MQTT Support
Posted: Thursday 15 May 2014 22:20
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?
Re: [90] MQTT Support
Posted: Thursday 15 May 2014 22:45
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
Re: [90] MQTT Support
Posted: Thursday 15 May 2014 22:50
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
Re: [90] MQTT Support
Posted: Thursday 15 May 2014 23:42
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.
Re: [90] MQTT Support
Posted: Friday 16 May 2014 8:17
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