Hi this is my first post and I am new in home automation so please forgive me if I’m doing something wrong.
I have about 10 sonoffs in my network connected to my light switches with retain: false.
The pool pump works with yet another sonoff basic and it turns on 2h after sunrise and off 2h before sunset. To use energy from the solar panels I added automation to turn it off when yr weather cloud % is high.
The problem is that sometimes EMC or voltage spike (I haven’t figured it out yet) resets the sonoff after it switches the pull pump off. After quick reset sonoff uses its poweron state 3 and comes back ON, but home assistant already sent the OFF command and pump stays ON.
I figured that if I use retain: true in HA it will turn it off even if it restarts… great! BUT!!!
When I tried it I manually turned the pump off from HA interface and it worked.
When automation sent the POWER OFF command, it didn’t update the retain bit in HA so if I sonoff resets or subscribes to mqtt, HA switches it back ON!
I spoken to my friend who uses 4 channel sonoff and he’s having the same issue with sonoff restarting sometimes when relay switches OFF. I need to find the answer.
The one with sonoff resetting is on me. The temperamental retain flag…please help.
You dont say if your sonoffs are using Tasmota, but if they are, check out this video to see if your not having the same issue mentioned in it with retain
Unless this pump provides cooling for a nuclear reactor, it’s best if its fail-safe mode is OFF.
You still need to prevent the “EMC or voltage spikes” or whatever it is that’s resetting the Sonoff. It could just be it temporarily loses Wi-Fi and resets itself upon re-connection.
and now automation commands are retained. Thanks Pippyn.
I also changed the “poweronstate 0” as it toggled the power unnecessarily when unwanted reset occurred.
I use “powertonstate 3” on my light switches and now I’m asking myself if it’s right? Thanks 123
I’ve tried LC filter on sonoffs power supply to eliminate the sudden reset when switching the load OFF - no success.
Tried LC filter with MOV’s between L-N, N-E, N-E -no success.
I tried moving the slave relay (one that switches the power to the pump) away from the sonoff and it seems to work!
The problem is I need bigger enclosure for it.
Adding retain: true is inadvisable. It’s the root cause of many posts on this forum complaining about devices like lights and garage doors ‘magically’ activating themselves.
The rule of thumb is to use message retention for state topics. For example, the device (Sonoff) should publish its status with retain=true. Command topics should not be published with message retention. You may have noticed the default for all MQTT platforms is retain: false (and for good reason) so published commands are not retained by the broker.
The majority of people who do set retain: true for a switch, light, etc often do so because they:
Don’t understand the purpose of retain but true sounds better than false.
Don’t understand its purpose but use it because it seems to magically fix a problem they have elsewhere (and aren’t aware of the potential drawbacks).
Don’t paper over the problem with retain: true, find the root cause of the disconnnects and fix it.
I understand but how can I be sure that the pump will switch off if I have no power to the house at the time of the “off command” being sent when there was no power to the sonoff but HA server was functioning on battery backup?
I don’t understand. If the retain bit was 0 and it’s 4AM, no reason for the pump to be on, why it just kicked in for about 5seconds? I thought it’s something else but yeah… It showed up in the HA history.
I will try the automation instead like DavidFW1960 suggested.
This is an odd example. Without any power, the pump will be … off. The Home Assistant system (running on batteries) will fail to communicate not only with the pump but with all AC-powered devices.
If you do not use retain: true, when power is restored the pump will remain off (fail-safe mode is off). Only reason it would not be off is if you programmed the Sonoff to restore the previous state on startup (that’s inadvisable).
If you do use retain:true, when power is restored the pump will turn on even if you programmed the Sonoff to remain off on startup.
I suggest:
Sonoff is programmed to leave the pump off on startup
Pump switch in Home Assistant uses retain:false.
If you want to the pump to restart after a power-failure, I would create:
binary_sensor.powerfail to detect when the host server is running on battery-backup. When its state is on then it means there’s a power-failure in effect.
an automation that is triggered when the power-failure is over. So it’s triggered when the state of binary_sensor.powerfail changes from: 'on' (power-failure) to: 'on (no power-failure). Upon being triggered, it checks if the current time is within the pump’s operating schedule. If it is, it calls the switch.turn_on service to start switch.pump.
This is the safe way of managing the pump. It does not rely on any default behavior (like the Sonoff activating itself on startup) or using a command retained by the MQTT broker. The pump’s fail-safe mode is always off and Home Assistant controls when it should be on.
You can just check for when the switch state changes to available and then check if it’s supposed to be on or off and action it. It’s a simple automation to do this. A binary sensor is not required.
I don’t disagree with that approach. Plus it is specific to the pump switch’s status unlike the power-failure sensor. Using both provides even more options for handling the failure.
For example, assuming:
no power-failure in effect
pump switch is unavailable
I know the problem is specific to the pump. Because power is available, the automation can proceed to notify me that the pump failed. When the pump switch becomes available it can decide if it ought to be restarted.
Assuming:
power-failure in effect
pump switch is unavailable
Now no notification can be sent and the automation waits for the switch to become available again before it should be restarted.
Assuming:
power-failure in effect
pump switch is available
This scenario implies someone shutoff the circuit-breaker to the host server. Other devices, like the pump switch, are still available so it’s possible to send a notification message.
The power-failure sensor can also be used to manage devices that don’t have an availability topic.
The more I know, the more I have to learn.
I just had my first baby so there was no time to experiment but I’ve noticed that the way I left it works pretty well.
For that reason, I decided to move all my automations to Node-RED and I’m lovin’ it. Pump still works on HA automation with no issues so… happy days.