NodeJS Module: node-domoticz-mqtt

Client tools or tools that can connect with Domoticz. Tools for Windows, iOS, Android, Linux etc.
User avatar
nayr
Posts: 431
Joined: Tuesday 11 November 2014 19:42
Target OS: Linux
Domoticz version: github
Location: Denver, CO - USA
Contact:

NodeJS Module: node-domoticz-mqtt

Postby nayr » Monday 25 January 2016 1:27

I created a NodeJS Module for interfacing with Domoticz directly via MQTT.. It has some sanity checks to keep Domoticz happy and all the basic functions you need to start interfacing your own hardware with Domoticz quickly and easily.

Here is the npm project: https://www.npmjs.com/package/node-domoticz-mqtt
Here is the code: https://github.com/nayrnet/node-domoticz-mqtt

What is the MQTT Interface? Its identical to the JSON HTTP GET interface with these important differences:
  • Persistent Connection - Quick Response without setting up full blown HTTP connections for every update. Great if your changing lots of devices.
  • Bi-Directional - Get instant status updates without polling for changes, no need to call your app via HTTP/Script
  • MQTT Broker provides simple security for devices, with crypto support. great if your locking down the Web interface for security reasons.
  • Your NodeJS app will have nearly all the benefits of native hardware

Why NodeJS? Well tons of hardware is already supported by NodeJS, for example:

This solution does not require node-red or any of that, this lets you develop NodeJS applications interacting directly with Domoticz. All you need to do is install mosquito locally and add and configure the MQTT Hardware within Domoticz. Your now ready to start using this module.

Requires:
  • MQTT Broker (apt-get install mosquitto)
  • NodeJS and NPM (apt-get install nodejs npm)
  • Domoticz w/MQTT Hardware Interface
To install:

Code: Select all

npm install node-domoticz-mqtt

Support, Feedback, Contributions, etc should all be done in this thread or my github repo.. thanks and enjoy!

Ive got several NodeJS Applications that will be using this module, and more planned.. I should be able to finally add BeagleBone Black support to Domoticz soon!
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

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

Re: NodeJS Module: node-domoticz-mqtt

Postby nayr » Monday 25 January 2016 11:08

small version update released, 1.1.0

Changes:
  • Small Bugfixes for Switches, beware Virtual Switches do not support 100 steps.. only 0-15, but I am working getting this fixed upstream.
  • Callback for connect and error, now you can ensure you are connected before publishing data.
  • All the IDX provided in Options are now automatically requested upon connect, dont have to do it your self. You'll see a data callback with the info you need shortly after connecting.
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

jrich523
Posts: 84
Joined: Monday 18 January 2016 22:43
Target OS: Windows
Domoticz version: 3.5196
Location: Seattle, WA
Contact:

Re: NodeJS Module: node-domoticz-mqtt

Postby jrich523 » Sunday 15 May 2016 0:14

Looks great, but, i have to say im a little lost. If you helped walk me through it id be happy to write up the tutorial.
One of the things throwing me is what belongs where. I have Domoticz running on a seperate PC so for your setup you dont really indicate whats done on the server vs for the "device". As you know from the other forum im just trying to start with something super basic (temp, DHT or 1wire would be fine)
[ Domoticz 3.5196 | Win10 | AeoTec Z-Stick Gen5 ]

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

Re: NodeJS Module: node-domoticz-mqtt

Postby nayr » Sunday 15 May 2016 17:45

Domoticz has native support for DHT and 1Wire sensors.. dont use this library to integrate those.
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

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

Re: NodeJS Module: node-domoticz-mqtt

Postby gizmocuz » Monday 16 May 2016 10:34

Hi Nayr,

Just found this thread....

Domoticz has native mqtt support.... would it not be better to extend/enrich domoticz's implementation ?
Quality outlives Quantity!

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

Re: NodeJS Module: node-domoticz-mqtt

Postby nayr » Monday 16 May 2016 16:43

Hey Gizmocuz, of course.. this module is simply a bunch of pre-defined functions that are ran against Domoticz's MQTT Implementation (domoticz/in) with a bit of error checking to prevent you from crashing domoticz's MQTT module with invalid data (NaN)..

its just a library to load and talk to domoticz/in without all the MQTT/JSON formatting to worry about, simple functions make the calls for you.. basically allows NodeJS to be used like Lua/Python thanks to MQTT.. nothing is stoping you from talking to domoticz/in directly.
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

jrich523
Posts: 84
Joined: Monday 18 January 2016 22:43
Target OS: Windows
Domoticz version: 3.5196
Location: Seattle, WA
Contact:

