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

You can try Espurna:

https://bitbucket.org/xoseperez/espurna/wiki/Home

Running into some problem here, probably very basic thing since I´m new to MQTT.
This is the HA config I´m using:

mqtt:
  broker: core-mosquitto
  port: 1883
  client_id: home-assistant
  keepalive: 60
  protocol: 3.1.1


# Sonoff Switch
switch:
  platform: mqtt
  name: "sonofflamp1"
  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

This is the Sonoff config. I´m using

I can see the switch in the HA interface
14

But I´m not able change the state with the switch. When I click it nothing happens (though the switch is in on state and the lamp is on.

Also I get the following log in MQTT

If anyone pls could give me a pointer in the right direction it would be great. Thanks!

This was a massively valuable piece of information. any chance it could go in your readme to help someone else find it sooner?

Hi @KmanOz - do you still need testers?

@KmanOz Tester here :slight_smile:

PLEASE. Maybe off topic but…

Sometimes you have single light but multiple switches. Lets say upstairs and downstairs. How to solve the situation where you use 2, 3 or more switches for single light? HA should compute status of all of them and decide if this = ON or OFF.

Thanx

Guys I have just created a new repo. This is a smallish rewrite of the firmware to hopefully make setup even easier. Please leave comments and suggestion here on it’s ease of use etc.

Thanks it’s taken a while cause I’ve been busy but hopefully it’s well received.

Problems here to connect 0.56.2 (last, i think) version of Home Assistant. Last version of repository manOz/KmanSonoff and the last version of the Mqtt library Imroy/pubsubclient

Mi broker config

mqtt:
port: 1883
client_id: home-assistant
username: homeassistant
password: welcome
keepalive: 60
protocol: 3.1.1

Sonnof config:

#define MQTT_SERVER “192.168.0.3” // Your mqtt server ip address
#define MQTT_PORT 1883 // Your mqtt port
#define MQTT_TOPIC “home/sonoff/caldera/1” // Base mqtt topic
#define MQTT_USER “homeassistant” // mqtt username
#define MQTT_PASS “welcome”

Sonoff log:

-------------------- KmanSonoff_Basic_v2.00 ------------------

UID: Sonoff_F9A22E
Connecting to lowi3B00 Wifi . . . . . . DONE
IP Address is: 192.168.0.160
Connecting to 192.168.0.3 Broker . . . .

Never goes further and after 5 minutes or so

Connecting to 192.168.0.3 Broker . . . . . . FAILED!


mqtt broker connection . . . . . . . . . . LOST

ets Jan 8 2013,rst cause:1, boot mode:(3,6)

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v3de0c112
~ld

Home Assistant log:

2017-11-02 11:57:19 INFO (MainThread) [hbmqtt.broker] Connection from 192.168.0.160:1070 on listener ‘default’

Some help here?

I have to install mosquitto broker in order to make it run

Something happened with a certain version of HA. I stopped upgrading a while ago. Too much troubleshooting every time I did an upgrade. I think Im on 49.x. 50.x broke mitt for me and I couldn’t be bothered working it out.

Hi @KmanOz - I had a look at your Arduino source code - and I see you have added some debug information about the wifi connectivity. I can’t really see this mentioned anywhere in the documentation - could you write a couple of lines on how to you envision to visualise that information in HASS?

Hi @ralu

LOL I forgot to document and clean some stray code before I published it. Oh well. The info that is published in MQTT_TOPIC/debug is useful if you find the switch losing connectivity by checking RSSI. I never had plans for the info there to appear in HA. You would probably need an mqtt client like mqtt-spy to make any use of it. As for the heartbeat (MQTT_TOPIC/heartbeat), I use that for testing and forgot to remove it :smiley: When I get some time I’ll clean up the code but it shouldn’t effect anything.

Kman

@KmanOz I rather like the debug info - and I would probably add it to HA in order to monitor wifi connectivity of my devices. I would probably create a view for detailed information about my esp8266 based devices.

Just a side-note, I know this project is intended for Sonoff devices (and I do have a couple running your firmware) but I also have a few Wemos D1 Mini based devices that is also using your firmware - I just wanted to mention that there is use for it outside of the Sonoff product-line :slight_smile:

Hey if you get it going post up a screen shot so I can have a look :smiley:

Actually this firmware came about because I had quite a few ESP-8266 projects that I built well before ITEAD released the Sonoff. I quickly just adapted it but yes can be used on heaps of other ESP based products for sure. I just cannot be bothered adapting it to all of them all and testing etc mainly because I don’t have any of them here. ESPEasy and Tasmota do a good job of that. There’s no need for another one in the space. Like I’v always said, those firmware are extremely adaptable whereas mine is just simple. I put it on the Sonoffs and never look at it again until I need to update if for whatever reason which is very rare. I guess I could support more sensors but again I don’t have them here and for general temp the DHT22 does a good job and it’s cheap. Anyway good to see it’s working for you :smiley:

Also I know that most of the issues people have are not with the firmware. I don’t have time to keep adding features and troubleshooting etc. Tasmota would be a lifelong project.

So, after a few months of using the Sonoff switches to control simple overhead lighting circuits I’ve decided to move away from using them. They are simply too unstable to be used for household lighting.

I’m using them to control 4 lighting circiuts and I have the wall switch support coded in. The problem I’m having is that the lights randomly flicker on & off. It doesn’t matter which position the wall switch is in. At first I thought it was better if I left the wall switch on (closed) but the more I used them I realized that it was only marginally better. The lights still flicker randomly off & on. Not all the time but enough to be really irritating when it happens.

All of them do it to some degree but I only have the problem significantly on 2 of the switches - one in my basement and one in my detached garage. The other two (also in the basement mounted only about 6 feet way from the problem one) only seem to be an issue when I switch the other lights on or off from the wall switch. It’s almost as if there is interference on the wifi system caused by the lights switching.

They have been doing this since about a week after I got them all wired in. At first I thought it was because I was getting interference from the main power going to the lights interfering with the wall switch input (induced voltage) but I switched to using a shielded cable and it didn’t help.

My wife was (reasonably) irritated with the flickering. Then the nail in the coffin, so to speak, was when my wifi router went down (tripped breaker feeding the router outlet for a separate reason) and all of the sonoffs started randomly turning on & off. I had no stable control at all from the wall switches (either off or on).

If anyone has any suggestions to fix the problems I’m having I’d love to hear them. I really would like for the sonoffs to work reliably because of the price point compared to other devices but until then I think I’m going to upgrade to zwave switches. I found some on Amazon for around $25. not great but not $60 either.

Any suggestions? Anyone else having these kinds of problems?

I’ve never had that issue, there must be something up with the way they’re wired. Are they the basic version or rf?

basic

I’m not sure how they could be wired differently. there is 110v on the input, lighting circuit on the output and I have the wall switch connected between GPIO 14 (the one closest to the main traces) and the ground pin on the GPIO header.

You can look up thread to see the code I’m using. It’s just Kmanoz’s code plus the changes I noted above.

They “kinda mostly” work. Until they don’t… then it just gets really annoying especially for the wife. Then if the wifi goes down (which has only happened twice) then all bets are off. They just randomly turn on and off.

I checked the signal at the switches with a wifi analyzer and the signal strength was really good. There is a wifi AP just 6 feet way from the one in my basement I’m having the most trouble with.

The only thing I thought of is they might not be connecting to that strong AP. Is there a way to force them to connect on a specific wifi channel? I haven’t had time to look into that yet.

When it fires without your telling it to is the GPIO pin high? I wonder if that’s the problem, maybe it’s getting interference or something and it’s going high for a split second which tells it to turn on. If you can try to unplug that and see if you have the flickering issues (even though you can’t use the switch).

There really shouldn’t be a mostly work situation. :slight_smile: What firmware do you have installed? You should try to increase the log level and output it somewhere (mqtt) so when things happen you can see what the sonoff thinks is happening.

I kind of assumed that too but as I said I used a shielded cable to the switch.

And if it is the switch wiring causing the problem then I don’t really want to use them without wall switch operability.

How do increase the log level? Would that tell me if the gpio pin is set high or low?

I used kmanoz firmware. I think it is v1.01? Then I made some mods to it to get the wall switch to work. The mods I made are posted up thread.

The thing that doesn’t make sense is that I’ve used the exact same firmware (apart from changing the topic) on four different switches. Two of them work 99.9% of the time. One works 100% as long as the WiFi signal is strong enough. The other one works about 90%. But that other 10% is a problem.

If it is the wall switch then why would it be that when the WiFi signal goes away that they all become unstable?

Might be the firmware, I use https://github.com/arendst/Sonoff-Tasmota and I’ve never seen that before. Before you give up on the hardware I’d try different firmware and see if you can debug it. I don’t know anything about kmanoz, sorry.