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

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.

@KmanOz

Maybe a nice feature to add in your repo, an online topic.
With HomeAssistant devices will be unavailable once the device is not connected anymore.
Once there is a power failure or your device is broken for e.g.

The devices will be greyed out and no possibility to operate them.

This is done with a “Last Will and Testament”
https://www.hivemq.com/blog/mqtt-essentials-part-9-last-will-and-testament

Sonoff Code

  if (WiFi.status() == WL_CONNECTED) {  
    Serial.println(" DONE");
    Serial.print("IP Address is: "); Serial.println(WiFi.localIP());
    Serial.print("Connecting to ");Serial.print(MQTT_SERVER);Serial.print(" Broker . .");
    delay(500);
        while (!mqttClient.connect(MQTT::Connect(UID).set_keepalive(30).set_auth(MQTT_USER,MQTT_PASS).set_will(MQTT_TOPIC"/online", "no", QOS, true)) && kRetries
--) {
      Serial.print(" .");
      delay(1000);
    }
    if(mqttClient.connected()) {
      Serial.println(" DONE");
      Serial.println("\n----------------------------  Logs  ----------------------------");
      Serial.println();
      mqttClient.subscribe(MQTT_TOPIC);
      mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/online","yes").set_retain().set_qos(QOS));

HomeAssistant Code

    state_topic: "bathroom/switch/0001/ventilation/state"
    command_topic: "bathroom/switch/0001/ventilation"
    availability_topic: "bathroom/switch/0001/ventilation/online"       
    entity_namespace: bathroom
    qos: 0
    payload_on: "on"
    payload_off: "off"
    payload_available: "yes"
    payload_not_available: "no"  

@KmanOz - I run multiple Wifi Access points on my home network - same SSID, different channels and same passwords

In order to get it to work I had to set the Wifi Channel and BSSID Mac address

I upgraded ESP8266 Board to 2.4.1

and in

KmanSonoff_v1.00sc.ino

  `uint8_t bssid[] = {0xXX, 0xXX, 0xXX, 0xXX, 0xXX, 0xXX};`

  `WiFi.begin(WIFI_SSID, WIFI_PASS, 1, bssid);`

The XX are each pair of chars from the BSSID of the router I wanted to connect to

Hope this helps someone

Thanks for the firmware! It’s just what I was after - something light and simple that’ll allow HA to handle all the logic.

Is it possible for the state of the relay to be on every time power is applied? The idea being, if my RPi or wifi network dies for any reason, I can always just use the light switches on the wall as a manual fallback. I do realize everything will switch on after a power outage, but thankfully they’re very rare here!

Hi, I would very much like to ask for the advice of more experienced colleagues. In my cottage I use a wifi thermostat to control the heating, which I knew how to set different temperature intervals, turn the heating on and off. this is how I was able to remotely switch heating from antifreeze temperature 6.C to comfort temperature 22.C. Since this one went wrong, I bought a new wi-fi brand Sonoff TH 16. When ordering the goods, the seller told me that even in this device you can set different daily temperature regimes. So I had the technicians replace the original relay with a new one. But I was very disappointed because the application is ewelink, it can only turn the heating on and off through this device and shows what the current temperature is, he can’t do anything more. I would very much like to ask that there is no alternative firmware through which I could set different temperature modes in the device remotely, via wifi, for example to heat at 22.C degrees during the day and only at 17.C degrees at night. Thank you for any good advice Jan

KManOz - Let me start by saying ‘Thank you’!

Question: Line 24 of config_sc.h defines the IP address for the MQTT_SERVER. When I first installed your software, i used the address 10.255.221.108, but I am not sure what this is! I now want to rebuild my system and I have been able to install a MQTT server on the Raspberry Pi device that runs Home Assistant. So, can i simply put the IP address if the Raspberry Pi in line 24?

Thanks.