Re: NodeJS Module: node-domoticz-mqtt

Postby jrich523 » Tuesday 17 May 2016 1:20

I guess I was mostly trying the temp because it was one of the most basic sensors, not so much that this was the end goal. Also I run my Dom on a laptop along with some other things, so id still need to run the temp on either a beagle/pi or something more basic like an arduino, using mysensors (which i havent had good luck with so far)

really the bottom line was an end to end example of how to get data from a beaglebone to dom
[ Domoticz 3.5196 | Win10 | AeoTec Z-Stick Gen5 ]

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

Re: NodeJS Module: node-domoticz-mqtt

Postby nayr » Tuesday 17 May 2016 1:28

for temp through this library you'd create a dummy sensor with idx of 101, then use: domoticz.device(101,0,"20") to set it to 20C

// Publish uDevice: nvalue = int, svalue = string
domoticz.device(idx,nvalue,svalue);

same as you'd find through the JSON API here: https://www.domoticz.com/wiki/Domoticz_ ... .2Fsensors
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

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

Re: NodeJS Module: node-domoticz-mqtt

Postby woody4165 » Monday 30 May 2016 13:03

Hi

I'm trying to undertand if MQTT is better than other solution with an ESP8266 with ESPEasy fw on it.
What I'm trying to reach is, a part setting On and Off GPIOs on ESP, having ESP to send "I'm alive" messages to Domoticz and with the help of Rules on ESPEasy return GPIOs status to Domoticz.

Hope this will work better than what I'm doing right now with HTTP.

What do you mean when you say that NodeRed is not anymore needed with node-domoticz-mqtt? Can I uninstall it from Domoticz?

How can I implement security (crypto and other) ?

Thanks

jrich523
Posts: 84
Joined: Monday 18 January 2016 22:43
Target OS: Windows
Domoticz version: 3.5196
Location: Seattle, WA
Contact:

Re: NodeJS Module: node-domoticz-mqtt

Postby jrich523 » Monday 30 May 2016 22:31

So I was able to setup the virtual device just fine (idx 52) and then used PowerShell to test sending data to it

Code: Select all

Invoke-WebRequest -Uri "http://192.168.11.98:8080/json.htm?type=command&param=udevice&idx=52&nvalue=0&svalue=21;33;1"


and it returned a status of OK and title of "Update Device" and I was able to see the data reflected in domoticz

I then went over to the beaglebone and created a simple script, I wont bother showing much of it, since its almost exactly youre example code, but i will show the output,

domoticz/in: {"command":"udevice","idx":52,"nvalue":0,"svalue":"21;33;1"}

Since this is from the On Data, i assume this is the info that dom received jsut fine. I also tossed in an On Error but nothing was spewed, however when I look in domoticz it never updates the sensor.
[ Domoticz 3.5196 | Win10 | AeoTec Z-Stick Gen5 ]

sj3fk3
Posts: 27
Joined: Sunday 22 March 2015 7:41
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: NodeJS Module: node-domoticz-mqtt

Postby sj3fk3 » Thursday 02 June 2016 14:46

Wouldn't it be nice to make it node-red node?
http://nodered.org/

rlust
Posts: 4
Joined: Saturday 24 December 2016 19:03
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: NodeJS Module: node-domoticz-mqtt

Postby rlust » Monday 09 January 2017 4:56

Trying to understand how to use this.
I am reading temperature and humidity on a ESP8266. The ESP code allows me to directly post a switch state, but cannot send temp & humidity data to domoticz . Does this allow me to use MQTT non json topics to domoticz?

rlust
Posts: 4
Joined: Saturday 24 December 2016 19:03
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: NodeJS Module: node-domoticz-mqtt

Postby rlust » Thursday 12 January 2017 5:23

I have used node-red to create a flow that posts the following to:
domoticz/in{"idx":59,"nvalue":0,"svalue":"70.0"}

I am getting this data from an ESP8266 and posting via MQTT
I get a reading in domoticz but the reading is being treated as Celsius.
I have tried 1 for the nvalue but still the same result.

Any ideas on how to fix the conversion?

seblang
Posts: 10
Joined: Sunday 27 December 2015 22:24
Target OS: Windows
Domoticz version:
Contact:

Re: NodeJS Module: node-domoticz-mqtt

Postby seblang » Wednesday 18 January 2017 21:24

Hi

I am still trying to use custom page with mqtt.
I am on windows and I have try mosquitto but mosquitto do not accept websocket!
I have try Hivemq!
Somebody use it? who can help me?


Return to “Third party and supplementary tools”

Who is online

Users browsing this forum: No registered users and 2 guests