Anyone using a new version of Sonoff Basic notice that they are unstable?

I’m using a Sonoff Basic RF which is the updated version of the old Sonoff Basic with the wires instead of solder traces. I have it programmed with ESPHome to be used with a wall switch on the internal GPIO header. Since the new version doesn’t expose GPIO14 on the header I believe the recommendation is to use GPIO3 (RX pin) to control the toggle with the external wall switch.

The problem I’m having is that the Sonoff is pretty unstable and the relay occasionally chatters. At first it only happened every few hours/days and I would get one or two chatters and it would be done. starting a couple of days ago it started to constantly do it to the point the light that is connected to was unusable.

The strange thing is that it only happens when the switch that is connected to the GPIO is open (connected between GPIO3 & GND). If the switch is closed (on) then there is no more chatter. So it definitely sounds like an induced noise problem. But, in order to try to prevent any noise causing the relay to toggle I bumped up the delay (debounce) for the GPIO to a full second and it still chattered like crazy when the switch was open. But I know the delay is working because when I use the switch to toggle the output it waits the full second before the relay toggles.

So I thought I had a bad Sonoff. I swapped it out with a spare (new version) that I had and it does exactly the same thing. So I don’t think the Sonoff is bad.

Then I swapped out the new Sonoff with an older version that uses GPIO14 for the switch input and so far everything is back to being stable again with the standard 200ms debounce delay.

Has anyone had any similar experiences with the new version Sonoff Basics? or is there any suggestions to get these to work with a wall switch?

Here is the relevant portion of the ESHome code for the switch input:

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    id: button
    on_press:
      - switch.toggle: relay_template
  - platform: gpio
    pin:
      number: GPIO3 # (RX Pin) - if using the newer Sonoff Basic with Wires instead of traces
      mode: INPUT_PULLUP
    id: wall_switch
    filters:
      - delayed_on: 200ms
      - delayed_off: 200ms
    on_press:
      - switch.toggle: relay_template
    on_release:
      - switch.toggle: relay_template
    on_multi_click:
    - timing:
        - ON for at most 0.5s
        - OFF for at most 0.5s
        - ON for at most 0.5s
        - OFF for at most 0.5s
        - ON for at most 0.5s
        - OFF for at most 0.5s
        - ON for at most 0.5s
        - OFF for at least 0.2s
      then:
        - switch.turn_on: restart_sonoff

Did the chattering slow down after this?

tic…tic…tic… or tictic…tictic…tictic…rather than tictcitctic?

If so, then it is still picking up noise and maybe a 0.1uF ceramic capacitor from the gpio to ground would help.

If not… then it could be a bad power supply design issue.

Also have a close look at the board. Any obviously missing components? (solder mask and pads but no component).

I’ve seen a couple of RS232 converters that came from a bad batch that missed a critical component. Maybe the pick and place machine wasn’t programmed correctly?

no. It wasn’t ever an even tic…tic…tic. off & on

It was more of a tic.tic..............tic....tic..tic..................tic kind of thing.

And since it did it on two of them installed in the same location I’m thinking it’s a design issue. maybe that circuit on the new one is more susceptible to noise than the older style. But TBH, they aren’t really designed to be used with a wall switch so I can’t really fault them for me trying to use it in that way.

I know that even the older style had some serious issues with noise when I installed some cheap LED replacements for flourescent tubes.

I don’t have them in front of me right now but I can check later for any “missing parts”.

And once I get some I can try the cap between GPIO & grd to see if that clears things up.

I guess I just need to start buying Shelly’s for wall switch relays and be done with it. Or maybe try out the new Sonoff Mini’s.

I recently got my first Shelly. A Shelly EM to monitor my two mains power meters. Other than having to interrogate the energy totals via restful sensors rather than MQTT I cant fault it. Nice bit of kit. Took ages to arrive though.

I’ve got four other Shelly 1’s already. They really are great devices. My only issue is that I bought a bunch of Sonoffs before the Shelly’s came out so I’m trying to get my use out of them. And the Sonoff’s are cheaper. But since the Shelly’s seem to work better then they are worth the extra.

I’m seriously considering one of the Shelly EM’s myself. I’m just needing to justify the cost compared to its usefulness.

I’m using it to collect a year’s worth of energy data to help me size a solar (and possibly battery) system. So far I’ve been surprised. I thought a larger portion of my energy use would have been a night (probably will be next winter):

