Analogue smart DoorBell

So i got a ESP32 and a 5A single phase sensor based on this

but his code is purly arduino, which of course i figured out once i bought everything.
but i still home to get it working.
I just have not idea how to get any output from the Sensor to HA.

I have this code which i dont think works, so i stopped using it. Also seems Pin34 cant give output, just saw that today on ESPhome doc.

#include "esphome.h"

class doorBellComponent : public Component
{
public:
	const int doorbell = 34;            //current sensor connected to pin 34 and ground
	int senseDoorbell = 0;              //variable to hold doorbell sensor reading
	int debounce = 1000;                //only allow one DingDong per second
	unsigned long currentMillis = 0;    //how many milliseconds since the Arduino booted
	unsigned long prevRing = 0;         //The last time the doorbell rang
	
	doorBellComponent(esphome::template_::TemplateNumber*&_prevRing)
	{
		_prevRing->add_on_state_callback([this](float newprevRing)
									  { prevRing = newprevRing; });
	}
	
	void setup() {
	  Serial.begin(9600);
	  pinMode(doorbell, INPUT);
	  Serial.println("DoorBellDuino Booted");
	}

	void loop() 
	{
	  //get the time since the arduino booted
	  currentMillis = millis();
	  //only check the doorbell if it hasn't been hit in the last second
	  if(currentMillis - prevRing >= debounce){
		senseDoorbell = analogRead(doorbell);  //read the doorbell sensor
		if(senseDoorbell > 50){                //mine read between 0 and 7 with no current and 200 with it.  50 seemed to be safe.
		  Serial.println("DingDong");
		  prevRing = currentMillis;            //engage debounce mode!
		}
	  }
	}
		
};

Also, i found this, but since its a device all in one, again i dont get any output from my Sensor

So i need to do a adruino component to get that working ?
Like if i can get any output i would probably just figure out all the automation in HA instead of doing a bug ESPhome script, but hey if anyone has any help to give, would be greatly appreciated.

You didn’t find @frenck ’s doorbell?

He has more details on his website, but it appears to be down atm :thinking:

Thanks for the reply, but he directly has a button, really not what i have, my device is in the chime and looking at power changes in the cables when the button is being pushed.
So no custom components, im like 85% sure since i have this
https://www.aliexpress.com/item/4000434009123.html
my reall issy is to do the Custom component the right way.

Does it work with magnetic coil?
if so…just use a reed contact?

No idea if it would work, but it would mean using completly different hardware, and i already have the ESP32 and the PowerSensor.

Also, i dont think i have an electory magnet doorbell, the chimes in the pictues look all simpler then mine

i should have bought this :smiley:

I think my issue is really about converting this .ino

// https://youtube.com/AnotherMaker
// https://github.com/mudmin/AnotherMaker
const int doorbell = 34;            //current sensor connected to pin 34 and ground
int senseDoorbell = 0;              //variable to hold doorbell sensor reading
int debounce = 1000;                //only allow one DingDong per second
unsigned long currentMillis = 0;    //how many milliseconds since the Arduino booted
unsigned long prevRing = 0;         //The last time the doorbell rang

void setup() {
  Serial.begin(9600);
  pinMode(doorbell, INPUT);
  Serial.println("DoorBellDuino Booted");
}

void loop() {
  //get the time since the arduino booted
  currentMillis = millis();
  //only check the doorbell if it hasn't been hit in the last second
  if(currentMillis - prevRing >= debounce){
    senseDoorbell = analogRead(doorbell);  //read the doorbell sensor
    if(senseDoorbell > 50){                //mine read between 0 and 7 with no current and 200 with it.  50 seemed to be safe.
      Serial.println("DingDong");
      prevRing = currentMillis;            //engage debounce mode!
    }
  }
}

to ESPhome .h component

#include "esphome.h"

class doorBellComponent : public Component, public Sensor
{
public:
	const int doorbell = 33;            //current sensor connected to pin 34 and ground
	int senseDoorbell = 0;              //variable to hold doorbell sensor reading
	int debounce = 1000;                //only allow one DingDong per second
	unsigned long currentMillis = 0;    //how many milliseconds since the Arduino booted
	unsigned long prevRing = 0;         //The last time the doorbell rang
	
	doorBellComponent() {}

	void setup() {
	  Serial.begin(9600);
	  pinMode(doorbell, INPUT);
	  Serial.println("DoorBellDuino Booted");
	}

	void loop() 
	{
	  //get the time since the arduino booted
	  currentMillis = millis();
	  //only check the doorbell if it hasn't been hit in the last second
	  if(currentMillis - prevRing >= debounce){
		senseDoorbell = analogRead(doorbell);  //read the doorbell sensor
		if(senseDoorbell > 50){                //mine read between 0 and 7 with no current and 200 with it.  50 seemed to be safe.
		  Serial.println("DingDong");
		  prevRing = currentMillis;            //engage debounce mode!
		}
	  }
	}
		
};

I think the issue is probably with

doorBellComponent() {}

then my yaml config for this is simply

  - platform: custom
    lambda: |-
      auto Doorbell = new doorBellComponent();
      App.register_component(Doorbell);
      return {Doorbell};
    sensors:
        name: "Doorbell"

Or you could just use this core ESPHome component:

Then use a threshold binary sensor that turns on when the current is above a certain level.

Will try, i seem to get a reading now, got to set it to update more often the 60s to see the change with the doorbell ringing.

Nice got it to trigger, but had to spam the doorbell because the adc is on a timer.
any way to get it to simply trigger when more the X power without being on a timer ?

Share your config.

Will do has soon has its all set.
Working on the automation right now.

Its weardly not triggering each time not sure why.

But here is what i got

ESP Home YAML

text_sensor:
  - platform: version
    name: Doorbell ESPHome Version
  - platform: wifi_info
    ip_address:
      name: Doorbell IP
    ssid:
      name: Doorbell SSID
    bssid:
      name: Doorbell BSSID
 
sensor:
  - platform: uptime
    name: Doorbell Uptime
  - platform: wifi_signal
    name: Doorbell WiFi Signal
    update_interval: 60s
  - platform: adc
    pin: 33
    id: doorbell_adc_sensor
    update_interval: 0.1s

switch:
  - platform: restart
    name: "Doorbell Restart"

binary_sensor:
  - platform: analog_threshold
    name: "Status Doorbell"
    sensor_id: doorbell_adc_sensor
    threshold: 0.08

i would love to find a way to not need to monitor the adc update interval but hey, thats where im at.
automation is nothing right now just notifies each time its set to on and it can be spammed.
So still need to find how to get it to detect each time and then il put conditions to not be spammed.
Ultimatly it will trigger a camera too.

A polling interval of 0.1s is quite fast but not ridiculous. Especially as the ESP is doing little else.
Most people would press a doorbell for at least a second so you could up the polling time to 0.25s if you want.

If you watch the adc sensor in the serial debug log how noisy is the signal when the button is pressed or not?

ill have too look how to enable debug, cause even now its not detecting each time

Go the the ESPHome addon, open the web UI, find your device and click on “Logs”.