How to stop notification spam for sensor state change

Hello everyone,

I’ve configured a Tasmotized sonoff basic in my garage with a HC-SR501 pir sensor, and it is working great.
However there is one drawback, I cannot adjust the time delay pot on the sensor anymore (it is hot glued), so my pushbullet notification is spamming me whenever there is motion since it triggers on/off state very rapidly.

I’ve tried to add in a condition to add in a 60 second delay in between notifications, but it seems to not work. Anyone that can help me out?

  - alias: Notify Garage Door
    trigger:
      platform: state
      entity_id: binary_sensor.bewegingssensor
      to: 'on'
    condition:
      - condition: template
        value_template: "{{(as_timestamp(now()) - as_timestamp(states.binary_sensor.bewegingssensor.attributes.last_triggered)) | int > 60}}"
    action:
      service: notify.motion
      data_template:
        title: "Alarm"
        message: "Beweging in schuur"

Copy an paste the value_template of the condition in Dev Tools/Templates und you will see what you get.
The binary_sensor hass no attributes.last_triggered.
You can use the state last_changed.
states.binary_sensor.bewegingssensor.last_changed

1 Like
  - alias: Notify Garage Door
    trigger:
      platform: state
      entity_id: binary_sensor.bewegingssensor
      to: 'on'
    condition:
        condition: template
        value_template: "{{(as_timestamp(now()) - as_timestamp(states.binary_sensor.bewegingssensor.last_changed)) | default(0) | int > 60}}"
    action:
      service: notify.motion
      data_template:
        title: "Alarm"
        message: "Beweging in schuur"

Would result as “true” under templates. If there is motion, no notifications gets sent. However if I call the automation under devtools > states I do get a notification.

1 Like

Right, if the sensor turns to on, the last_changed time is now, and so the condition is false.
Found this, maybe it helps.

1 Like

Thanks a lot, that did the trick.

  - alias: Notify Garage Door
    initial_state: 'on'
    trigger:
      platform: state
      entity_id: binary_sensor.bewegingssensor
      from: 'off'
      to: 'on'
    condition:
        condition: template
        value_template: '{{ (as_timestamp(now()) - as_timestamp(state_attr("automation.notify_garage_door", "last_triggered") | default(0)) | int > 60)}}'
    action:
      service: notify.motion
      data_template:
        title: "Alarm"
        message: "Beweging in schuur"

I just called the delay on last triggered of the automation of sending a notification, instead of the state of the sensor. Works perfectly, no more Pushbullet spam <3