Help needed with automation constantly fired

Hi all,

the problem:
I have a doorbell witch I have made smart trough this guide: https://frenck.dev/diy-smart-doorbell-for-just-2-dollar/
I have made a automation when the doorbell is going Telegram send me a message. It worked fine until a few days ago, the automation is fired once every half hour about 5-6 times. I can’t find a solution.

HA version 2021.5.5
Docker: true
Supervisor: true
Operating System: Linux

My automation:

- id: '1622284053297'
  alias: Als de voordeurbel gaat
  description: ''
  trigger:
  - platform: state
    entity_id: switch.doorbell_chime
  condition: []
  action:
  - service: telegram_bot.send_message
    data:
      message: er staat iemand voor de deur
  mode: single

Any help is appreciated

Greets
Bas

should the trigger not be looking for a change in state, i.e. from off to on ?

trigger:
  - platform: state
    entity_id: switch.doorbell
    from: 'off'
    to: 'on'

Hi smck83, thanks for your answer. I have tried that but no result. Telegram would sent nothing.
Some other thoughts?

Have you used telegram for anything else? I.e. are we troubleshooting the accuracy of when the doorbell triggers or telegram being able to send a msg?

Perhaps a loose connection for the GPIO sensor or a floating GPIO pin. Did you set the mode: INPUT_PULLUP and inverted: True on the binary sensor?

Presumably the switch is changing its state repeatedly, which you should find in the logbook and entity history.
Without that information it’s very hard to suggest anything concrete.

That trigger will fire when the state or any attribute changes.

You may want to add a little logic like

condition:
- condition: template
  value_template: "{{ trigger.from_state.state != trigger.to_state.state }}"

So you mean it would also trigger if state went to unknown not just on/off?

Have a look at the states and attributes in Dev Tools > States

Search for switch.doorbell_chime

And like my example with on and off change it to whatever the different states are

So I’am back at my desk :slight_smile:

@smck83 I have Telegram for several items to send me a notification. I have tried your
@spiro Yes I have set this mode
@TazUk I have changed it but no result

I have checked the wiring, its all good.

Wouldnt it be better to trigger on the button press ?

EDIT scrap that, it would send a notification if the chime active switch is off

With respect I think this reply isn’t for me.
I merely suggested that you provide some additional information so that the community can help solve the issue - I didn’t suggest changing anything.

yes @TazUk you are wright. I’ am sorry.
Where can I find logs of a single entity? In the general logs I can’t find anything

Assuming you have the Logbook - Home Assistant configured you should be able to search by entity in there.
Alternatively under the Developer Tools > State in the UI, if you click on the ⓘ against the entity there should be an option to view History from there.
One of these should tell you the pattern of states that are changing (attributes not so much).

Alternatively, as an old-school programmer I still have a weakness for temporarily adding logbook entries to problem automations to help smooth the implementation.
So you could add another step to your automation, something like:

    - service: logbook.log
      data:
        entity_id: "switch.doorbell_chime"
        name: "States: from= {{ trigger.from_state.state }} to =  {{trigger.to_state.state }}"
        message: "Attributes: {{ states.switch.doorbell_chime.attributes }}"
        domain: automation

That would at least ensure you can view state changes in the Logbook and get a snapshot of the attributes at the point the automation fires.

1 Like

Simple check the history of switch.doorbell_chime to see what it is doing every half-hour. For example:

Screenshot from 2021-07-20 11-20-31

If you see activity every half hour then the automation is just reacting to the switch’s state-changes.

As mentioned, the State Trigger will trigger for any change of state (off to on, on to off, off to unavailable, etc) and a change to any of its attribute’s values. The off/on/off sequence would explain at least two of the ‘5-6 times’ you mentioned.

My guess is that the doorbell switch is losing its connection on a periodic basis and every time that happens, it rapidly changes its state through several phases (unavailable, off, on, etc).