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

this is what I don’t want to do …

Hi. I’ve flashed the @KmanOz sketch and I have the same issue. Relay on, switch off WiFi, switch on WiFi, and as sonoff connect to mqtt after wifi, the relay switch off… Seems an mqtt message but i don’t know how to solve or troubleshoot

The firmware is working perfectly in this situation. If the WiFi signal is lost, the switch will reset after 1 minute and currently the relay will return to off. This is not a problem at all. This firmware relies on WiFi and hence mqtt being available and stable 24/7.

I am not going to re write the firmware at this stage for WiFi signals that go off or mqtt networks that are questionable. All I can suggest is, if you are someone who turns off your WiFi or mqtt server overnight then this is not the firmware for you. An automation network should have all of it’s resources on all the time. I am however about to release a version that does remember it’s state after it’s been reset and will come back on in said state. This is more for power failures and if a switch was say connected to a fridge. Anyway sorry I can’t help.

The code is up on GIthub. If someone wants ro create a different routine that’s bulletproof (repeat bulletproof) for checking WiFi & mqtt services are there then do a pull request. I have tried it before and I found that sometimes the ESP8266 would get stuck in a loop looking for services and never come back even though the services had returned. Hence why I do a complete reset.

Ohh that’s a problem. Where I live I do have power outages often, unfortunately

I’m sure you misunderstood my last post. In a couple of days it won’t be a problem when I release an updated version that allows for power failure. Stay tuned.

Yes, you’re right but I ask if someone has same trouble. My WiFi turns off overnight and I cannot understand why the switch turn off when WiFi comes back if its state was transmitted and persistent on mqtt. I’ve already written my firmware looking at your code, to manage wall switch, but i’ve asked here because here is where i’ve started and here there’s people that have mod the sonoff. And i’ve seen that tour firmware has the same problem. Sorry if you 've wasted time for my trouble, is not my goal.

Sorry I misunderstood LOL. When I embarked on automating the house I soon realized that having a backend (Wifi, Servers, Switches, HA Server etc) that wasn’t on a UPS was silly so I added a UPS to my main setup. Having to restart all the backend after a short power failure was just a pain in the ass. I keep forgetting :smiley:

Yes I have UPS already too.

My case is the following:

  • pi3 on UPS (running HASS and soon I guess mqtt server??)
  • router and extender on UPS
  • switches NOT on UPS

not sure if with a power outage I have Internet though … need to check that

That’s basically what I have, different equipment but same deal. I run mqtt server separately to HASS. I run mqtt server on my NAS which is always up. If I lose power (currently) all switches will come back on in the OFF state. In the next couple of days with the firmware update, switches that were on will come back on.

Well put your modem / router on the UPS as well and you will.

Same behaviour here. I have 2 basic switches and 2 POW switches. All four show the same behaviour.

I have a NAS too. WHy you separate? I mean if HASS is not working, you will not use your mqtt anyhow, no?

Because it’s the backbone to my whole network. Everything I have runs on mqtt, for me at least it’s important it stays up. I have more than just Sonoff’s running. RF Gateways for PIR’s, Smoke Detectors, Alarm Panel, Weather Station receiver etc etc. It needs to be up. I also run Node-Red which relies on mqtt. It’s like saying ethernet goes down in your house and it doesn’t matter. It’s an essential service for me.

can you share which?

Trying now also to build RF system

It’s my own design Hardware/Software

I’ve built a Shield. It uses the RX pin to handle a wall switch, debounced with R-C filter, and provides an DHT socket



I’m testing the WiFi/mqtt reconnection process (my WiFi is turned off overnight)
:slight_smile:

1 Like

@piotr @touliloup @blackgear

Guys I had some time to have a look at your problem today. I think i have discovered an issue. Please check your configuration.ini where you have setup the switch(s). Is the switch currently set to QOS 1. Example:

switch:
  - platform: mqtt
    name: "Living Room"
    state_topic: "home/sonoff/living_room/1/stat"
    command_topic: "home/sonoff/living_room/1"
    qos: 1
    payload_on: "on"
    payload_off: "off"
    retain: true

If so try changing that to QOS 0 then restart HA and tell me if the same situation happens.

Thanks

Yes, qos is on 1, but won’t it make it worst to put it to 0? Or is there a special reason qos 1 would be problematic in this case?

I’ll try tonight, thanks :slight_smile:

All

I have updated the Github and added v1.01 files. Basically EEPROM support for relay state, Wallswitch support for external switching and general cleanup of stuff.

Any question let me know.

Cheers

Hello KmanOz!

Do you happen to know what is this for mystery device? Can’t find it on Sonoff’s website:

http://webcache.googleusercontent.com/search?q=cache:u5x3krzVSNkJ:103.249.111.24/index.php/2016/06/08/switchen/+&cd=12&hl=sv&ct=clnk&gl=se&client=firefox-b

I also discovered that you turn off onboard LED when you switch power on. Very nice. Thank you!