Adding a touch switch to Sonoff Mini

Hi,
I tried to add “Heltec Automation Capacitance Touch Switch Module” to Sonoff Mini running esphome.
heltec_touch_switch
I was doing it based on this article:

There’s three pins on Heltec: 3.3V, GND and OUT,


First I tried to connect:
3.3V on switch to 3.3V on sonoff mini
GND on switch to GND close to 3.3V
OUT on switch to GPIO0
gpio-mini
but this does not work,
so I changed:
3.3V remains same
GND on switch goes to GND close to GPIO4
OUT on switch goes to GPIO4
But still nothing.
In both cases when I touch switch it lights up but nothing happended with sononff
(either on “switch” side or in log).
my config (last part) is:

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO4
      mode: INPUT_PULLUP
      inverted: True
    name: "przycisk oswietlenie spizarnia"
    on_press:
      - switch.toggle: przekaznik_oswietlenie_spizarnia

switch:
  - platform: gpio
    name: "przekaznik oswietlenie spizarnia"
    pin: GPIO12
    id: przekaznik_oswietlenie_spizarnia

seems there something wrong either with code or switch connection?
before I used ordinary two state switch and everything was working OK.
Can someone help me with that?
Regards
Maciek

Perhaps because you are using a different gpio in your code to the one you have it wired to.

sorry - I made mistake - of course I set both in code and physical contact for OUT - GPIO4
I corrected original post.

Does it work now?

No - error Was only in post - both were GPIO4
the switch lights on when I close my finger, but nothing happends.

If no one has a clue what can I done wrong,
I will remove one sonoff basic from environment and make test on that
I hope difference between sonoff basic and sonoff mini should not be a problem
or that I was using esphome instead of tasmota neither.

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?