Simulate touch (capacitive) button from nodemcu

Well it’s a 5V servo and the ESP logic is 3.3v so there’s that to contend with. A transistor driver to shift the 3v to 5V would do.

You’ve got the frequency right (50Hz) but the duty cycle of your servo can only vary from 5% to 10% for 0 to 180 degrees rotation. So you will need to specify a minimum and maximum.

servo:
  - id: washing_machine_mcu
    output: pwm_output
    min_level: 5%
    max_level: 10%

Not sure what you’re trying to do with the lambda function.

1 Like

Thanks mate, I don’t know what I was doing, I was copying someone else’s sketch. lol

For future reference and as a closure to this thread.

Here’s what I ended up with and I love it!

esphome:
  name: washing_machine
  platform: ESP8266
  board: nodemcuv2

api:

ota:

output:
# SERVO
- platform: esp8266_pwm
  id: pwm_output
  frequency: 50Hz
  pin: D8

servo:
- id: servo2
  output: pwm_output
  min_level: 5%
  idle_level: 7.4% 
  max_level: 10%

  - platform: template
    icon: "mdi:washing-machine"
    name: "Washing Machine Servo"
    turn_on_action:
    - output.set_level:
        id: pwm_output
        level: 10%
    - delay: 1000ms
    - output.set_level:
        id: pwm_output
        level: 7.5%

As for the capacitive part which was the main reason for this thread, the only thing that worked was a single wire touching the tap that then touches the START button on the washing machine that would simulate a finger press… The wire didn’t work without placing a 20c coin on the button to have more surface area (closer to a finger)

Thank you for all your help and patience @tom_l

2 Likes

Glad you got a solution in the end. +1 for perseverence.

1 Like

Anything to get the wife approval factor! :smiley:

I have a Medifyair, MA-25. HEPA Air Cleaner. I wanted to automate it just by controlling the AC power to it. Unfortunately, it returns to an idle state when I cycle the power. You have touch the ON button to start it again. It seems like all new appliances are moving to capacitive touch switches.
I tried the ESPHOME method (OUTPUT_OPEN_DRAIN) with no success. I soldered along wire to a copper penny and taped it over the ON/OFF button. When I connect the end of the wire to ground, nothing happens. I think that the latest capacitive switch measure the change in mutual capacitance between transmitter and receiver plates within the switch. Sliding a grounded penny over the button using a linear servo motor might work but I would prefer an electronic rather than mechanical solution. I might have to open the MA-25 and bypass the controls with wire so the fan is always ON. I may destroy the unit in the process.
It has been awhile since this post was created. Does anyone have a solution?

@GrahamS I’m in the same situation, turning ON a dehumidifier using a controllable “smart finger” :slight_smile: I have a esp8266, do you solved your problem in any way?

I took my MA-25 (not MH-25) apart and installed an ESP32 and power supply in the empty space under the top control panel. ( I had wanted to have a manual override scheme but I shorted the motor feedback signal to ground which killed to control panel. I did not have an oscilloscope to see what was going on. I used some temporary ESP32 code to measure the frequency of the PWM signal to the motor. ) I disconnected the control panel cable and connected the motor PWM control signal to the ESP through an NPN transistor with a pullup.
Note that a ESP8266 cannot be used because of the 10 KHz PWM requirement.

From Home Assistant I can now turn the fan ON and OFF as well as control the speed over a continuous range. I turn the fan ON at 40% speed for 1 hour after the heat or cooling comes ON.
I accumulate the fan ON time, scaled with speed, to determine when the filter need changing.

What follows is the relevant ESPHome code that I used:

esphome:
  name: hepafilter
  platform: ESP32
  board: nodemcu-32s
...
# Measured 10KHz on MA-25 PWM pin
# Connected to 2N3904 NPN BJT with a 4K7 resistor to base
# and 470 ohm pullup resistor on collector (output PWM signal).
output:
  - platform: ledc
    pin: GPIO33
    inverted: true
    frequency: 10000 Hz
    id: hepa_fan_pwm

fan:
  - platform: speed
    output: hepa_fan_pwm
    name: "Hepa Filter Fan"

