Got a bug and cant find it, need help

Hi all,

hope you don’t mind me asking this but I have a doorbell that I made smart thanks to a tutorial online, I’ve made a few small changes to suit my doorbell and needs but I’ve got an issue and I cant find where it is to fix it.

when connected to HA everything works perfectly, exactly as I want, somone pushed the doorbell and it goes “ding, dong…ding, dong” i can turn it off/on from HA and I can trigger it from HA if needed. However I’ve recently had some issues with HA shutting down unexpectedly and its highlighted an issue that i need to fix, it would appear that if the Doorbell cant connect to HA then every so often it goes “Ding, dong” which at 3am is not ideal, it appears to do this about every 10-15 mins or so (i’ve not timed it ). is this something I can fix ? what’s causing it?

any help welcome… here is my complete yaml from ESPhome

Edit: just remembered that I have a uptime log on the doorbell and checked that, it looks like the Door bell is restarting and triggering the doorbell as it does. no idea why it is restarting or why it is triggering the bell, but the bell only randomly rings if HA is off.

esphome:
  name: front_doorbell
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: !secret ssid
  password: !secret wifi_password
  manual_ip:
    static_ip: 192.168.0.5
    gateway: 192.168.0.1
    subnet: 255.255.255.0
    dns1: 192.168.0.1
    dns2: 192.168.0.1

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

# Enable Web server.
web_server:
  port: 80

# Sync time with Home Assistant.
time:
  - platform: homeassistant
    id: homeassistant_time


# Sensors with general information.
sensor:
  # Uptime sensor used in following formatted uptime sensor
  - platform: uptime
    name: "Doorbell Do Not Use"
    id: doorbell_do_not_use
    update_interval: 1s

  # WiFi Signal sensor.
  - platform: wifi_signal
    name: Doorbell WiFi Signal
    update_interval: 60s


# Text sensors with general information.
text_sensor:
  # Expose ESPHome version as sensor.
  - platform: version
    name: Doorbell ESPHome Version
    
  # Expose WiFi information as sensors.
  - platform: wifi_info
    ip_address:
      name: Doorbell IP
    ssid:
      name: Doorbell SSID
    bssid:
      name: Doorbell BSSID

# Sensor to display uptime in Days/hours/minutes      
  - platform: template
    name: "Doorbell Uptime"
    lambda: |-
      uint32_t dur = id(doorbell_do_not_use).state;
      int dys = 0;
      int hrs = 0;
      int mnts = 0;
      if (dur > 86399) {
        dys = trunc(dur / 86400);
        dur = dur - (dys * 86400);
      }
      if (dur > 3599) {
        hrs = trunc(dur / 3600);
        dur = dur - (hrs * 3600);
      }
      if (dur > 59) {
        mnts = trunc(dur / 60);
        dur = dur - (mnts * 60);
      }
      char buffer[17];
      sprintf(buffer, "%ud %02uh %02um %02us", dys, hrs, mnts, dur);
      return {buffer};
    icon: mdi:clock-start
    update_interval: 1s



# Global to store the on/off state of the chime
globals:
  - id: chime
    type: bool
    restore_value: true
    initial_value: 'true'

# Exposed switches.
switch:
  # Switch to restart the doorbell.
  - platform: restart
    name: Doorbell Restart

  # Switch to turn on/off the chime.
  - platform: gpio
    id: relay
    inverted: true
    name: Doorbell Chime
    pin: GPIO0

  # Switch to turn on/off chime when
  # doorbell button is pushed.
  #
  # It creates a "virtual" switch based
  # on a global variable.
  - platform: template
    name: Doorbell Chime Active
    id: chime_active
    restore_state: false
    turn_on_action:
      - globals.set:
          id: chime
          value: 'true'          
    turn_off_action:
      - globals.set:
          id: chime
          value: 'false'
    lambda: |-
      return id(chime);
      
