Sonoff - WiFi Wireless Smart Switch For MQTT

Building and connecting hardware to OpenNethome
LeifG
Posts: 6
Joined: Wed Feb 18, 2015 6:39 pm

Sonoff - WiFi Wireless Smart Switch For MQTT

Post by LeifG »

Did any one have experience of this WiFi switch, Sonoff - WiFi Wireless Smart Switch For MQTT COAP Smart Home
https://www.itead.cc/smart-home/sonoff- ... witch.html
Only $4,85 USD
How hard is it to implement in opennethome?
I do not know anything about MQTT.

Slampher, Wireless control light holder is also very interesting.
stefangsbb
Site Admin
Posts: 313
Joined: Sun Nov 30, 2014 2:16 pm

Re: Sonoff - WiFi Wireless Smart Switch For MQTT

Post by stefangsbb »

Wow, $4,85 USD is really cheap! MQTT would probably not be super hard to implement, unfortunately I won't have time to do that in the near future...
SourceCodeSourcerer
Posts: 10
Joined: Mon Mar 02, 2015 9:58 pm

Re: Sonoff - WiFi Wireless Smart Switch For MQTT

Post by SourceCodeSourcerer »

Stefan,

please have a look at http://tech.scargill.net/itead-slampher-and-sonoff/ which describes the Sonoff a bit on the technical side.

Here's a link to a couple of links, especially Moquette - could be interesting to have a MQTT home item at some point: https://github.com/mqtt/mqtt.github.io/wiki/servers

Cheers!

/Peter
jas
Posts: 8
Joined: Wed Apr 15, 2015 7:35 am

Re: Sonoff - WiFi Wireless Smart Switch For MQTT

Post by jas »

I have been using Sonoff switches with nethome for three months and they work just fine. I have found them to be a lot more reliable than Nexa switches.

You need to have your own software for the Sonoff though, the original code from Itead uses their cloud services.

I have integrated Paho Java MQTT client to nethome, so that part has already been done. I have not tested it extensively, but with the devices I have, it works without any problems.

If there is interest, I'm happy to contribute that code to nethome project.
LeifG
Posts: 6
Joined: Wed Feb 18, 2015 6:39 pm

Re: Sonoff - WiFi Wireless Smart Switch For MQTT

Post by LeifG »

jas,

I would appreciate it if you wanted to share files and information about how to install and use it together with nethome. Pending implementation of nethome project.

/Leif
jas
Posts: 8
Joined: Wed Apr 15, 2015 7:35 am

Re: Sonoff - WiFi Wireless Smart Switch For MQTT

Post by jas »

To use Sonoff switches with nethome, you need:
- MQTT broker
- Sonoff switch programmed with custom software to communicate with MQTT broker

MQTT broker is a server program which delivers messages between clients (in our case nethome and Sonoff switch are both clients)
Clients can publish and subscribe to messages. For example I have a Sonoff switch in garage which subscribes to
"garage/carheater" topic. When nethome wants to switch on car heater it publishes "on" message to that topic.
Sonoff receives it and turns on car heater socket. I have also a Raspberry Pi in garage which publishes
temperature every minute to "garage/temperature" topic. Nethome subscribes to this topic and receives the temperature and
displays it as "Garage Temp" thermometer.

I'm using Mosquitto MQTT broker running on Raspberry Pi. I have it installed on a separate Raspberry together with OpenVPN server,
but I cannot see any reason why it would not run on the same computer as nethome.
Here http://www.switchdoc.com/2016/02/tutori ... pberry-pi/ is a good tutorial
how to install Mosquitto on Raspberry. It has also more detailed explanation of MQTT in general.

To program Sonoff you need to solder a four pin header to the PCB and use a USB/serial adapter for serial connection.
There is a lot of information how to connect USB/serial adapter to Sonoff in Peter Scargill's blog. You can find the link in Peter's post.
I prefer to use CP2102 USB adapter instead of FTDI232 adapter, because the transmit output level in CP2102 is already 3,3V and you don't
need to use any resistors to lower the voltage.

I have not published the software I'm running in Sonoff, but I can do it if there is interest.
There are already some implementations of Sonoff MQTT in github, but I'm not really familiar with them, so cannot give any recommendations.

Anyway, the easiest way to start, would be to get an already compiled binary and program that to Sonoff an see what happens :-)
You can also set up a programming environment on your computer for ESP8266 tool chain, but that is a lot more complicated task.