# Used to measure frequency of MA-25 PWM pin
# Used resistor divider to tolerate 5V signal.
# Series 1K8 and 2K2 resistor to GND.
# Measured frequency up to 25KHz.
# Limited by overflow of ESP32 16 bit counter.
#sensor:
#  - platform: pulse_counter
#    pin: GPIO27
#    internal_filter: 1 us
#    unit_of_measurement: 'Hz'
#    name: 'Hepa Filter Fan Speed'
#    update_interval: 1 s
#    filters:
#      - multiply: 0.01667 # Convert to pulses/sec ie Hz 
#      - throttle_average: 60s
1 Like

Hi, I’m looking for something similar. Is my understanding correct that you connected a wire to the tap (eg. Ground) which is pressed by a servo motor to a coin which you attached to the capacitive button? Can you share a picture please?:grinning:

I’ve recently bought a ikea OBEGRÄNSAD clock that has a circle light on the back and you can turn it on or off only by pressing the touch sensor on the top (and it’s very inconvenient if you append the clock very high).
I’ve tried using a wire connected to a gpio pin on my esp32 and control it with the gpio switch function (platform: gpio) but with no luck…the sensor seems to register only the finger touch, if I try with a capacitive pen it doesn’t work.
Has anyone succeed in this kind of automation?

I too stumbled on this thread when trying to achieve a similar thing: be able to toggle power to a small touch controlled humidifier (retaining original manual touch function)

I have next to 0 knowledge/experience with electronics, so please take my instructions with a spoonful of salt. Nevertheless, I got it working.

I tried the original OUTPUT_OPEN_DRAIN suggestion, plus a combination of different coil wire lengths and placements, to no avail. It would either have no effect, or seemingly keep the touch sensor in “constant touch” mode.

What ended up working for me was to use a transistor from the wire coil to ground, and trigger it with a basic output pin from esp8266. This output can then be used from a button template, that toggles the output, waits 300ms and toggles it again.

The wire coil itself is very likely application specific, so hard to say something that would work for every use case, but I found it important that it is not in direct contact with the original capacitive coil, so I have a layer of office tape in between. Same goes for the touch activation time. The microcontroller from this humidifier is a Holtek BS84B08C.

Anyway, here is a bad picture of the whole thing. That single wire from the pcb with the original coils (and the microcontroller) to pin D5 is just to read the state. The D1 mini is being powered by a simple DC-DC buck converter.

1 Like

Could you tell me, which transistor you used and also the values for the resistors maybe?

2N3904, 100K

And here is the relevant bit of the ESP code as well:

switch:
  - platform: gpio
    pin:
      number: D2
      mode:
        output: true
    id: output_vcc
    device_class: switch
    restore_mode: RESTORE_DEFAULT_OFF

button:
  - platform: template
    name: "Cycle mode"
    on_press:
      then:
        - switch.toggle: output_vcc
        - delay: 300ms
        - switch.toggle: output_vcc
2 Likes

Ah so great, that also works on my model. Many thanks!

I have a lamp with touch to turn on/off and want to automate the lamp (and a smartplug will not work as it will stay off). I have used your ESP code but without success. I have GPIO5 (D1 on a D1 mini) directly wired to the metal of the touch button. Am I missing something?

Thanks!

Did you read my message above (and the rest of the thread)?

Triggering capacitive touch will vary from case to case, but connecting directly to the metal is something that I can bet won’t work in most of them, as it will mess with the baseline capacitance values that the appliance’s micro controller is expecting.

Also, my code is meant to work with a transistor. If you want to try to connect directly, you probably want the OUTPUT_OPEN_DRAIN method that was described in the beginning of this thread.

Cheers

Hi Jonybat,

Thanks for the quick reply. I did indeed read the thread top-down but probably lack the know-how to understand what needs to happen for my case. I also tried the output_open_drain mode without success. Is there a wire drawing (with transistor) that I can replicate? In the meantime, let me do some more testing.

Cheers!

Hey, did you have any luck getting it working? Here is a quick diagram, hope it helps:
circuit

I tried this setup following the wiring diagram and it looks like the coil wrapped around the plastic part is actually preventing touch presses now. And the code does not trigger in esphome.

It’s interesting how much of an unsolved problem this is considering we’ve had touch sensors for decades.