Binary sensor to check automation not working

I have a vibration sensor that gets triggered by the doorbell physically, which triggers an automation

I wanted to add a sensor that checks if the automation has been triggered in the last 60 seconds and if it has, it should not trigger again

I want this to eleminate false trigger from when i turn the lock and open the doorbell and close the door again

I added a template that checks of the automation has been triggered in the last 60 seconds:

binary_sensor.dorrklocka_triggad

{{ now() - state_attr(‘automation.dorrklocka_hemma_borta’, ‘last_triggered’) < timedelta(seconds=60) }}

So I added a condition that checks if the automation.dorrklocka_hemma_borta has been triggered, if off = not recently triggered

But whenever I add that condition, and it shows he value “off”, It wont trigger the automation even though all other conditions match

I’ve tried to add a delay by 1 sec, but no difference:

condition: state
entity_id: binary_sensor.dorrklocka_triggad
state: "off"
enabled: true
for:
  hours: 0
  minutes: 0
  seconds: 1

Thankfull for tips, what is the problem here?

This is the whole yaml:

> alias: Dörrklocka - Hemma & Borta
> description: ""
> triggers:
>   - entity_id: binary_sensor.hall_ytterdorr_vibration_vibration
>     to: "on"
>     trigger: state
> conditions: []
> actions:
>   - delay:
>       hours: 0
>       minutes: 0
>       seconds: 3
>       milliseconds: 0
>   - choose:
>       - conditions:
>           - condition: state
>             entity_id: binary_sensor.hall_ytterdorr_dorrsensor_contact
>             state: "off"
>           - condition: state
>             entity_id: person.jesper_viking
>             state: home
>             for:
>               hours: 0
>               minutes: 0
>               seconds: 0
>           - condition: time
>             after: "07:00:00"
>             before: "23:00:00"
>             enabled: true
>             weekday:
>               - sun
>               - sat
>               - fri
>               - thu
>               - wed
>               - tue
>               - mon
>           - condition: state
>             entity_id: binary_sensor.dorrklocka_triggad
>             state: "off"
>             enabled: true
>         sequence:
>           - metadata: {}
>             data:
>               cache: true
>               media_player_entity_id: media_player.overallt
>               message: NÄgon knackar pÄ dörren
>               language: sv-SE
>             target:
>               entity_id: tts.home_assistant_cloud
>             enabled: true
>             action: tts.speak
>           - metadata: {}
>             data:
>               message: NÄgon knackar pÄ dörren!
>             enabled: true
>             action: notify.mobile_app_samsung_s22
>           - metadata: {}
>             target:
>               entity_id:
>                 - scene.hej
>             enabled: true
>             action: scene.turn_on
>             data: {}
>           - delay:
>               hours: 0
>               minutes: 0
>               seconds: 1
>               milliseconds: 300
>             enabled: true
>           - target:
>               entity_id:
>                 - light.dorrklocka
>             data:
>               transition: 1
>             action: light.turn_off
>           - delay:
>               hours: 0
>               minutes: 0
>               seconds: 2
>               milliseconds: 0
>             enabled: true
>           - target:
>               entity_id:
>                 - light.dorrklocka
>             data: {}
>             action: light.turn_on
>           - delay:
>               hours: 0
>               minutes: 0
>               seconds: 1
>               milliseconds: 0
>             enabled: true
>           - target:
>               entity_id:
>                 - light.dorrklocka
>             data:
>               transition: 1
>             action: light.turn_off
>           - delay:
>               hours: 0
>               minutes: 0
>               seconds: 2
>               milliseconds: 0
>             enabled: true
>           - target:
>               entity_id:
>                 - light.dorrklocka
>             data: {}
>             action: light.turn_on
>           - delay:
>               hours: 0
>               minutes: 0
>               seconds: 1
>               milliseconds: 0
>             enabled: true
>           - metadata: {}
>             target:
>               entity_id: scene.hej
>             action: scene.turn_on
>             data: {}
>             enabled: true
>           - delay:
>               hours: 0
>               minutes: 0
>               seconds: 10
>               milliseconds: 0
>       - conditions:
>           - condition: state
>             entity_id: binary_sensor.hall_ytterdorr_dorrsensor_contact
>             state: "off"
>           - condition: state
>             entity_id: person.jesper_viking
>             state: not_home
>         sequence:
>           - action: notify.mobile_app_samsung_s22
>             metadata: {}
>             data:
>               message: dwq
> mode: single

No one has a clue what’s going wrong?

Would really appriciate it

Kind regards
Jesper

For situations like this I like to use a timer.
When the automation is triggered set a timer for 60 seconds.
Then in the automation’s conditions check that the timer is idle.

1 Like

Thank you!! I was stuck in the box, this worked out perfectly!

For anyone else wondering:

  1. I made a helper in form of a Timer set for 1m, with restore box checked

  2. Then made an automation to start the timer when the vibration sensor triggers:

alias: Dörr öppnas = Timer On
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.hall_ytterdorr_dorrsensor_contact
    to: "on"
conditions: []
actions:
  - action: timer.start
    metadata: {}
    data: {}
    target:
      entity_id: timer.dorrklocka
mode: single
  1. After that I added the timer to conditions to my doorbell automation:
condition: state
entity_id: timer.dorrklocka
 state: idle
 enabled: true