That’s interesting.

I think I’d get more use out of something like that using it to measure individual branch circuits than measuring the main incoming line. My electric company already does a very good job of keeping track of my total usage every month. :heavy_dollar_sign::heavy_dollar_sign::heavy_dollar_sign: :wink:

I’d be keen to see your code for doing those calculations to get day / night figures etc. Do you have that posted on Github or elsewhere on this forum?

I do monitor a few individual devices.

For branch circuits you’d be better off with an ESP32 and a bunch of current transformers. Too many Shelly EMs otherwise. The ESP has 7 analogue inputs.

The cost calculations are just to prevent bill shock at the end of the quarter. :grimacing: I’m more interested in the day/night L&P vs heating split.

I don’t but I’ll write it up later tonight. Right in the middle of reorganising a bunch of cards and views at the moment.

@finity

Or an iotawatt. I have one waiting to be installed next weekend…I just haven’t had any spare time lately.

1 Like

Ah! That’s the one I couldn’t think of. All I could remember was the Open Energy Monitor.

Looks neat but kind of pricey for non-commercial use at ~$200 for a starter kit.

Just to update this thread with additional information…

I put a different original version (with the solder traces) Sonoff Basic in its place and at first it seemed ok but as time has gone on the random switching has gotten worse and worse even with that old style.

I’m not sure what could be happening. It’s the only place that I’ve used three different Sonoffs & I get the same results.

here is the log file I generated so I know it’s definitely the GPIO14 connected wall switch that is causing the switching:

[17:59:09][D][binary_sensor:033]: 'wall_switch': Sending state OFF
[17:59:09][D][switch:029]: 'Kitchen Sink Lights' Toggling ON.
[17:59:09][D][light:261]: 'status_led' Setting:
[17:59:09][D][light:270]:   State: ON
[17:59:09][D][light:300]:   Transition Length: 0.0s
[17:59:09][D][switch:021]: 'relay' Turning ON.
[17:59:09][D][switch:045]: 'relay': Sending state ON
[17:59:09][D][switch:045]: 'Kitchen Sink Lights': Sending state ON
[17:59:09][D][binary_sensor:033]: 'wall_switch': Sending state ON
[17:59:09][D][switch:029]: 'Kitchen Sink Lights' Toggling OFF.
[17:59:09][D][light:261]: 'status_led' Setting:
[17:59:09][D][light:270]:   State: OFF
[17:59:09][D][light:300]:   Transition Length: 0.0s
[17:59:09][D][switch:025]: 'relay' Turning OFF.
[17:59:09][D][switch:045]: 'relay': Sending state OFF
[17:59:09][D][switch:045]: 'Kitchen Sink Lights': Sending state OFF
.
.
[18:08:38][D][binary_sensor:033]: 'wall_switch': Sending state OFF
[18:08:38][D][switch:029]: 'Kitchen Sink Lights' Toggling ON.
[18:08:38][D][light:261]: 'status_led' Setting:
[18:08:38][D][light:270]:   State: ON
[18:08:38][D][light:300]:   Transition Length: 0.0s
[18:08:38][D][switch:021]: 'relay' Turning ON.
[18:08:38][D][switch:045]: 'relay': Sending state ON
[18:08:39][D][switch:045]: 'Kitchen Sink Lights': Sending state ON
[18:08:39][D][binary_sensor:033]: 'wall_switch': Sending state ON
[18:08:39][D][switch:029]: 'Kitchen Sink Lights' Toggling OFF.
[18:08:39][D][light:261]: 'status_led' Setting:
[18:08:39][D][light:270]:   State: OFF
[18:08:39][D][light:300]:   Transition Length: 0.0s
[18:08:39][D][switch:025]: 'relay' Turning OFF.
[18:08:39][D][switch:045]: 'relay': Sending state OFF
[18:08:39][D][switch:045]: 'Kitchen Sink Lights': Sending state OFF
[18:09:17][D][sensor:092]: 'Kitchen Sink Lights WiFi Signal Strength': Sending state -40.00000 dB with 0 decimals of accuracy
[18:10:17][D][sensor:092]: 'Kitchen Sink Lights WiFi Signal Strength': Sending state -40.00000 dB with 0 decimals of accuracy
[18:11:17][D][binary_sensor:033]: 'wall_switch': Sending state OFF
[18:11:17][D][switch:029]: 'Kitchen Sink Lights' Toggling ON.
[18:11:17][D][light:261]: 'status_led' Setting:
[18:11:17][D][light:270]:   State: ON
[18:11:17][D][light:300]:   Transition Length: 0.0s
[18:11:17][D][switch:021]: 'relay' Turning ON.
[18:11:17][D][switch:045]: 'relay': Sending state ON
[18:11:17][D][switch:045]: 'Kitchen Sink Lights': Sending state ON
[18:11:17][D][binary_sensor:033]: 'wall_switch': Sending state ON
[18:11:17][D][switch:029]: 'Kitchen Sink Lights' Toggling OFF.
[18:11:17][D][light:261]: 'status_led' Setting:
[18:11:17][D][light:270]:   State: OFF
[18:11:17][D][light:300]:   Transition Length: 0.0s
[18:11:17][D][switch:025]: 'relay' Turning OFF.
[18:11:17][D][switch:045]: 'relay': Sending state OFF
[18:11:17][D][switch:045]: 'Kitchen Sink Lights': Sending state OFF

