So the issue for me was the Wireless / AP I have now added in the below lines giving the unit a static ip and uploaded the code… have rebooted about 20 times in different locations around the house and been successful every time. not sure if this is clean code, by all means correct me
So i’ve set my IP’s on the Sonoff to static and will test that out see how I go.
The other thing I have noticed is if I reboot my HA and the Sonoff is ON, When HA all boots up and MQTT reconnects
I do not see the correct State of the Switch.
The only way I have found to workaround this is to add this code to the timedTasks()
if(digitalRead(RELAY) == LOW) {
mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "off").set_retain().set_qos(1));
Serial.println("Relay is OFF, Letting HA Know");
} else {
mqttClient.publish(MQTT::Publish(MQTT_TOPIC"/stat", "on").set_retain().set_qos(1));
Serial.println("Relay is ON, Letting HA Know");
}
It’s reporting back correctly now, seems strange that no one else has had this issue?
Another small quirk with the firmware for those that use the physical button on the sonoff.
I have a couple hooked up to my bedside lamps and I flick them on thru HA web interface. When I go to bed I press the physical button to turn them off. All good I thought until you loose wifi or if the MTQQ broker crashes then then after a reboot and reconnection to wifi and the broker then it pushes the last retained message which in my case is ON.
So the state is saved in the EEPROM but if you have “retain: true” which is the default on your configuration then it pushes that.
For the sonoffs that I don’t use the physical button I have no issues.
Just wanted to say thank you for the info in this thread. This was very simple to flash the Sonoffs, and they are working 100% perfectly with HA. I am a novice with the soldering iron but I got 6 of these up and running very quickly. An extremely cheap and solid solution!
That’s great and quite frankly what I set out to achieve when I first posted. It’s good to know that novices can pick this up fairly quickly and get a cheap working solution up and running fast.
As I have a sperate Access points to the firewall it seems to point at an issue with the AP’s. i am going to be adding some more sonoff today so will try adding it at the fw,
These are pretty neat. I’ve been messing mostly with the S20 outlet and the Sonoff Basic’s using Tasmota. I have them tied in fairly seamlessly with the rest of my Z-wave stuff, they seem to react as fast or faster.
There’s a couple US vendors on eBay that will sell the S20’s preflashed with a firmware you want for under $20, which I would have done before if I hadn’t drained several hours learning to flash them (first I reversed the RX/TX pin, then I kept forgetting to put them into flashing/programming mode).
yup it can be flashed. I purchased one and flashed Tasmota on it. The issue with the Tough is the design is meant for EU boxes and horizontal mounting. It does way US and does have mounting holes that line up.
The back won’t fit a single gang box,the set screw are really close the the box. Maybe a plastic box would be wider.