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

For the resistor: the need for the resistor depends on many factors: the strenght of the ESP internal pull-up, the capacitance of the cable, the input voltage etc… With the resistor it must work, without it can work. In my own experience, the DS18B20 in TO-92 (the 3-pin transistor-like) with short wires worked without, the waterproof version with the stainless encased sensor and attached 50cm cable without resistor always reported “0°C”

For the “offline” problem, have you configured the Last Will for your devices?

This is my configuration for Sonoffs` with Tasmota, see the availability topic and payload available/not available:

  - platform: mqtt
    name: "Sonoff 2"
    state_topic: "stat/sonoff-2/POWER"
    command_topic: "cmnd/sonoff-2/POWER"
    availability_topic: "tele/sonoff-2/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    retain: true

The last will is a retained message. This way HA should recognize that the devices are available when it connects to the broker, because it gets the “Online” message.

Does this one work with Sonoff Wifi Relay 5V?
Tasmota does, but at startup it turns on and off quickly and that would be enough to open the door unintentionally, for example…

Thank you!

Post 1 of 2: Some things I have learned as a newbie that may help others

First, the ubiquitous ‘Thank you’ to KamnOz!

My project status: I have an industrial-grade WAP in my house and I configured one of the SSIDs specifically to support my home automation system. I installed Home Assistant, ‘from scratch’, on a Raspberry Pi 3 and configured its wired Ethernet port to connect with my primary home network and the wireless Ethernet to connect to the aforementioned SSID. I then installed mqtt and everything (a SOnOff S20 and a SOnOff basic) is up and running.

SOnOff pin-outs: Sometimes the pin-out changes between versions of the SOnOff device. Specifically, the Rx/Tx pins for the S20 seem to have flipped from the first release to the one I purchased. This leads to…

Suggestion for solder-in header: For me, simply placing wires in the holes did not work and since the pin order from device to device can change, a header that allows one to use a single programmer cable with all devices is desirable. I resolved this problem buy soldering in Samtec SSA-104-W-T. This header has spring terminals that will grab a 22 awg solid wire quite nicely. Thus, my programmer has four bare wires and I simply plug them into the header – takes only a few seconds.

External switch for SOnOff Basic: In my kitchen, there is a two gang switch – one for a light (which I want to control) and one for the disposal (which is on a different circuit). Since the devices are on different circuits, using a standard SOnOff T1 or Touch is not an option – not enough room. I was able, however, to ‘bury’ a SOnOff Basic inside the box, but this required an external push button. I found that unsoldering the existing button without lifting the pads to be very challenging. What was easier was to remove the top part of the switch, exposing its inner contacts and soldering to them was easy. Add a drop of silicone or epoxy to help secure them in place and cut a small notch in the side of the case (to route the wires) and done.

Arduino IDE settings: In some instances, setting the chip type to Generic ESP8285 Module (instead of Generic ESP8266 Module) is required. Try looking at the board using a 10x loupe to see which chip is actually used. Also, per a post from KmanOz, “The new Sonoff Basics I have received are using a different EEPROM … but will not boot correctly unless you use FLASH MODE = DOUT in the settings”.

Thanks @KmanOz for this firmware I have had the old version running on some switches for over a year now and never had any issues with them.

I flashed a new batch of Sonoff basics yesterday with the newer KmanSonoff firmware and the process was slightly different - had to use DOUT flash mode, and the newest esp8266 board would not work (downgrading to 2.3.0 solved it for me). So if any of you are having trouble flashing, try downgrading the esp8266 board definition.

I wrote up some notes here:

1 Like

Please help me configure my two-gang SOnOff T1 properly. I was able to flash the device and I see it communicating with my wireless access point. However, HA cannot control it and when I press either button on it, HA does not respond.

My config_mc.h files looks like this (left out everything that has been tested/confirmed with single channel devices):

> #define CH_1                                                  // Channel 1 (Default single channel. Do not comment out)
> #define CH_2                                                  // Channel 2 (Uncomment to use 2nd Channel)

> #define MQTT_TOPIC       "home/sonoff/garage/1"          // Base mqtt topic

My configuration.yaml file looks like this:

  - platform: mqtt
    name: "Garage Inside"
    state_topic: "home/sonoff/garage/1/stat"
    command_topic: "home/sonoff/garage/1"
    qos: 0
    payload_on: "on"
    payload_off: "off"
    retain: true

  - platform: mqtt
    name: "Garage Outside"
    state_topic: "home/sonoff/garage/2/stat"
    command_topic: "home/sonoff/garage/2"
    qos: 0
    payload_on: "on"
    payload_off: "off"
    retain: true

My assumption is that the state_topic and/or command_topic are not properly defined. Please advise.

Subscribe to the home/sonoff/garage topic on your MQTT server and see what messages are being sent.

oakbrad - thanks for the speedy reply

It turns out that I have full logging enabled for my mosquito mqtt server, so looking at the log file is easy (thankfully!)

In a nutshell:

  • The garage device is talking to the mqtt server
  • The message traffic for the garage device appears to be ‘identical’ to that of the kitchen device
  • When I toggle the garage device from the HA dashboard, I see a ‘Received PUBLISH from home-assistant-1’ followed by a ‘Sending PUBLISH to Sonoff_989835’. (This is the exact same behavior I see when I turn on one of the other lights. The difference is that with the other lights, I see a ‘Received PUBLISH from Sonoff_429AAB’ after the ‘Sending…’, but I do not see this for the garage device.
  • I only see home/sonoff/garage/1 in the log - home/sonoff/garage/2 is missing.
  • I edited configuration.yaml to include logging. When I manually activate the T1 device, I see log messages such as ‘Received message on home/sonoff/garage/1/stat: 1on’. (This is true for both switches.) However, the switch status is not reflected in the HA dashboard. Also, when I try to change the switch state from the HA dashboard, no messages are logged (they are when I toggle the other devices).

Hopefully, this additional information provides some useful clues.

Hello,

Anyone knows that this compatible with Tasmota?
https://pt.aliexpress.com/item/QIACHIP-220-V-Wi-fi-de-Casa-Inteligente-Interruptor-3-Gang-86-Tipo-de-Vidro-APLICATIVO/32847327096.html?spm=a2g0s.9042311.0.0.oy9nnO

Thanks you

You may want to follow @nickrout here

1 Like

Did you ever get these working? I have a 2 gang device and it refuses to have firmware uploaded. I am getting a new FTDI in the next few days so will try again with that.

I not even received mine yet!!! Can you believe that?
110 days after buying from Brazil!!!
Asa I get it, I’ll try uploading the firmware…

nickrout: Two quick comments:

  1. With a minor amount of creativity, you can make the UK version of the T1 work in the US. Specifically, take a two-gang blank face plate, cut out an opening than allows the T1 to fit, and epoxy a couple of nuts on the back-side of the cover plate (to hold the T1 - the screw holes to hold the plate onto the box will get partially covered, so the cover plate needs to be mounted first, then the T1. I would send a picture, but mine is not yet installed (see my posts above…)

  2. What do you mean by “it” and “refuses”? If you are talking about a SOnOff T1 and cannot get it into programming mode, try the following:

  • Plug the T1 into your programming device and make sure everything is powered
  • Holding the T1 such that the small, S1 switch is facing you and at the bottom, press and hold the touch switch on the left
  • While continuing to hold the touch switch, press and hold S1 for about one second
  • Continue holding the touch switch for about another second or so after releasing S1

I’ve done a couple Sonoff Basics in the electrical box myself and it can be a chore at times but I do use a standard dumb switch in front of it. I usually solder in a 5 pin header on my Sonoff Basics anyways, but when I put one inside, I put the two leads on GND and the 5th pin which is GPIO 14. Then I assign a toggle state to it so when the state of the switch changes it toggles the relay. Works pretty good and can’t beat the price for other switches such as Zwave or whatever, combined with this being on WiFi, open source, and you can modify the code yourself, it’s a huge win win for me.

Hi KmanOz,

Sat reading this entire thread last night and this morning, and just wanted to say a huge thank you to you for the work you put in, and for sharing your code.

I have a few Sonoff basics, a clone of the T1 2-chan, and a WiFi bulb so far, and I intend to flash them all to your minimal firmware - and buy lots more! (This time direct from itead).

Couple of observations:

  1. I could see by the bottom end of the thread that the amount of negativity, and people not reading the title, discussing Sonota, ESPeasy etc) seems to be rightly annoying you - would annoy me too frankly. Just hope it doesn’t cause you to abandon this thread or your good works.
  2. How about you implement some sort of counter, where either automatically or via a button, you can count the number of users who use your firmware? (And extend that, to make something where users can put in the number of devices they use your firmware on). Might be far more than you realise :smiley:
  3. Finally, why don’t you add your Paypal info at the bottom of your page, make it “donationware”? I know the entire point of using Sonoff is to keep costs to a minimum, but tbh if your fw works as well as this thread suggests, I’d be more than happy to throw a few £ your way just to show appreciation - and I’m sure so would many others.

Will update as I start using your firmware

Very disappointing! We had a power outage here today. Post outage, my SOnOff S20_US V1.3 was not responding. Long story short - it died. While it can still be programmed, when plugged into an outlet, it does not power on. Given the design of the device, it cannot be disassembled without being destroyed, so I have no idea what failed.

I have three sonoff basics and a sonoff 4ch (with three more basics on the way). I’ve only been in this HA game for a few weeks and reading this thread raises a couple of questions for me.

This is not meant to be taken in any negative way - I also don’t understand why anyone would be down on this - if you don’t want to use it then don’t. But is there any reason for me to change to using this firmware instead of Tasmota? Like I said I ask this out of ignorance not to be antagonistic.

Thanks.

the only real reason is (in theory) is the simplicity of it.

it just does one thing. Tasmota is extremely versatile but that makes it complex.

either one will work. you just have to decide which one meets your needs.

Hi, thanks for your post. I haven’t really logged in for quite some time so was good to see.

Initially I created this firmware for ME to use personally. A few years back I offered it to someone in this group (I think it was here at least) and they liked the simplicity of it. They convinced me to publish it and after some thinking I put it up as a Github repository for others to use. To be honest I had no idea it would become popular and I was a little over whelmed with how many people decided to use it. From that came a whole bunch of suggestions, additions, modifications and some bugs (although minimal) but most of all a lot of negativity, and to be honest Im not sure what they were negative about exactly. It’s just CODE !!! and it was free !!!

Yes Tasmota existed and is fantastic code, and from a programatic point of view far better code (in terms of writing skills) than mine is, but for me at least was unnecessarily complex and cumbersome.

Initially I started defending my work and some of the stupid comments on here but grew tired of it very quickly, so yes you are right I stopped working on it. I haven’t really needed any other features personally so I thought to myself why bother trying to keep working on it if it isn’t being appreciated and constantly being crapped on. The thread started getting so full of rubbish that it made it impossible to follow a conversation anyway so I stopped paying attention here as well.

Not sure how I’d implement a counter exactly and I never thought anyone would be interested in paying, considering that Tasmota is also free and has many more features. EDIT: I just noticed that Tasmota has a Donate button. I may have a think about it again :smiley:

I thought I would try and give back to the HA community but after all the crap, just stopped caring :smiley:

3 Likes

Sorry to hear that @KmanOz. Thank you for your contribution to the home assistant community. I hope the reconsideration leads to an active return in the community :slight_smile:

Hi KManOz

Thanks for your firmware, I’m enjoying playing with it!

However I’m stuck trying to get temperature and humidity working on a TH16 with the Sonoff Si7021 sensor that plugs into the jack socket.

I’m pretty sure the problem is with my configuration of the firmware, not Home Assistant.

I’ve set

#define TEMP
#define TH
#define DHTTYPE DHT22

And the code compiles, so I’m fairly sure I have the right libraries installed - is this the right incantation for the TH16 with the sensor?

A.