Jump to content



Recommended Posts

These little devices were discussed before and I recently came across one. Sure I had to make a NodeServer :) It's called "MQTT" in the NodeServer store. Installation is not very trivial:

First of all - you'll need to install Mosquitto MQTT Broker on your Raspbery Pi or other UNIX system.

sudo apt-get install mosquitto

If using the same Pi as your Polyglot - make sure to configure it to listen on different port, for example 1884
(Reson for not using Polyglot's MQTT broker - Polyglot requires TLS encryption and Client/Server certificate authentication)

There is the example Mosquitto configuration:

$ cat /etc/mosquitto/conf.d/mosquitto.conf
allow_anonymous false
password_file /etc/mosquitto/pwfile
port 1884

Create a MQTT user with password on Mosquitto.

sudo mosquitto_passwd -c /etc/mosquitto/pwfile mqttuser


Restart mosquitto

sudo systemctl restart mosquitto

After you done - just add the following configuration parameters to the MQTT nodeserver:

mqtt_server - defaults to 'localhost'
mqtt_port - defaults to 1883, I'm using 1884 in my example
mqtt_user - username you've setup
mqtt_password - mqtt user's password
devlist - there you'll need to put a json list of all your Sonoff devices and topics they listen to, for example: 

[ {"id": "sonoff1", "type": "switch", "status_topic": "stat/sonoff1/POWER", "cmd_topic": "cmnd/sonoff1/power"}, {"id": "sonoff2", "type": "switch", "status_topic": "stat/sonoff2/POWER", "cmd_topic": "cmnd/sonoff2/power"} ]

id is your ISY node ID - so alphanumeric characters only and underline, no special characters, maximum 14 symbols.

Note - your Sonoff MUST run the Sonoff-Tasmota firmware in order to work with MQTT!

Happy hacking! :) If there is interest - I'll make it support NodeMCU based sensors so in addition to $5 on/off device - we'll support ~$20 wifi multi-sensors :)

Link to comment
Share on other sites

Without digging too deep, I noticed some complaints with their v1.6 version breaking OTA flashing. Were you able to flash Tasmota without doing any physical modifications? Or are you working with pre 1.6 devices?

Sent from my HTC U11 using Tapatalk

Link to comment
Share on other sites

I did a little more digging.  There is a way to flash a custom firmware purely over WiFi (OTA) if the original firmware version is less than 1.6.  Versions >= 1.6 seem to have broken that ability and ITead is claiming they only support OTA updates for "their" firmware.

SonOTA is the github project for OTA flashing if you get any more devices with versions less than 1.6.  That would beat cracking it open/soldering/etc.


Link to comment
Share on other sites

Ah, got ya! I don't know what firmware version my Sonoffs came with... It only takes me about 10 minutes to solder a header and re-flash Tasmota firmware (half of that time is wicking out old solder from the header pads) so I did not even bother to mess with whatever they came with.

I think if you can have someone hold FTDI cable real tight - you can get away without soldering :) 

Like this guy: 


Another interesting one:



Link to comment
Share on other sites

Hah!  I guess just holding it there is KISS.

I'm mulling over options for automating the irrigation on a carnivorous plant garden that I have in my queue.  The Wireless Tags are working great in my inside terrarium, but I really hate having to depend on the cloud.  And at $20 - $25 a pop, I'm thinking a cheaper route using the ESP8266 might be the best way at this time.


Link to comment
Share on other sites

NodeMCU based or Sonoff TH ?

Wireless TAG is not entirely cloud - @Jimbo wrote it in a way that Tag Manager connects to the NodeServer directly for reports. Cloud is used for setup purposes and I don't think it's needed during normal operation.

ESP8266 is a great option, but will require some sort of enclosure and probably permanent power. In return - it gives you instant updates :) 

I'll go ahead and support "multisensor" type of something like on the video below



Link to comment
Share on other sites

I'm sort of gravitating to the Adafruit HUZZAH at the moment (NodeMCU, but will probably convert it to Arduino).  My goal is to attempt to power a bunch of sensors off a 12V gel cell bank that is solar charged each day.

From what I've read recently, the Wireless Tag, is "mostly" local.  The tag manager still wants to auth to the cloud which is annoying.

