Connecting my amp meter, currently used with arduino code


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() {
  pinMode(doorbell, INPUT);

void loop() {
  currentMillis = millis();
  if(currentMillis - prevRing >= debounce){
    senseDoorbell = analogRead(doorbell);
    if(senseDoorbell > 80){
      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 = "";
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() {

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
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 )) {


} else {

Serial.print("failed with state ");


client.publish("esp32", "reboot");


void loop()


    currentMillis = millis();
    if(currentMillis - prevring >= debouncering){
      senseDoorbell = analogRead(doorbell);
      if(senseDoorbell > 80){
        client.publish("esp32", "dingdong");
        prevring = currentMillis;

    currentMillis2 = millis();
    if(currentMillis2 - prevping >= debounceping){
        client.publish("esp32", "online");
        prevping = currentMillis2;

That’s why i always post a question on a forum, after posting it I mostly suddenly get it to work.

So instead of trying to make a xxxx.h file with the original or adjust arduino codes
and adding custom stuff in the esphome sensor it was apperently working when I found something different on a page somewhere.

I added this in the .yaml file and it added a sensor with the A info.
then used it in my automation trigger to get my lights and telegram notifcations to work.

Unless someone has a better option, this seems to do the trick and with a very basic code.

  - platform: ct_clamp
    sensor: adc_sensor
    name: "Measured Current"
    update_interval: 1s

  - platform: adc
    pin: GPIO17
    id: adc_sensor

Made another small change, just used one sensor setting.
so now i have changed the interval also to 500ms (with 1seconde i had sometimes issues connecting with the wifi due to overload)

So now when the bell is pressed it gets it every time, and it will reconnect with the wifi as well as it shoudl. No more missed bell notifcations.

  topic_prefix: esp32
  username: mqtt
  password: mqtt

  - platform: adc
    pin: GPIO17
    id: adc_sensor
    update_interval: 500ms
      - above: 0.009
          - mqtt.publish:
              topic: esp32
              payload: dingdong