PIR - ignore "motion detected" for 3 minutes after initial detection

Hi all - I have a little question for you experts!
I have a few sensors spread around the house and have added PIRs to them all. I have added an automation that will alert me if any of them go off by sending a notification via Pushover to my phone but as the PIR does the on/off/on/off shuffle I get a lot of messages!

Is there a way of sending the initial “motion detected” message to MQTT and then ignore everything else for the next, say 3 minutes?

Thanks in advance!

Try a search for automation rate limit. There are a few ways to do it.

1 Like

I did look at that but perhaps I understood it incorrectly. From my thinking, if the PIR sends MQTT messages saying on / off / on / off every (for an example) 10 seconds and I put a delay in for 1 minute, when that 1 minute has gone by Hass will grab the next MQTT messages and start sending messages again, although at a slightly delayed rate.

Perhaps I will go and re-read it - thanks for the reply!

What are you using for the trigger of your automation?

Use the “for” statement in the trigger as defined here: https://www.home-assistant.io/docs/automation/trigger/#state-trigger

If you have multiple PIR’s per room or area you could combine those to a group and trigger with the group state. Group evaluates to true if any of the entities are true and false when all entities are false.

1 Like

Right off the top of my head one way you could do it would be to create an input_boolean and use it for a condition of your notification automation. then you could manipulate the boolean to get the result you want.

Example:

automation_1:
  trigger:
    platform: state
    entity_id: binary_sensor.your_motion_sensor
    to: 'on'
  condition:
    platform: state
    entity_id: input_boolean.your_bool
    state: 'off'
  action:
    - service: notification
      .
      .
    - service: homeassistant.turn_on
      entity_id: input_boolean.you_bool

automation_2:
  trigger
    platform: state
    entity_id: input_boolean.your_bool
    to: 'on'
  action:
    - delay: '00:03:00'
    - service: homeassistant.turn_off
      entity_id: input_boolean.your_bool

There may be a cleaner way but I think that should work.

1 Like
- platform: state
  entity_id: binary_sensor.Frontroom_PIR
  from: 'off'
  to: 'on'

Thats all I have - just getting into automations so starting off with, what I thought would be anyway, something simple :smiley:

working with an input_boolean is a good way.
there is also an input_datetime or a timer that can be used for simular ways to adchieve it.
i dont think it cant be done with less coding.

1 Like

Use a value template to query the last time the pir was triggered and tell it to ignore it for x minutes. My snippit below is similar my pir will detect movement and switch a light on and then ignore any further movements for 120 seconds. Obviously you would remove the condition and substitute the service for ios push instead of light on… I’m sure you get the gist

#Upstairs
  - alias: Visitor Mode Upstairs
    trigger:
      platform: state
      entity_id: binary_sensor.landing_pir
      to: 'on'
    condition:
      - condition: state
        entity_id: input_boolean.visitor_mode
        state: 'on'
      - condition: time
        after: '22:30:00'
        before: '06:30:00'
      - condition: template
        value_template: '{{ as_timestamp(now()) - as_timestamp(states.automation.visitor_mode_upstairs.attributes.last_triggered) | int > 120 }}'
    action:
      - service: light.turn_on
        entity_id: light.bathroom_ws_3
      - delay: 00:02:00
      - service: light.turn_off
        entity_id: light.bathroom_ws_3

I would also suggest putting a Boolean condition in so you can switch the pirs off.

Hope this helps

1 Like

Thanks to everyone who has taken time to reply - learning a lot so I guess an old dog can learn new tricks, it just takes a little more beating on the skull to get it to sink in!
Thanks again all

1 Like

dont bang to hard or it will fall out on the bottom again :wink:

1 Like

Forgot to say thanks to samtwilliams who provided their code snippet - helped me no end and I am now automating like a demon :smiley: