Adding a touch switch to Sonoff Mini

when I do it on Sonoff Basic V2 it’s working OK
touch switch is connected to:
GPIO14 Optional Sensor (C1 Pin 5)
which pin should I use on sonoff mini?
GPIO0
GPIO1
GPIO2
GPIO3
GPIO4
GPIO16
which one should be similar to GPIO14 on Sonoff Basic (c1 pin 5)?

You may need a pull-up resistor at the GPIO pin unless the pull-up is already handled by the Sonoff?

what resistance and to which pin it should be connected? 3.3v or GND?

Pull-up would be between 3.3v and GPIO. Try 4.7k ohm or similar.

I will try that and let you know

Reading the doc, it’s a little confusing, but it looks like it outputs 3.3v on touch.

Therefore you would need to add in a pull-down resistor and not pull-up. Try putting the 4.7k ohm resistor between GND and GPIO instead.

you were right - It works now - thank you very much
but one more question:
If i touch it too slow it switches on and off
how to set the code it will read next change state in let’s say two seconds?
(i don’t know it I explained it correctly)

1 Like

Great!
Then you need a debounce filter to fix this:

I have added filter to code

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO4
      mode: INPUT_PULLUP
      inverted: True
    filters:
    - debounce: 0.3s
    name: "przycisk oswietlenie test"
    on_state:
      - switch.toggle: przekaznik_oswietlenie_test

but validation says:

INFO Reading configuration /config/esphome/sonoff-mini-test.yaml...
Failed config

binary_sensor.gpio: [source /config/esphome/sonoff-mini-test.yaml:30]
  platform: gpio
  pin: 
    number: GPIO4
    mode: INPUT_PULLUP
    inverted: True
  filters: 
    - 
      Unable to find filter with the name 'debounce'.
      debounce: 0.3s
  name: przycisk oswietlenie test
  on_state: 
    - switch.toggle: przekaznik_oswietlenie_test

Your indentation is wrong.

found that in binary sensor debouce does not exist:

tried

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO4
      mode: INPUT_PULLUP
      inverted: True
    name: "przycisk oswietlenie test"
    on_state:
      - switch.toggle: przekaznik_oswietlenie_test
    filters:
      - delayed_on_off: 100ms

but it does work as same as debounce
maybe It was removed?

Maybe on reflection it never existed for binary_sensor. See Binary Sensor Component — ESPHome

is there any way to omit this?

To omit what?

to omit debouncing.
If I touch the switch it sometime switch on and off again rapidly.
How to do that It will change the state once - from off to on or vice versa - and “sleep” one second before reading next state?

By using the config I pointed you to.

You mean this:
Binary sensor filters
If yes which filter should I use?

Well 2 of them mention they are useful for debouncing push buttons and 1 useful for debouncing binary switches, so have a play with those.

Or perhaps even read the docs for the component you are using GPIO Binary Sensor — ESPHome

thank you - I will try both

i changed code to this:

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO4
      inverted: True
    name: "przycisk oswietlenie test"
    on_press:
      - switch.toggle: przekaznik_oswietlenie_test

and I don’t need to use any filters anymore
now switch works as expected
thank you very much for your support

1 Like