ESPHome voltage detection (integrate doorbell)

I’m trying to integrate my dumb doorbell into Home Assistant with ESPHome with a ESP32-WROOM-32U (DevKitC).

When the ‘gong’ (which is a loudspeaker) is rang, the power meter reports a value of up to 0.8v or so. The value on the speaker is reporting 0.4 watt. So all low values.

Wanted to use something like a binary_sensor, but that doesn’t change unless I (dis)connect the wires. I would have expected that 0.0v would be off, and > 0.0v would be on. But maybe there always is at least 0.01v on it?

Would like to have a switch in ESPHome to go on when it’s above 0.5v, is this (easily?) possibly?

Currently using ADC pin 34, and the other wire is connected to ground.

Connection:

Current config:

binary_sensor:
  - platform: gpio
    pin: GPIO34
    id: door_gong
    name: "Door Gong"

sensor:
  - platform: uptime
    name: "Esphome2 Uptime Sensor"
  - platform: adc
    name: "Gong Voltage"
    id: gong_voltage
    pin: 34
    update_interval: 0.5s
    internal: true

ESPHome log:
image

So ESPHome does detect a voltage, but binary_sensor never changes. This solution isn’t nice because it will generate logs every 0.5s.

There is may be a point on the doorbells board that gets pulled to ground or maybe high to run the tone generator. The high signal would be 4.5v at most since only powered by the 3 batteries.
Can you send a picture of the board?

Thanks for your reply Jason. Currently the voltage of the 3 batteries is around 3v, need to replace them, but don’t have them yet :slight_smile:

Back:

Front:

Front 2:

Front far:

A digital input requires some more voltage to trigger. If you get the signals from your log, it seems possible to do some templating described here:

especially the part:

      on_value_range:
        - above: 65.0
          then:
            - switch.turn_on: dehumidifier1
        - below: 50.0
          then:
            - switch.turn_off: dehumidifier1

seems like you want that. It would pbe placed in the ADC part and trigger the change of a binary sensor.

It could look something like this (no warranty, I did not check the code for functionality :wink: ):

binary_sensor:
  - platform: gpio
    pin: GPIO34
    id: door_gong
    name: "Door Gong"

sensor:
  - platform: uptime
    name: "Esphome2 Uptime Sensor"
  - platform: adc
    name: "Gong Voltage"
    id: gong_voltage
    pin: 34
    update_interval: 0.5s
    internal: true
      on_value_range:
        - above: 0.5
          then:
            - switch.turn_on: door_gong
        - below: 0.5
          then:
            - switch.turn_off: door_gong

Maybe you need to exchange your binary sensor with a template sensor…

Thanks CeeCee. I did look into them, but could figure out something that could work.

Hmm, I see what you are doing. Hopefully works, because the adc this is a little ‘special’ :slight_smile: First I thought that the switch.turn_on etc was from HA, but it looks like it is from ESPHome itself, which is good.

Well definitely look into this tonight!

Check the voltages on the pins marked IDEL and DAT.
That board appears to be the receiver added onto a wired doorbell board.
You should see it change when the button is pressed

Hmm, there is always like 0.2 - 0.8v on it. It also doesn’t really change or behave in any pattern.

I would like to let you know that the following did work, inspired by @CeeCee

binary_sensor:
  - platform: template
    name: "Doorbell Chime"
    id: doorbell_chime
    lambda: |-
      if (id(doorbell_chime_voltage).state > 0.1) {
        return true;
      } else {
        return false;
      }

sensor:
  - platform: uptime
    name: "Esphome2 Uptime Sensor"
  - platform: adc
    name: "Doorbell Chime Voltage"
    id: doorbell_chime_voltage
    pin: 34
    update_interval: 0.5s
    internal: true

Will probably replace the lambda with: return (id(doorbell_chime_voltage).state > 0.1)

Adjusted the voltage to 0.1v, because sometimes it does drop back before continuing back above 0.5v. Could find a way like a delayed_on or a delay in general. It would be nice if the switch was on for 5 seconds when once above 0.1v.

This is not the prettiest solution. I would still like to completely hide the logging that is generated, 4 lines a second, but couldn’t find a way.

2 Likes

I never used it, but ESPHome seems to have a solution for this:

Maybe this will help?

Your template will work but I personally prefer a slightly different style where you leave the lambda out and put the logic in the adc. This lets you play with delays etc. It will still generate logs I guess (I have the logger disabled personally).

Untested example:

 - platform: adc
   ...
   on_value_range:
     above: 0.1
     then:
     - if:
         condition:
           binary_sensor.is_off: doorbell_chime
         then:
         - binary_sensor.template.publish:
             id: doorbell_chime
             state: on
         - delay: 5s
         - binary_sensor.template.publish:
             id: doorbell_chime
             state: off

At my home, with a wired AC doorbell, I decided to instead put the ESP32 completely between the button line and the doorbell so there’s no direct connection. Instead:

  • the doorbell button line connects to small a 5V power supply,
  • the 5V from the power supply goes to the ESP32’s GPIO, which has a pulldown configured in esphome,
  • I have a cheap 4-channel aliexpress SSR module using 4 GPIOs and one output powers the doorbell.

This lets me have an esphome switch to ring the doorbell programatically (only used for alarms, ie. never) and have a template switch to silence the physical doorbell button.

Thanks! I’ve added this, and yes, it does work. Luckily I don’t have any other adc or sensor logging :slight_smile:

# Enable logging
logger:
  level: VERBOSE
  logs:
    adc: NONE
    sensor: NONE

Now it’s only :+1:
image

2 Likes

Thanks a ton all of you! :innocent:

The indentation of this on_value_range then if condition then then was challenging!

binary_sensor:
  - platform: template
    name: "Doorbell Chime"
    id: doorbell_chime

sensor:
  - platform: adc
    name: "Doorbell Chime Voltage"
    id: doorbell_chime_voltage
    pin: 34
    update_interval: 0.5s
    internal: true
    on_value_range:
      above: 0.1
      then:
        if:
          condition:
            binary_sensor.is_off: doorbell_chime
          then:
            - binary_sensor.template.publish:
                id: doorbell_chime
                state: on
            - delay: 5s
            - binary_sensor.template.publish:
                id: doorbell_chime
                state: off

image

1 Like