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.
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.
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"
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 ?
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?