Sonoff Mini relay switching on and off fast

Hi,
I’ve installed 3 sonoff minis into my house which 2 are working fine but one of them the relay keeps switching on and off fast randomly. I dont think its anything to do with my esphome yaml as its the same and i used at my other ones.

Any sugestions?

esphome:
  name: outdoor_front_lights
  platform: ESP8266
  board: esp8285

wifi:
  ssid: ""
  password: ""

# Enable logging
logger:
# Enable Home Assistant API
api:

ota:

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO4
      mode: INPUT_PULLUP
      inverted: true
    name: "Carport Lights"
    on_state:
      - switch.toggle: relay
switch:
  - platform: gpio
    name: "Carport Lights"
    pin: GPIO12
    id: relay
  
status_led:
  pin:
    number: GPIO13
    inverted: yes

Could be a dry solder joint.

This has just started happening to one of mine. It’s been installed and working fine for about a year, but over the last few days has started turning itself on and off for a second every few minutes.

A dry electrolytic capacitor or degraded film capacitor can cause there to be increased ripple on the DC power supply to the point where this occurs. Just one possible reason. Check the wire terminal screws are still tight first.

1 Like

tom_I nailed it.

I also experienced this phenomenon, where a Sonoff Mini would switch on and off repeatedly (in a manner of seconds), then go quiet, then do it again, etc.

The solution is very simple! I put a capacitor between S1 and S2 (note: S1=GND, S2=GPIO4). That took care of the problem.

Side effect: when I used 100 uF (or was it nF, I forget), there was a delay when I switch manually. Reducing the capacitance to 22 uF resolved that as well.

Thanks but no. To fix the problem I suggested it “may be”, you would have had to put the capacitor across the DC power supply, not the GPIO.

What you have done is filter noise on the long cables to your GPIO. There are better low pass networks you can use for this than just a large capacitor. See Sonoff flickering with GPIO14 and GND connected - #2 by inutilis, this should help with your delay.

Well, my solution worked (so thank you), and with a small enough capacitor there was no delay.

The beauty of this solution is the simplicity of installation. I just stuck the capacitor between S1 and S2 (see pic, not to scale).

My theory is that the switch was flickering because of the noise between the two pins, and the capacitor filtered that out.

I had the same issue and arrived here to find some answers. I used same code (example from ESPhome) used on two mini switches and only one experienced issue. To fix it I have added a slight delay filter to the GPIO4.

# the 13 lines below toggle the main relay on command
  - platform: gpio
    name: relay_toggle
    internal: true  # hides relay toggle from HomeAssistant
    pin: GPIO04
    id: gpio_light_id
    filters: 
      - delayed_off: 200ms #slight delay to filter out line noise
    on_press:
      then:
        - light.toggle:
            id: light_id
    on_release:
      then:
        - light.toggle:
            id: light_id

Just a bit of an update to this. While the above code helped with quick on/off pulsing I was still getting a random on / off event here and there. I have bumped up the filter to 600ms for now, if that does not work I will need to try the capacitor and or 10k resistor trick as per this post