Sonoff-HomeAssistant (Alternative firmware for Sonoff Switches for use with mqtt/HA)

Make sure that you have Neutral connected correctly.

These sonoff touches suddenly make it very interesting to automate switches due to the low cost!

Personally however, I don’t like very much the look of the face plate. Can somebody comment wether it is easy to replace the face plate, e.g. with one of Livolo?
Such as this one:
https://www.aliexpress.com/item/Livolo- … 21458.html

Thanks Kman (and others involved) this is a great thread and project. I’m just getting started after delivery of my TH10/16’s and have a quick question or concept I’d like to run by you.

Is it possible to re-purpose either the Rx or Tx (GPIO 1 and 3) as a digital in from a wall switch? Are their pull-ups in place for the serial comms already? Then the pin headers I have already soldered in for the first flash would be all the physical interfaces I need, including the temperature and humidity sensors via the 2.5 mm jack where applicable.

The alternative is to solder in a set of jumpers and pull-up to get GPIO4 up and running over on the mostly empty through hole strip intended for the RF module.

I appreciate the simplicity of this firmware and will leave all logic out in HA.

Yes you can use ESPsonoff_TH-v1.01ptOTA firmware on the TH series and change 4 to 3 below. After that point you can flash via OTA if you need changes. GPIO4 is a pain but if you can solder SMD components no issue. The 2.5mm plug is a pain to wire as well. Header is easier.

#define BUTTON          0                                    // (Don't Change for Sonoff TH Series)
#define RELAY           12                                   // (Don't Change for Sonoff TH Series)
#define LED             13                                   // (Don't Change for Sonoff TH Series)
#define DHTPIN          14                                   // (Don't Change for Sonoff TH Series)
#define WALLSWITCH      4                                    // (Don't Change for Sonoff TH Series)

Guys,

If have a Sonoff can i use HA without to flash the firmware in order to use MQTT?
or i must to make a firmware in order to use MQTT?

Thanks!

You need to flash the firmware in order to use it with HA, there is no MQTT functionality in the base firmware.

1 Like

Does anyone know the “2017-Version” I found here: https://www.aliexpress.com/item/2017-New-Sonoff-Smart-Home-Wireless-Remote-Control-Wifi-Switch-Intelligent-Timer-Switch-Diy-Switch-220V/32796752033.html ?
Just a marketing gag by this aliexpress shop owner or something new?

Actually I spoke to Sonoff just last week and asked the same question. The device is the same. It’s a marketing ploy :smiley:

1 Like

After upgrade HA it seem the all my sonoff switch lost its connection and restart every night between 3-4am not sure why without any automation setting…

I got crazy with this GPIO14 crazily changing states when just plugged something on…

But got it working… using only the 10k resistor connected like you sayd.
No need for the 430k resistor…

Just another question!
Is this connection safe for the board? Won’t it toast in some days???

Thanks

It’s quite normal to have a pull up/down resistor. Sleep easy.

Thought it might be useful to place a link here as well for a recall on some Sonoff POW and TH16 units:
https://community.home-assistant.io/t/sonoff-recall-th16-pow-dec-2016-jan-2017/13799

I have just spoken to my contact at Sonoff. She has no idea about a recall and I have sent her the links. She is in sales though so she is investigating and will get back to me. So far everything is OK here, house is still a house.

We will know fairly soon if this is legit or slandering :smiley:

Heres the link direct from ITLead

https://www.itead.cc/blog/sonoff-th16-and-pow-recall-notice

ITEAD got back to me. It’s a very small % of units that are effected. Because they don’t have batch numbers, it’s almost impossible to track. It’s basically left up to the customer to contact them after the fault has occurred and they will replace the unit. Hopefully nothing major happens in that process.

1 Like

I finally decided to give this a try. However, I am stuck at uploading the firmware to the Sonoff.

I am using the basic version of Sonoff

I don’t have any FTDI around so I use my old Arduino UNO as an alternative.

This is how I connect it…

The Arduino editor I am using is version 1.6.5.

My settings in the editor is as follows…

When I press verify button, it was OK. But when upload it, it gives these errors…

warning: espcomm_sync failed
error: espcomm_open failed
error: espcomm_upload_mem failed

I did press and hold on to the black elongated button on the Sonoff before plug in the USB port and release it after few seconds.

Not sure will it help but just to add, the LED on the Sonoff did not blink or light up at all. If I plug in the USB port without press, hold and release the black button, the LED on the Sonoff will blink once every 2 seconds.

Please help. Thanks.

I have never used a Uno to program a Sonoff. I have only ever user an FTDI adaptor.

http://www.ebay.com.au/itm/FTDI-FT232RL-USB-to-TTL-Serial-Converter-Adapter-Module-5V-3-3V-For-Arduino-GH-/272279719836?hash=item3f6522cf9c:g:j3QAAOSw5ZBWPbNF

and

http://www.ebay.com.au/itm/40pcs-20cm-Jumper-Wire-Cable-For-Arduino-Breadboard-Prototyping-Female-to-Female-/252324355458?hash=item3abfb41d82:g:p08AAOSwiDFYRR2A

It seems you have the connection right. You just need the FTDI adapter. You need to connect the adaptor to the header on the LED controller like this. Make sure the adapter is set to 3.3V with the onboard jumper otherwise you will blow the controller if you try and program with 5V.

CABLE/FTDI ADAPTER         SONOFF

VCC                        VCC
TX                         RX
RX                         TX
GND                        GND

You need to set the parameters on the IDE like this and change the port to the correct COM port that the FTDI adapter is connected to COM4, COM5 etc.

Hope that helps

I had one of those but it doesn’t work with my Windows. Somehow, the whole FTDI became unusable after I plugged it into my windows. I believe it was due to fake chip used by the FTDI. The link that you provided is most probably using the fake chip as well due to the low price. I am wondering what Windows are you using? Is there any additional steps you took before you plug in your FTDI? I’m using up to date Windows 10.

Yes there was a big issue with fake chips. Actually the issue was with drivers and the way they were signed and made useless after detecting a fake chip. The link I provided was the same one I use on Windows 10. No additional steps.

By using an Arduino, serial data is going from Windowa 10 to the Arduino but unless you have a sketch that passes that data back out to the Sonoff through another serial port I’m not sure how it would work. Never tried it or even bothered to learn how. Get an FTDI and you will have no issues.

@masterkenobi
To get the arduino working as ftdi you have to bridge a couple of pins. iirc it’s reset and gnd. Don’t quote me on the actual pins, but get the right pins jumpered and you’ll be fine.