Hey,
I have been using my esp board with a ta17-03 amp meter. I have connected it to the wire of my doorbell to measure when the bell is pressed to send a signal to activate different actions.
I’ve used arduino to set this up and it works as it should (besides the time to time wifi drops or reboots)
But now i’ve been trying to add this with ESPhome into my hassio.
What i’ve figured out so far is that i can’t directly program this amp sensor in esphome (unless i’m wrong) and can only use it with adding it as a custom sensor. I’ve been trying for the last 2 days, to get sense out of the options, but I don’t have a clear line of progress in this matter.
Does someone have any suggestions on how to possibly get this to work?
The amp meter: TA17-03
This is the basic set-up:
const int doorbell = 32;
int senseDoorbell = 0;
int debounce = 3000;
unsigned long currentMillis = 0;
unsigned long prevRing = 0;
void setup() {
Serial.begin(9600);
pinMode(doorbell, INPUT);
}
void loop() {
currentMillis = millis();
if(currentMillis - prevRing >= debounce){
senseDoorbell = analogRead(doorbell);
if(senseDoorbell > 80){
Serial.println("dingdong");
prevRing = currentMillis;
}
}
}
This is the set-up as im using it right now, with mqtt notifcation, reboot and wifi connection:
#include <WiFi.h>
#include <PubSubClient.h>
#define DEVICE "DoorBellDuino"
const char* ssid = "*******";
const char* password = "*******";
const char* mqttServer = "192.168.1.10";
const int mqttPort = 1883;
const char* mqttUser = "mqtt";
const char* mqttPassword = "mqtt";
const int doorbell = 32; //current sensor connected to analog15 and ground
int senseDoorbell = 0; //variable to hold doorbell sensor reading
int debouncering = 5000; //only allow one DingDong per 5 seconds
int debounceping = 60000;
unsigned long currentMillis = 0; //how many milliseconds since the Arduino booted
unsigned long currentMillis2 = 0; //how many milliseconds since the Arduino booted
unsigned long prevring = 0; //The last time the doorbell rang
unsigned long prevping = 0; //The last time the doorbell rang
int request = 0; //A place to store incoming MQTT Requests for future use
char *cstring; //For parsing MQTT requests
boolean probe_sent = false;
WiFiClient espClient;
PubSubClient client(espClient);
void setup() {
Serial.begin(921600);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println("Connecting to WiFi..");
}
Serial.println("Connected to the WiFi network");
client.setServer(mqttServer, mqttPort);
while (!client.connected()) {
Serial.println("Connecting to MQTT...");
if (client.connect("ESP32", mqttUser, mqttPassword )) {
Serial.println("connected");
} else {
Serial.print("failed with state ");
Serial.print(client.state());
delay(2000);
}
}
client.publish("esp32", "reboot");
}
void loop()
{
client.loop();
currentMillis = millis();
if(currentMillis - prevring >= debouncering){
senseDoorbell = analogRead(doorbell);
if(senseDoorbell > 80){
client.publish("esp32", "dingdong");
Serial.println("dingdong");
prevring = currentMillis;
}
}
currentMillis2 = millis();
if(currentMillis2 - prevping >= debounceping){
client.publish("esp32", "online");
Serial.println("online");
prevping = currentMillis2;
}
}