Hopefully this gave at least some idea what is needed to use Sonoff with nethome.
Just ask if you have any questions.
mikkot
Posts: 33
Joined: Fri Aug 21, 2015 6:30 am

Re: Sonoff - WiFi Wireless Smart Switch For MQTT

Post by mikkot »

Hi All,

I'm using generic ESP8266 WIFI modules with Arduino IDE as MQTT enabled IoT gadgets (switches, sensors, etc etc). You can program the ESP8266 directly like you would do with an Arduino, but this little beast is more powerfull and has the WIFI inbuilt!

See http://www.esp8266.com/viewtopic.php?f=29&t=8746 for fully working code examples.

Be warned, this thing is really addictive and you might end up spending hours with it. :) On the other hand it opens a whole lot of possibilities for home automation with almost zero investment!

-Mikko-
perjarle
Posts: 32
Joined: Wed Aug 03, 2016 8:08 am

Re: Sonoff - WiFi Wireless Smart Switch For MQTT

Post by perjarle »

jas wrote: Mon Jun 06, 2016 7:34 am To use Sonoff switches with nethome, you need:
- MQTT broker
- Sonoff switch programmed with custom software to communicate with MQTT broker

MQTT broker is a server program which delivers messages between clients (in our case nethome and Sonoff switch are both clients)
Clients can publish and subscribe to messages. For example I have a Sonoff switch in garage which subscribes to
"garage/carheater" topic. When nethome wants to switch on car heater it publishes "on" message to that topic.
Sonoff receives it and turns on car heater socket. I have also a Raspberry Pi in garage which publishes
temperature every minute to "garage/temperature" topic. Nethome subscribes to this topic and receives the temperature and
displays it as "Garage Temp" thermometer.

I'm using Mosquitto MQTT broker running on Raspberry Pi. I have it installed on a separate Raspberry together with OpenVPN server,
but I cannot see any reason why it would not run on the same computer as nethome.
Here http://www.switchdoc.com/2016/02/tutori ... pberry-pi/ is a good tutorial
how to install Mosquitto on Raspberry. It has also more detailed explanation of MQTT in general.

To program Sonoff you need to solder a four pin header to the PCB and use a USB/serial adapter for serial connection.
There is a lot of information how to connect USB/serial adapter to Sonoff in Peter Scargill's blog. You can find the link in Peter's post.
I prefer to use CP2102 USB adapter instead of FTDI232 adapter, because the transmit output level in CP2102 is already 3,3V and you don't
need to use any resistors to lower the voltage.

I have not published the software I'm running in Sonoff, but I can do it if there is interest.
There are already some implementations of Sonoff MQTT in github, but I'm not really familiar with them, so cannot give any recommendations.

Anyway, the easiest way to start, would be to get an already compiled binary and program that to Sonoff an see what happens :-)
You can also set up a programming environment on your computer for ESP8266 tool chain, but that is a lot more complicated task.

Hopefully this gave at least some idea what is needed to use Sonoff with nethome.
Just ask if you have any questions.
How did you configure ONH to send mqtt messages?
I am able to receive messages in ONH, but have not yet figured out how to send

Sending and receiving XMPP messages works well.
mikkot
Posts: 33
Joined: Fri Aug 21, 2015 6:30 am

Re: Sonoff - WiFi Wireless Smart Switch For MQTT

Post by mikkot »

Hi,

I think we discussed this over the other topic earlier today; you can do this e.g. with the Custom lamp item. But it's really a "dummy lamp" item only - not capable of handling feedback/response/state/availability/LWT messages from e.g. Sonoff or other similar "smart switch".

This, until Stefan or some other guru proves me wrong :)

/Mikko
stefangsbb
Site Admin
Posts: 313
Joined: Sun Nov 30, 2014 2:16 pm

Re: Sonoff - WiFi Wireless Smart Switch For MQTT

Post by stefangsbb »

There is currently very little support for sending MQTT-Messages from Items in ONH. All the internal pluming is there, if you create an internal event with the correct attributes, the MQTTClient-Item will sent it, but currently only the MQTTValueLogger does that. The question is how the sending Item should look? Should it be an MQTTSwith, where you can configure topic and message for the on and off commands? Or just a more general MQTTMessage-Item with a "send"-action and where you configure topic and message? Any other ideas?
Post Reply