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

I’d say they are models about to be released. 2 3 & 4 channel wall switch would be nice. I will ask Sonoff and find out.

They look like broadlink switch:

Also sold under the name VHome, they are 433MHz walls switch but not esp based.

They are probably an esp based variant.

can you explain more in detail, sorry newb here

First, my Sonoff is the basic version, so this diagram and the PCB would fit only this type of Sonoff switch.
Basically, the circuit holds an RC filter to debounce wall switch and the resistor needed by DTH22. Also provides a PCB header in wich you can insert the DTH22 directly. Obviously the Sonoff’s enclosure box must be modified to fit the DTH header and the wall switch clamp.
Here the circuit diagram

Actually the C1 is a 47uF and the other components are not yet defined (in the breadboard works great but when i use a long cable to connect the wall switch, seems that sometimes the capacitor not charge properly so the switch does not commute).

Sonoff Pin 1 is +3.3v, then RX pin, TX pin leaved, ground and GPIO14.
DTH22 pin1 is V+, then DATA, pin 3 not used, and ground.

I’m planning to drive the DTH22 with 5v not with 3.3v provided by the Sonoff programming interface pins because seems that reads values with an error of +4°C if compared to a mercury thermometer. So, work is in progress.
I want to try the new Kmanoz firware too.

Well I’ve buckled and have been working on OTA for all versions of the firmware, and I have it going and tested so will be releasing it soon. I had a situation here where I had to change my WiFi password and it was a PITA on 20+ devices. I can’t seem to make it work in my Windows environment but am not prepared to troubleshoot it there considering it works on all models with OS X so chances are very high it’s my Windows machine at fault.

Anyway …

EDIT: Got Windows working. As I thought, stupid Windows was setup for public network and firewall was blocking the port. All good so happy to get this out ASAP.

2 Likes

Hi guys,

this may be a remarkably stupid question, but how do you install the copper wires into the TH10 / TH16? I was expecting a standard screw mechanism, but I cannot get the wires to stay in those gray clamp things. Do the white plastic clips on top do something special?

Thanks and Cheers,
Kevin

you have to press down the plastic clips while inserting the wire

gl

D’oh. Why was this so obvious… Thanks, @MrMep :slight_smile:

@KmanOz Thanks for the work. I tried to use your firmware but seems there is a bit issue. Below message showed in the serial monitor:

------------------ Sonoff Powerpoint v1.01p ------------------

Unit ID: esp8266-9597EB
Connecting to XXXXXXX Wifi . . . . . . . . . . WiFi FAILED!

WiFi connection . . . . . . . . . . LOST
ets Jan 8 2013,rst cause:1, boot mode:(1,6)
ets Jan 8 2013,rst cause:4, boot mode:(1,6)
wdt reset

Any idea where might go wrong? Thx!

Any one know of there is any video on youtube how to flash it?

Check if your SSID and Password are correct, if the chip cannot connect to wifi, it will restart. So your sonoff is simply unable to connect to wifi as it seems.

@blackgear but this works with momentary switch or latching switch?

Thanks!
Actually I have been connected to the Wifi a few times. Just after I remove the Vcc pin and plug it back it wouldn’t connect and show the error message. If I change to a separate SSID it would help, but only for the first time.

It is very strange and I have no clue why it is behaving like this…:frowning:

@Rodolfo_Vieira the differences between managing a momentary or latching switch should be in circuit components values and in the software routine.
Mine is a latching switch, it stay “on” or “off” until someone change its status.

Well, @KmanOz why not perform a GET request to the HA API to get the latest switch status? for HA users will solve the EEPROM life problem. To be honest, I’ve leaved this solution because the Sonoff should compare the DateTime of the last “local” switch to the DateTime received by the HA API before choose to ignore the MQTT message…

…But it should be the solution to power outages… In the init procedure, before mqtt loop, get the state from the API and set the relay.

I have a couple of these running on your firmware and it is rock solid. Was looking at replacing some of my old Zap 433 mhz switches with the Sonoff RF versions. Have you got any plans to update your firmware to that model. I know you have a lot on your plate with the OTA stuff just wondering. Thanks again for the great firmware.

Are you using static or dynamic IP address? Maybe it’s your router that have problem attributing IP address fast enough.

If you’re using DHCP, try using static IP address.

Have you tried increasing the delay or the number of retryes in the connect function? Either should work

I think I might be having a similar issue to blackgear.

I’m using internal mqtt server to HA. If I have the sonoff ON and I restart HA it will reset the sonoff to OFF. No automation or other rules related to these devices. Tested with my bone stock HA dev just to verify.

My qos: is set to 0. Should it be 1?

Is this by design? Because i’m using internal MQTT server? Would the keep state on power changes you added fix this?

Thanks again for the work!

Guys

I have just upgraded my whole network to the OTA version of the firmware and it works great. I needed to change my WiFi password :smiley: That’s close to 30 devices including some Arilux LEDS and Sonoff LED that are all OTA upgradable. Will update it shortly but had to make sure it was rock solid and it is.

Iv explained this before but I will explain it again. With my firmware it expects the mqtt server to be up all the time. I designed it that way because once you get serious about Home Automation (and considering my whole network is mqtt 30+ devices) then having it go up and down is not an option. I use a separate mqtt server to HA. mqtt stays up all the time even with a power failure because my servers are on a UPS. If mqtt goes down then the Sonoff will reset after 1 minute. That is changeable in the firmware but it will reset and hence the relay will drop. If it’s v1.01 firmware then it will come back to the previous state but you will see it turn off then back on.

You should be able to use the firmware in the RF version of the Basic Sonoff Switch. Give it a try.

There is a EEPROM life problem? You are putting the cart before the horse I think. Yes there is a theoretical limit to read/writes but when it fails it just means the guaranteed data rentention time is not guaranteed anymore. It does not mean that it stops working immediately. It means that it may lose memory sooner. 100,000 read/writes is a long time. Will the Sonoff even last that long? It’s not really a problem.

I see you have ideas of your own. Why don’t you create a PR or FORK and make the changes you require. Or maybe you can re-write the whole firmware altogether and make it better your way? Good little project for you.

OK well it’s not connecting to WiFI. Move the unit closer to your access point. Change kRetries in the firmware to a higher value, make sure yor password and access point name is correct. There’s nothing else I can suggest. That part of the firmware doesn’t have an issue. If it persists, try another Sonoff / Router combination. Basically it’s not the firmware.

1 Like

Thank you for taking the time to reply. Everything is on a ups here and I had a feeling that it was due to the internal mqtt. I do disagree with the timing out and turning state off or resetting upon disconnect of mqtt - but that’s the beauty of open source. I can take your great code and make it work the way I want. Thanks again!

I’m going to place an order for more soon, probably picking up the sonoff dev to play with. Do you need any of their devices to further development or anything I can pickup from them for you?