# Binary sensor representing the
# Doorbell button push.
binary_sensor:
  - platform: gpio
    id: button
    name: Doorbell Button
    pin:
      # Connected to GPIO on the ESP-01S.
      number: GPIO2
      mode: INPUT_PULLUP
      inverted: true
    filters:
      # Small filter, to debounce the button press.
      - delayed_on: 25ms
      - delayed_off: 25ms
    on_press:
      # Only turn on the chime when it is active, switch is then turned off to prevent shorting the system
      then:
        if:
          condition:
            - switch.is_on: chime_active
          then:
            - switch.turn_on: relay
            - delay: 100ms
            - switch.turn_off: relay
    on_release:
      # On release, turn of the chime, switch is turned on then off to increase the audible notification and prevent shorting
      - switch.turn_on: relay
      - delay: 100ms
      - switch.turn_off: relay

thank you for your help and time .

The reoccurring chime is probably the ESP device restarting.
In the API section, there is a default for reboot time if it cannot connect to Home Assistant:

**reboot_timeout** ( *Optional* , [time](https://esphome.io/guides/configuration-types.html#config-time)): The amount of time to wait before rebooting when no client connects to the API. This is needed because sometimes the low level ESP functions report that the ESP is connected to the network, when in fact it is not - only a full reboot fixes it. Can be disabled by setting this to '0s' . Defaults to '5min' .

It sounds like when it restarts, it is temporarily energizing the circuit and ringing the chime. On the on_press and on_release you have the chime relay activating and deactivating - this is a change you made from the template Frenck blogged on (your source for the YAML).

One question - what device are you using?
The original design was for a ESP01s, it could be that if you are using another device the YAML would need to be modified to account for this.

The “quick fix” is to just set the reboot time on API to 0 to disabled it… but if you want to investigate further it would be interesting to find out why it triggers on boot.

Cheers!
DeadEnd

1 Like

Hi DeadEnd,

Thank you for your reply and yes looking at the uptime logs I can confirm it is rebooting, though I didn’t know about the connection to HA.

Yes that’s the tutorial I used (couldn’t find it again to give a link and wasn’t sure how to spell his name :wink: ) .

the devices I’m using are as described in the tutorial an ESP-01s and relay (purchased using the link provided). I’m happy to investigate this further (though honestly I have no idea how and would need help/direction) as with this I hope to learn more and not just “put a plaster on it and hope for the best” .

thank you

Okay - I am still very inexperienced, but enjoy troubleshooting…
I would expect that one of the pieces you customized is causing the trigger on reboot.
I don’t know the boot process of the ESPHome firmware intimately, but here is my guess…

The one thing that makes me itch is the on_press and on_release at the end.
I expect you did this for a reason, but I am wondering if at power up if the on_release is being triggered… Try removing the - switch.turn_on: relay under on_release:. I just an feeling this is triggered on boot-up, but again, just a guess.

We can also kindly request @frenck assistance and see if he has a minute to shed light on the topic. He might be able to tell use what part of the YAML is being triggered during bootup causing the chime trigger.

Cheers!
DeadEnd

ok these are the parts I have customized

# Sensors with general information.
sensor:
  # Uptime sensor used in following formatted uptime sensor
  - platform: uptime
    name: "Doorbell Do Not Use"
    id: doorbell_do_not_use
    update_interval: 1s

The below was found here https://community.home-assistant.io/t/uptime-sensor-in-hours-or-days/116392/15

# Sensor to display uptime in Days/hours/minutes      
  - platform: template
    name: "Doorbell Uptime"
    lambda: |-
      uint32_t dur = id(doorbell_do_not_use).state;
      int dys = 0;
      int hrs = 0;
      int mnts = 0;
      if (dur > 86399) {
        dys = trunc(dur / 86400);
        dur = dur - (dys * 86400);
      }
      if (dur > 3599) {
        hrs = trunc(dur / 3600);
        dur = dur - (hrs * 3600);
      }
      if (dur > 59) {
        mnts = trunc(dur / 60);
        dur = dur - (mnts * 60);
      }
      char buffer[17];
      sprintf(buffer, "%ud %02uh %02um %02us", dys, hrs, mnts, dur);
      return {buffer};
    icon: mdi:clock-start
    update_interval: 1s

this is was me trying to work it out myself

# Binary sensor representing the
# Doorbell button push.
binary_sensor:
  - ...
    ...
    on_press:
      # Only turn on the chime when it is active, switch is then turned off to prevent shorting the system
      then:
        if:
          condition:
            - switch.is_on: chime_active
          then:
            - switch.turn_on: relay
            - delay: 100ms
            - switch.turn_off: relay
    on_release:
      # On release, turn of the chime, switch is turned on then off to increase the audible notification and prevent shorting
      - switch.turn_on: relay
      - delay: 100ms
      - switch.turn_off: relay

hope that helps

Please try my suggestion and let me know… of the things that you customized, this is the only one that touches the relay, so it is the only likely candidate.

just changed that and uploading it now (commented it out along with the delay)

if that turns out to be the flaw i guess the following would work to solve it…

          condition:
            - switch.is_on: chime_active
          then:
            - switch.turn_on: relay
            - delay: 100ms
            - switch.turn_off: relay
            - delay: 1s
            - switch.turn_on: relay
            - delay: 100ms
            - switch.turn_off: relay

or is there another way ?

done all that, unplugged HA and waited… then my wife tells me she took the bell apart lol totally appart so I’ll need to re-assemble the doorbell now lol

Is there a reason you are not using what frenck wrote originally?
Is your chime only ringing once instead of twice? Is that the reason?

In its default design, one a two tone chime, it will hit one tone when the button is pressed and the other tone when it is released - this should work fine.

Try going back to the original:

    on_press:
      # Only turn on the chime when it is active.
      then:
        if:
          condition:
            - switch.is_on: chime_active
          then:
            - switch.turn_on: relay
    on_release:
      # On release, turn of the chime.
      - switch.turn_off: relay

DeadEnd

SECOND THOUGH:

Is your doorbell circuit AC or DC?

I was thinking you might have customized the on/release because you were only getting one tone instead of two. I think if the curcuit was DC this might happen.

The YAML has the relay setup with inverted: true… it could be that your doorbell is different (DC) and this is causing it to be not work as expected… aka it is energized all the time, and the button is interrupting the circuit instead of completing it.

Check your circuit for AC/DC and try removing the inverted: true from the relay component.

the doorbell is A/C

the reason for the configuration I had is due to a local trend with kids putting tape onto the doorbell and running away. the doorbell only rings once but it causes the doorbell to short resulting in a new doorbell/transformer (happend to me twice now) . the Double ring (on- off, on- off) is just personal preference.

Edit: still in the process of rebuilding the doorbell

Ah! okay - that makes great sense.
In that case, I would leave your on_press as is.
This will prevent the circuit from staying energized and burning up.

The on_release I would either remove entirely (since you turn off the relay during on_press) or just have it as the template from frenck - switch.turn_off: relay.
I still have the thought that the on_release is triggering on boot (but this is just a hunch).

DeadEnd

after hunting around for lost parts I’ve got the doorbell re-assembled and online, Home assistant is still unplugged so will know in a few mins if the bell will ring

that’s sorted it, thank you. would be good to know why the on_release: was being triggered on a reboot though.

Thet on_press and on_release are triggered by the high and low state of the binary sensor. When the device boots up, it probably sets the initial state, which for the binary sensor is triggering the on_release automation.

Someone who knows ESPHome better than me could probably confirm or explain it better. But that is what I think is happening. I don’t know if we’ll get an answer here, but if you really want to figure it out, you could post something on the issues page of the ESPHome github… this is probably your best bet for getting attention on it.

Cheers!
DeadEnd

1 Like

that makes sense, i suppose being a switch it has to start in one position.

thank you for your help i greatly appreciate it.