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

It 's great to hear that, I wish they will also send this T1 model to you soon. I already replaced some of Sonoff Basics with the old type 1-gang touch switches in my home. Your firmware is very stable. I hope you will make the new ones for 2-3 gang too. Thank you very much.

@KmanOz

I flashed the firmware for the basic Sonoff with the changes I referenced above and with the standard toggle light switch wired up also as referenced above.

It almost works. I can control the Sonoff from HA. I can control the Sonoff from the button. And I can control the Sonoff from the toggle switch…kind of…

If the the Sonoff is in the off state then switching the toggle turns the Sonoff off and on fine. However, if the HA had previously told the Sonoff to turn on then turning on the toggle switch causes the relay to chatter. If I turn the toggle switch off it is stable again.

Any suggestions?

How to configure Sonoff Dual in Home-assistant with newest Tasmota Firmware?

- platform: mqtt
  name: "Deckenlampe"
  state_topic: "stat/sonoff/POWER/1"
  command_topic: "cmnd/sonoff/POWER/1"
  payload_on: "ON"
  payload_off: "OFF"
  retain: true

doesn’t work
MQTT parameters in Tasmota:
set host ip, port, user and password of Broker
topic: sonoff

i think you’ll find there is a Tasmota thread where you can ask this question and get better results.

Got it working

For others here is how to use the Sonoff DUAL with Tasmota:

- platform: mqtt
  name: "relay1"
  state_topic: "stat/sonoff/POWER1"
  command_topic: "cmnd/sonoff/Backlog/power1"
  payload_on: "ON"
  payload_off: "OFF"
  retain: true

- platform: mqtt
  name: "relay2"
  state_topic: "stat/sonoff/POWER2"
  command_topic: "cmnd/sonoff/Backlog/power2"
  payload_on: "ON"
  payload_off: "OFF"
  retain: true
1 Like

Nothing?

Nothing at all?

:disappointed:

might be the same problem i expierienced while using a switch attached to GPIO 14:

https://github.com/arendst/Sonoff-Tasmota/issues/744

Hi KmanOz, I’ve bought one of these Wifi/RF 433 bridges, but I’m new to Sonoff flashing (and HA)

Is it compatible with existing firmware?

@diplix

Thanks for the help but i don’t think it is related (unless I’m misunderstanding something - which is completely possible!)

I’m using KmanOz basic sonoff firmware 1.01pOTA.

The problem crops up when the sonoff is already on via the on-board pushbutton or HA and I turn the toggle switch to the ‘on’ position. In that case the relay chatters off & on until I turn the toggle switch back off again. then sonoff stays on and is again stable.

If i turn on the sonoff with the toggle switch (sonoff previously off) if I then try to turn the sonoff off with the pushbutton or HA then the relay chatters again until i turn the toggle switch off. Then the sonoff turns off and is again stable.

If the toggle switch is on and the sonoff is on and then i turn the relay on again using the pushbutton or HA (and maintaining the toggle in the ‘on’ position) then the sonoff remains stable.

If the sonoff is turned on & off via the toggle switch, HA or the pusbutton while the sonoff is already off it turns on & off like it should and is stable.

It only happens when the relay tries to change state (off to on or on to off) with the toggle switch in the ‘on’ position.

I have tried to set the retain state to false in the firmware but it made no difference in the results.

Also it is not an intermittent problem. it happens every single time i try it in the above circumstances.

@KmanOz, @diplix and others who might (or might not :wink: ) be following along…

I was having trouble with the relay chattering when I turned on an external toggle switch to change the state of the Sonoff.

Here is what I did to solve it:

  1. Using KmanOz’s original ESPSonoff-v1.01pOTA firmware, I made the following changes:

a. In the definitions section I added:

#define WALLSWITCH      14

b. In the void setup() section I added

pinMode(WALLSWITCH, INPUT_PULLUP);

c. In the void loop() section i modified the first block of code to the following:

void loop() {
  ArduinoOTA.handle();
  if (OTAupdate == false) { 
    mqttClient.loop();
    timedTasks();
    checkWallSwitch();       // added by me for wall switch utilization
    checkStatus();
  }
}

