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

Got two Sonoff switches and have tried to flash them for a few hours today… For some reason Arduino IDE is just saying

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

which is the same error message which happens when the FTDI cable is not connected to any device. When I start the switch while pressing the button, LED doesn’t light up so I’m guessing I’m succesfully in programming mode? I can also upload code to Adafruit Huzzah without problems so my gear should be ok. Few questions:

  • How do people know which pin is which in the Sonoff? I used this source that I found with Google. Hopefully it’s correct.
  • I should use 3.3V right? When I do so without going to programmig mode the LED doesn’t light up - with 5V it does. Is this normal? (I used the 5V before realising I shouldn’t have, oops… Doesn’t look like I broke anything though)
  • I have this FTDI cable connected to Sonoff with jumper wires. Should be ok…?
  • Which settings should I use when uploading (board, programmer, upload speed…) with the Arduino IDE?

Thanks for any help.

Hi. Anyone has trouble with sonoff/mqtt when WiFi signal is resumed after turn off? My sonoff switch off the relay when WiFi comes back and the relay was on before the WiFi turns off. I’ve shutdown ha service, but nothing changes, then shutdown the Raspberry and the issue disappear ( i think that terminate ha service doesn’t terminate mqtt service too ). I’ve modified the software so when WiFi connects, the sonoff should transmit relay status, and mqttclient.loop() is not executed if sendrelaystatus or senddht status variables are set true… But this not solved the problem.

Yes that source of pinout for the sonoff is correct. You may have damaged the ESP8266 if you have connected +5v to it. But in saying that I have had issues trying to flash them with some adapters due to them being unable to supply enough power at 3.3v. To solve this in the past I have modified them by using the +5v line with a step down buck module like these

http://m.ebay.com/itm/mini-2000mA-DC-5V-to-3-3V-DC-DC-Step-Down-Power-Supply-Buck-Module-AMS1117-LDO-/172372057816?_trkparms=aid%3D222007%26algo%3DSIC.MBE%26ao%3D1%26asc%3D20150519202348%26meid%3D9799b893776a4045ab3ceaf13c04eac7%26pid%3D100408%26rk%3D4%26rkt%3D14%26sd%3D261172232237&_trksid=p2056116.c100408.m2460

@KmanOz first of all Thank you for awesome work! I’d just linke to inform all guys here the firmware is very well working with the s20 smart socket. i have up and running 3 of the now for a week or two.

That’s great. Did you use the original Sonoff firmware? Did you need to modify any pins or did the default ones work fine?

All

Iv been working on the firmware in the last couple of days. It now writes the state of the relay to the EEPROM so if power fails it will come back to the state it was before. Good for Fridges as someone pointed out earlier or anything that needs to stay on after power has been restored. I’ll update Github shortly.

Cheers

1 Like

I have two Sonoff POW switches, flashed with your firmware. I’ve noticed they sometimes switch off, at random (no power failures), the status in HA shows on and I don’t see any “off” command in the logging. Is this related to this fix ?

Hi KmanOZ,

i used the firmware ESPsonoff-v1.0p from your Git-Repository. Had some troubles with flashing, but this was my fault :sweat_smile:

1 Like

Keep in mind that there’s a write cycle limit to eeprom. About 100000. Still a lot but expect write to fail when you’re reaching that limit

I’m very familiar with the fact. That’s why it will be a feature that they can turn on or off. Thanks.

1 Like

No. I haven’t seen that but will take notice. I have one here that runs all the time (on and off on schedule) but I haven’t seen that behavior. Is there anyone else this is happening to? Further up this thread I was asked to store the state of the relay, for fridges etc. I thought it was a good idea mainly because I use the one I have here on my Garage Fridge. Made sense to do it.

Also go to my Github and report it as a fault. Let’s see if anyone else reports along with you.

I thought so. It seems the original Sonoff Basic, the Sonoff LV (Low Voltage), Sonoff Touch and S20 Smart Socket is basically the same technical design repackaged as different devices. Good to know. Will update the the Github with the details. Thanks

Has anyone measured the power consumption of the switch? I get something like 1.3W when it is turned off and about 1W when on. 1.3W actually seems like a lot…

1 Like

I think this have to do with wifi/mqtt failure. My Sonoff also sometimes restart without reason (and goes back to a “ON” status directly after restart).

I cannot think of another reason than wifi failure or mqtt being too slow to respond/unreachable.

Maybe trying a reconnection for a few second to either wifi or mqtt would avoid this problem?

Which model is it?

The simple Sonoff Wireless control switch

There is no code in the current Github repository for the basic Sonoff that turns them ON after a reboot / restart. Something else is going on.

Btw, instead of restarting esp8266, have you considered to have loops to try reconnecting mqtt and also Wifi when it is disconnected?

how do you flash it in there, easy to dismantle the s20?

:fearful: I’ll have to see what are the exchanged mqtt message in this case. I can hear the relay click, my light turning off and a few second later the relay clicking and the lamp turning on again.

Hi claudio,

yes very Easy. Just one Screw and you can dismantle it. After that there a 2 additional screws, that hold everything in place inside.

After that just solder a 4 Pin-Connector (or what ever you like) on the board and flash kmanoz firmware.

Here are some Pictures, for the Teardown: http://tinkerman.cat/s20-smart-socket/