I bumped the filter up to 500ms and it’s made literally no difference to the chattering as if the fiulter is being completely ignored.

But if I use the physical wall switch you can definitely tell the difference in the responses time.

Either I don’t know how to use the filter or…:man_shrugging:

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    id: button
    on_press:
      - switch.toggle: relay_template
  - platform: gpio
    pin:
      number: GPIO14
      mode: INPUT_PULLUP
    id: wall_switch
    filters:
      - delayed_on: 500ms
      - delayed_off: 500ms
    on_press:
      - switch.toggle: relay_template
    on_release:
      - switch.toggle: relay_template

I haven’t tried a capacitor (don’t have one to try) but I don’t get why the filter seems to be completely ignored except for when moving the physical switch.

Since this seems to be specific to ESPHome I’ll tag @OttoWinter to see if I can get any insight why the filter doesn’t seem to work.

Have you tried the resistor + capacitor filter on the button input?

Not yet.

I have a 10k resistor I had been using for some Sonoff’s in another location before I switched to ESPHome with the filter setting available (using an older firmware from KManOz) that I could try but I don’t have any caps laying around. I’ve even taken all of the resistors off of the other ones and they are pretty solid now with ESPHome running on them.

I still don’t get why the filter setting isn’t having any effect. I thought surely that if it works for delaying the toggle when I physically move the switch that it should also work for delaying the toggle when the device thinks the switch is being moved because of noise. I don’t get that at all.

Isn’t that the way the filter setting above is supposed to work?

I’m not trying to be stubborn about the other stuff (cap & resistor). I’ll try it when I get a chance (working 12 hour shifts this week…) but i’m just trying to figure out if I’m doing something wrong on the filter at the same time.

The filters might not work if the noise is continuous. They are meant for debouncing switch contacts where the noise only occurs for a brief period when the switch changes state.

Instead of delayed on you want something to tell you when the on pulse is longer than xxx ms.

Edit: actually, try the debounce filter instead of delayed on.

D’oh. :man_facepalming:

you’re right! that makes more sense.

Now I need to change to that in my code.

I’ll let you know how it goes.

I actually missed that edit originally and I was just coming back to ask another question and saw it.

Any idea where I can find any documentation on that? I’m not seeing it in the docs.

But also after looking at those docs some more i was going to say that I’m pretty sure that the delay_on & delay_off are the “something to tell you when the on pulse is longer than xxx ms” that you suggested:

delayed_on: When a signal ON is received, wait for the specified time period until publishing an ON state. If an OFF value is received while waiting, the ON action is discarded. Or in other words: Only send an ON value if the binary sensor has stayed ON for at least the specified time period. Useful for debouncing push buttons.

delayed_off: When a signal OFF is received, wait for the specified time period until publishing an OFF state. If an ON value is received while waiting, the OFF action is discarded. Or in other words: Only send an OFF value if the binary sensor has stayed OFF for at least the specified time period. Useful for debouncing push buttons.

Yeah you’re right and the debounce filter is actually a sensor filter not a binary sensor filter: https://esphome.io/components/sensor/index.html?highlight=debounce#sensor-filters