notice the indicated change

d. BEFORE the void checkStatus() code I added:

void checkWallSwitch() {
  wallSwitch = digitalRead(WALLSWITCH);
    if (wallSwitch != lastWallSwitch) {
      digitalWrite(LED, !digitalRead(LED));
      digitalWrite(RELAY, !digitalRead(RELAY));
      sendStatus = true;
  }
  lastWallSwitch=wallSwitch;
  }

e. All the above changes were in addition to setting all of my personalization settings in the definitions section

  1. On the Sonoff hardware I connected a standard toggle style light switch between the ground pin and the GPIO14 pin on the previously installed 5 pin header. This is the same header used to program the Sonoff.

That’s it. It now works completely stable no matter how I switch the state.

I didn’t need any other external resistors added since the ESP8266 has pre-built in pullup resistors that just need to be enabled by the INPUT_PULLUP pin mode designation.

Hope this helps the other NOOBS who are still struggling to figure this all out.

1 Like

Also, if your Sonoff can’t connect to your WiFi network make sure your router is setup to accept WPA authentication.

I had 2 routers. One it could connect to and the other it couldn’t. I had to set the one it couldn’t connect to to WPA+WPA-2. It was previously only set to WPA-2.

Hi folks. My sonoff isn’t working with HA and I’m stumped.

From the console
01:45:25 MQTT: Connected
01:45:25 MQTT: tele/sonoff/LWT = Online (retained)
01:45:25 MQTT: cmnd/sonoff/POWER =
01:45:25 MQTT: stat/sonoff/RESULT = {“Command”:“Unknown”}
01:45:25 MQTT: tele/sonoff/INFO1 = {“Module”:“Sonoff Basic”, “Version”:“5.2.1”,
“FallbackTopic”:“DVES_AF5FE0”, “GroupTopic”:“sonoffs”}
01:45:25 MQTT: tele/sonoff/INFO2 = {“WebserverMode”:“Admin”, “Hostname”:“sonoff-8160”,
“IPaddress”:“192.168.1.7”}
01:45:25 MQTT: tele/sonoff/INFO3 = {“Started”:“Software/System restart”}
01:45:25 MQTT: stat/sonoff/RESULT = {“Command”:“Unknown”}
01:45:26 MQTT: stat/sonoff/RESULT = {“POWER”:“OFF”}
01:45:26 MQTT: stat/sonoff/POWER = OFF
01:45:33 MQTT: tele/sonoff/STATE = {“Time”:“2017-08-24T01:45:33”, “Uptime”:0, “Vcc”:3.113,
“POWER”:“OFF”, “Wifi”:{“AP”:1, “SSID”:“removed”, “RSSI”:100, “APMac”:“removed”}}

From config.yaml

light:

  • platform: mqtt
    name: “Garage Bench Light”
    command_topic: “sonoff”
    state_topic: “sonoff/stat”
    qos: 0
    payload_on: “on”
    payload_off: “off”
    retain: true

Here is what my sonoff switch configuration looks like.

command_topic: “cmnd/sonoff/power”
state_topic: “stat/sonoff/POWER”

Seems like the result is similar. Thanks though.

From the console

