Binary Sensor and switch on the same pin

I have a dehumidifier that I want to control from Home Assistant while still being able to use the buttons. For instance if I turn it on/off it should show on/off in Home Assistant and vice versa. I soldered two leads to the button and hooked it up to my d1 mini

This is what I currently have down:

  - platform: gpio
    pin: D5
    name: "Living Room Dehumidifier"
    id: dehumidifier1
  - platform: gpio
    name: "Living Room Dehumidifier"
      number: D5
      mode: INPUT_PULLUP
      - then:
        - switch.turn_on: dehumidifier1
      - then:
        - switch.turn_off: dehumidifier1

Unfortunately, I know what I put wrote in esphome isn’t correct. what would be the best way to go about this?

I do not think you can use the same pin as a switch and a binary sensor.

Correct. Can’t use same pin for both. What you’re asking to do is quite complicated. Without knowing some very specific electronic details of your dehumidifier, My suggestions are going to be pretty abstract:

For control, use a relay with contacts connected to either side of the dehumidifier power button (assuming it is a momentary button). This electrically isolates esphome from the dehumidifier circuitry - which you definitely want.

For detection, I’d setup something similarly isolated. Maybe a LDR places next to the dehumidifier power LED that esphome can use to detect if power LED is on.

As I said, complicated.

You need to have the switch output of your D1mini connected across the switch contact of the dehumidifier and then use a separate input pin on the D1mini to read the status from the dehumidifier to give you the binary sensor. You should be able to get the status from somewhere on that circuit board (I was hoping to see a generic ‘ON’ LED but dont see that…)

What voltage is the dehumidifier circuit board running? You may need to do all of this using:

  1. a relay on the D1mini output to simulate the button press
  2. a voltage divider resistor circuit to take the status back to the D1mini

Or some sort of opto coupler.

1 Like

That circuit is likely also just reading the state of the button, therefore it isn’t putting out any on/off signal on that node. So your idea requires a second wire, if you will, to get the on/off state from the circuit.

As mentioned above, LED’s are a good target for getting a binary signal, since they are always safe low voltage. Other parts of that circuit may carry mains voltage… stay away from probing parts that look dangerous (thicker traces, bulky caps and transformers, isolation slots, etc…). Usually parts attached to thin and closely spaced pcb traces are safe to probe. Either way, some probing needs to be done to find a suitable on/off signal.

A relay is likely needed to operate the button. That’s the second wire. If your really, I mean really really, can’t use a second pin, you’ll have to DIY some rather complicated 1-wire method… and that’s a far stretch for DIY… certainly not something you’ll get a schematic for by asking here.

1 Like

Thanks everyone. Unfortunately, there is no simple on/off led just the digit display. I’m going to try looking at the connector for on/off signal with a multimeter.

What about using a power monitor to detect if it is on ?

You can use an esp01 with relay to simulate pushing the button ?