Need help with AC voltage detection

Hello there! i installed the esphome software on a cheap “qs-wifi-s04-2c” and i have this problem, when i’m on the bench with a simple wire to test with the device correctly detects on and off states and it toggles without any problems the relay accordingly but when i try to install it into my light system it goes crazy and starts randomly changing the state. This is how i’m detecting the being button pressed:

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO13
      inverted: true
    id: button
    filters:
      - delayed_off: 100ms
    on_press:
      then:
        - light.toggle: light_1

it’s obvious i need some other filter then only “delayed_off” but i can’t find whitch one could fix my issue, home someone helps!

Hello and welcome to the forum. Please edit your post and format your pasted code as per point 11 here.

Hello sir, i fixed the code

How is the button connected?

Is it shorting 3.3V or ground to the GPIO when pressed?

The module (qs-wifi-s04-2c) has 220V ac voltage detection on the inside, maybe it has a simple resistor to drop down the 220v AC to friendly 3.3V so probably it pulls HIGH the GPIO when 220V is attached to the internal resistor

Then you need to enable the input pulldown resistor.

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO13
      inverted: true
      mode: INPUT_PULLDOWN
...ect

This is super weird…

binary_sensor.gpio: [source /config/esphome/lucesalotto.yaml:32]
  platform: gpio
  pin:  [source /config/esphome/lucesalotto.yaml:34]
    number: GPIO13
    inverted: True
    
    Unknown value 'INPUT_PULLDOWN', did you mean 'INPUT_PULLDOWN_16', 'INPUT_PULLUP', 'WAKEUP_PULLDOWN'?.
    mode: INPUT_PULLDOWN [source /config/esphome/lucesalotto.yaml:36]

Maybe the module doesn’t support PULLDOWN internal resistor?

Sorry. If it is esp8266 based use INPUT_PULLDOWN_16

INPUT_PULLDOWN is only for ESP32 devices.

Hold on sir, i was trying to OTA update the firmware on the device and looks like my entire home assistant istance crashed right after system update, i will wait for it to recover

Looks like this won’t work, i found this into the official esphome.io wiki:
image
as you can see it says (ONLY gpio 16)
Solution?
I will solder in my own pull down resistors

1 Like

I had a similar issue with a similar device.
Internally, my device has a resistor divider to the base of a transistor. This transistor pulls down the GPIO input.
Unfortunately, when the external switch is open, it seems that with such low current going into the pin, something in my house makes some voltage build up there, and the transistor ends up activating when it should not.
I tried a relatively large resistor between S1 and N, but this did not help at all.
The only thing that helped was a 100V zener diode in series with S1, “pointing out”, so that in order to activate the transistor, there needs to be more than 100V in that input.
So… S1 ----|>Z---- your switch.