As far as enclosures are concerned, I'm pondering the purchase of a 3D printer.  For years, figuring out how to enclose a project has wasted too much of my time and I was never happy with the results.  Maybe 3D printing my own is the way to go.  Although, taking the time to design the enclosure probably won't speed things up, but at least I'll get exactly what I want.

And thank you very much for pointing out those videos.  They are quite imformative.


Link to comment
Share on other sites

Well, if you come up with some default firmware to connect to initially (act as Access Point on first power on) and configure it... :) It's actually faster to flash it via USB cable than mess with connecting to different WiFi :D

Link to comment
Share on other sites

  • 1 month later...

Trying to get the multisensor working but running into the following errors:

2018-09-23 12:07:15,722 INFO     UDI Polyglot v2 Interface 2.0.28 Starting...
2018-09-23 12:07:15,727 INFO     Connecting to MQTT... localhost:1883
2018-09-23 12:07:15,786 INFO     MQTT Connected with result code 0 (Success)
2018-09-23 12:07:15,788 INFO     MQTT Subscribing to topic: udi/polyglot/ns/6 -  MID: 1 Result: 0
2018-09-23 12:07:15,788 INFO     MQTT Subscribing to topic: udi/polyglot/connections/polyglot -  MID: 2 Result: 0
2018-09-23 12:07:15,789 INFO     Sent Connected message to Polyglot
2018-09-23 12:07:15,856 INFO     Started MQTT controller
2018-09-23 12:07:15,857 ERROR    mqtt_user must be configured

I have the configuration parameters set as described (at least I think I do)

Doesn't look like it is taking my port (also 1884) or mqtt_user configurations


Anything obvious stick out?

I only have one id/device, but included the open & close brackets in devlist.

Didn't include mqtt_server; assumed localhost was correct.

(password is set to same as defined during installation)


Link to comment
Share on other sites


I see now that the 1883 in the log is part of every nodeserver (at least the ones I have) startup and is probably correct.

The 'mqtt_user must be configured' ERROR still appears that it is not reading the config parameters.

Also realized that "id" is not supposed to be the MQTT primary/controller address  (as it should be unique to each MQTT device).

Changed it to generic "sensor1" and assume that is how it should populate as an ISY MQTT node. (maybe with nxxx_ prefix)

---Now I'm wondering if this should match something that is hardcoded in each device so that multiple devices can be differentiated correctly?

Based on code, it looks like the "type" should be 'sensor' and not 'multisensor'.

Here is how my devlist parameter looks now.

[ {"id": "sensor1", "type": "sensor", "status_topic": "bruh/sensornode1", "cmd_topic": "bruh/sensornode1/set"} ]

Link to comment
Share on other sites

  • 3 months later...

Hey guys,  I think I'm pretty close on getting this working but I can get the ISY to control the Sonoff.

I got Polyglot setup and working with the MQTT nodeserver and it all looks ok.  MQTT log snip:

2019-01-08 19:28:51,901 [NodeServer] [INFO ] Started MQTT controller
2019-01-08 19:28:51,916 [NodeServer] [INFO ] Adding switch Shelves
2019-01-08 19:28:51,924 [NodeServer] [INFO ] Adding node Shelves(shelves)
2019-01-08 19:28:51,939 [NodeServer] [INFO ] Done adding nodes, connecting to MQTT broker...
2019-01-08 19:28:51,963 [Thread-1  ] [INFO ] Poly MQTT Connected, subscribing...
2019-01-08 19:28:51,966 [Thread-1  ] [INFO ] Subscribed to stat/sonoff_s20_7699/POWER MID: 1, res: 0
2019-01-08 19:28:51,969 [Thread-1  ] [INFO ] Updating All Drivers to ISY for Shelves(shelves)
2019-01-08 19:32:08,732 [Controller] [INFO ] Updating All Drivers to ISY for MQTT Controller(mqctrl)

I think I have the MQTT config set ok, but not entirely sure on the "devlist" topic format, I have:

[ {"id": "Shelves", "type": "switch", "status_topic": "stat/sonoff_s20_7699/POWER", "cmd_topic": "cmnd/sonoff_s20_7699/POWER"} ]

I got these topic formats from Home Assistant were they work fine.  This new "Shelves" device shows up on the ISY, but it doesn't respond to on/off?