02:52:02 MQTT: Connected
02:52:02 MQTT: tele/sonoff/LWT = Online (retained)
02:52:02 MQTT: cmnd/sonoff/POWER =
02:52:02 MQTT: stat/sonoff/RESULT = {“Command”:“Unknown”}
02:52:02 MQTT: tele/sonoff/INFO1 = {“Module”:“Sonoff Basic”, “Version”:“5.2.1”, “FallbackTopic”:“DVES_AF5FE0”, “GroupTopic”:“sonoffs”}
02:52:02 MQTT: tele/sonoff/INFO2 = {“WebserverMode”:“Admin”, “Hostname”:“sonoff-8160”, “IPaddress”:“192.168.1.7”}
02:52:02 MQTT: tele/sonoff/INFO3 = {“Started”:“Software/System restart”}
02:52:02 MQTT: stat/sonoff/RESULT = {“POWER”:“ON”}
02:52:02 MQTT: stat/sonoff/POWER = ON
02:52:02 MQTT: stat/sonoff/RESULT = {“Command”:“Unknown”}
02:52:03 MQTT: stat/sonoff/RESULT = {“POWER”:“ON”}
02:52:03 MQTT: stat/sonoff/POWER = ON
02:52:10 MQTT: tele/sonoff/STATE = {“Time”:“2017-08-24T02:52:10”, “Uptime”:0, “Vcc”:3.112, “POWER”:“ON”, “Wifi”:{“AP”:1, “SSID”:“removed”, “RSSI”:100, “APMac”:“removed”}}
02:52:38 MQTT: stat/sonoff/RESULT = {“POWER”:“ON”}
02:52:38 MQTT: stat/sonoff/POWER = ON

Looks like this should be …
cmnd/sonoff/POWER

and
state_topic: “sonoff/stat”
should be
stat/sonoff/RESULT

This allows me turn the light on but not off. After toggleing the button in HA this light goes on but the button almost immediately return to off (the light remains on)…

command_topic: “cmnd/sonoff/POWER”
state_topic: “stat/sonoff/RESULT”

23:49:37 MQTT: Connected
23:49:37 MQTT: tele/sonoff/LWT = Online (retained)
23:49:37 MQTT: cmnd/sonoff/POWER =
23:49:37 MQTT: stat/sonoff/RESULT = {“Command”:“Unknown”}
23:49:37 MQTT: tele/sonoff/INFO1 = {“Module”:“Sonoff Basic”, “Version”:“5.2.1”, “FallbackTopic”:“DVES_AF5FE0”, “GroupTopic”:“sonoffs”}
23:49:37 MQTT: tele/sonoff/INFO2 = {“WebserverMode”:“Admin”, “Hostname”:“sonoff-8160”, “IPaddress”:“192.168.1.7”}
23:49:37 MQTT: tele/sonoff/INFO3 = {“Started”:“Software/System restart”}
23:49:37 MQTT: stat/sonoff/RESULT = {“POWER”:“ON”}
23:49:37 MQTT: stat/sonoff/POWER = ON
23:49:37 MQTT: stat/sonoff/RESULT = {“POWER”:“ON”}
23:49:37 MQTT: stat/sonoff/POWER = ON
23:49:37 MQTT: stat/sonoff/RESULT = {“Command”:“Unknown”}
23:49:38 MQTT: stat/sonoff/RESULT = {“POWER”:“ON”}
23:49:38 MQTT: stat/sonoff/POWER = ON
23:49:45 MQTT: tele/sonoff/STATE = {“Time”:“2017-08-24T23:49:45”, “Uptime”:0, “Vcc”:3.113, “POWER”:“ON”, “Wifi”:{“AP”:1, “SSID”:“removed”, “RSSI”:100, “APMac”:“removed”}}

If the button goes off, that means the device is not sending back the status in the stat topic exactly the same as it went out from HA in the cmnd message or HA is subscribing to the wrong stat topic. Probably HA should subscribe to stat/sonoff/POWER then.

Same problem here:
switch:
- platform: mqtt
name: “Switch Lavatrice”
state_topic: “stat/sonoff/power”
command_topic: “cmnd/sonoff/power”

The stat topic is the correct one, but in HA after some second the button return off. In mqtt the command result sounds good:

stat/sonoff/POWER ON

I suspect there is a bug somewhere…

@ivandal77

state_topic: “stat/sonoff/power”
is not the same as
stat/sonoff/POWER

My config:
-platform: mqtt
name: Sonoff_Basic
state_topic: “stat/sb10-1/POWER”
command_topic: “cmnd/sb10-1/POWER”
qos: 1
payload_on: “ON”
payload_off: “OFF”
retain: true

response from sonoff:
topic: stat/sb10-1/POWER
message: ON

I have about 6 or so of these on my network. All running tasmota.
They are working perfectly. No issues.

You’re right, now it works!
Sorry my misunderstanding.