I added a Sonoff Powr3 to my Home Assistant network to control an immersion heater to turn on the hot water during our overnight low-tariff period.
It’s been working reliably up to this week - I’ve got a graph on my HA Console showing when it’s on and I show how much peak/off-peak energy it’s used.
I “think” it’s still working as I can see power being drawn overnight from my electricity meter … but HA isn’t reliably reading the power and voltage values? I poll the device for _voltage and _power every 10 seconds and poll device state every 60 seconds.
If I manually turn the switch on, the device state returns “on” and I can hear (!) the immersion heater warming up. But the voltage returns 1.25 volts and power returns 0.0 Watts.
I don’t know this. One thing you could try to rule out a hardware fault is to flash a custom firmware like esphome or tasmota. You should be able to save the present firmware with a serial connection so (in theory) you can restore that later.
I ended up deleting HACS and the Sonoff integration, updating all the HA software and other integrations then reinstalling HACS and Sonoff. I also changed the polling frequency to the POWR3 device.
It all seems to be working again today - overnight switching of the immersion heater worked and capturing the voltage and power readings worked.
Not sure which “change” has made the problem go away - I’m tempted to say it was the device polling frequency. I was polling volts and power every 10 seconds and device state every 60 seconds. I changed them all to poll every 60 seconds.
I use Node-RED to build my HA models - so afraid I don’t have any “code” to help. Node-RED has “poll state” nodes that connect to the Sonoff devices and I can easily adjust the polling frequency using parameters available in the poll state node.
However, I don’t think that was really the problem! My HA still stops being able to read data from the POWR3. I’ve just checked HA and can see that my Sonoff devices are all reporting that they are unavailable.
I’ve now restarted HA and HA has successfully reconnected to all the Sonoff devices including the POWR3.
So when I thought I’d fixed the problem by changing the polling frequency, it was actually resetting HA that made the problem go away when I put the change live.
I still don’t have a solution to “fix” the problem, I just reset HA when I notice it’s gone wrong. Maybe there is some smart way to do this - e.g. a keep-alive timer that automatically resets HA if it loses contact with the Sonoff devices?
For such a task like reading power and voltage values from a device it’s best to avoid polling at all and instead make use of push. It mostly not only puts less (unnecessary) traffic on the network but also allows the device to only update values when they are actually changing
So for example I have a Sonoff PowR2 are running with esphome and I set the update_frequency to 1s. Because I make use of the native api (local push) the values will only update when they are actually changing.
For example 4 hours without changed values
If polling would have been used instead a total of 14.400 (fourteen thousand four hundred) unnecessary poll requests would have been send across the network in this 4 hours