Any help appreciated!



Link to comment
Share on other sites

No, seem to get endless "Connect" messages?

mosquitto_sub -d -u mqttuser -P 'mypasswd' -t "cmnd/sonoff_s20_7699/POWER"
Client mosqsub/3178-raspberryp sending CONNECT
Client mosqsub/3178-raspberryp sending CONNECT
Client mosqsub/3178-raspberryp sending CONNECT

Nothing seems to change in the nodeserver log, or the Sonoff log?

(JFTR, You must first install the mosquitto clients with: "sudo apt-get install mosquitto-clients" to get the mosquitto_sub command)

Here's what the Sonoff log looks like when it gets a command from Home Assistant:

22:13:14 MQT: tele/sonoff_s20_7699/STATE = {"Time":"2019-01-08T22:13:14","Uptime":"0T01:35:15","Vcc":3.135,"POWER":"OFF","Wifi":{"AP":1,"SSId":"CHAOS-HOUSE","RSSI":94,"APMac":"88:41:FC:D0:86:23"}}
22:13:19 MQT: stat/sonoff_s20_7699/RESULT = {"POWER":"ON"}
22:13:19 MQT: stat/sonoff_s20_7699/POWER = ON
22:13:26 MQT: stat/sonoff_s20_7699/RESULT = {"POWER":"OFF"}
22:13:26 MQT: stat/sonoff_s20_7699/POWER = OFF


Link to comment
Share on other sites

The port (-p 1884) of course!  This looks encouraging, but I don't see anything on the NodeServer side?

pi@raspberrypi:~/polyglot $ mosquitto_sub -d -p 1884 -u mqttuser -P '1q2w!Q@W' -t "cmnd/sonoff_s20_7699/POWER"
Client mosqsub/3200-raspberryp sending CONNECT
Client mosqsub/3200-raspberryp received CONNACK
Client mosqsub/3200-raspberryp sending SUBSCRIBE (Mid: 1, Topic: cmnd/sonoff_s20_7699/POWER, QoS: 0)
Client mosqsub/3200-raspberryp received SUBACK
Subscribed (mid: 1): 0
Client mosqsub/3200-raspberryp sending PINGREQ
Client mosqsub/3200-raspberryp received PINGRESP

I would have expected this to power on the Sonoff, but it didn't:

pi@raspberrypi:~/polyglot $ mosquitto_pub -d -p 1884 -u mqttuser -P 'mypasswd' -t "cmnd/sonoff_s20_7699/POWER" -m "ON"
Client mosqpub/3206-raspberryp sending CONNECT
Client mosqpub/3206-raspberryp received CONNACK
Client mosqpub/3206-raspberryp sending PUBLISH (d0, q0, r0, m1, 'cmnd/sonoff_s20_7699/POWER', ... (2 bytes))
Client mosqpub/3206-raspberryp sending DISCONNECT

Thanks for your help, there is clearly something I don't get about this!

Link to comment
Share on other sites

So what happens when you go to ISY and hit On or Off button for that Sonoff? Do you see anything in the MQTT stream? Anything in the node server log?

Node Server is configured with port 1884, right?

Link to comment
Share on other sites

Nothing in the NodeServer log after an ISY toggle, and yes NodeServer is set to port 1884 for sure.

The NodeServer did respond to these commands (although the Sonoff didn''t!)

mosquitto_pub -d -p 1884 -u mqttuser -P 'mypasswd' -t "stat/sonoff_s20_7699/POWER" -m "ON"

mosquitto_pub -d -p 1884 -u mqttuser -P 'mypasswd' -t "stat/sonoff_s20_7699/POWER" -m "OFF"

2019-01-08 22:48:08,668 [Thread-1  ] [DEBUG] Received ON from stat/sonoff_s20_7699/POWER
2019-01-08 22:48:08,676 [Thread-1  ] [INFO ] Updating Driver shelves - ST: 100, uom: 78
2019-01-08 22:53:11,119 [Thread-1  ] [DEBUG] Received OFF from stat/sonoff_s20_7699/POWER
2019-01-08 22:53:11,151 [Thread-1  ] [INFO ] Updating Driver shelves - ST: 0, uom: 78


Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...