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

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.

Did you end up figuring anything out? They’re back on a serious sale on amazon (I picked up 4 for less than $25). I am trying to reverse engineer it, but I’d rather not reinvent the wheel.

No, I haven’t bought any but it does have the esp8266 so it should be flashable.

I updated a few of my Sonoff devices with the latest software, works perfect! But somehow ota update doesn’t seems to work. I see the devices with Arduino Ide but during trying ota update I will get an error with: 19:07:18 [ERROR]: No response from device
19:07:18 [ERROR]: No response from device

Strange some devices OTA will work some others not. Till so far no idea why it went wrong.