Hold down timer for motion sensor and toggle button card to mute alerts

I am new to Home Assistant. so I apologize in advance for asking a question that may have already been answered.

I have a motion sensor connected through an ESP32 configured as an MQTT binary_switch. I have an automation setup that sends a text to my phone whenever the motion sensor is triggered, but I am looking for some way to configure a hold down timer on the binary_switch or the automation so I don’t get 100 text messages over a minute whenever the dog chases a squirrel in the back yard. Just one alert in 5 minutes is enough.

Is it possible to store the time in a variable when a binary sensor is triggered and then compare the current time with the stored time + X minutes the next time the sensor is triggered?

Is there a way to configure the automation to set a timer or store the current time in a variable so it can be compared the next time the sensor is triggered? Once the motion sensor has been triggered and an action is performed, additional motion sensor triggers should not take any actions for X minutes.

The other question is, is there any way to configure a button card that toggles the value of a variable that can also be set to mute notifications? For example, is it possible to set a variable as true or false that can be used in a condition?

Thanks for any help.

That should be a binary_sensor, not switch. You change switch states. Binary sensor states are changed by some process (e.g. movement detected).

There are a few ways to do this. The simplest is to make sure the automation is running in single mode (it is the default mode) and add a short delay at the end of the actions.

Another way is to use a condition that checks how long ago the automation was last triggered.

Please share the automation config. Correctly formatted for the forum.

Yes. Use an input boolean helper. Call it something like “Mute Notifications”. Then add a state condition to your notification automations to check if this helper is off.

Thanks for the information. I was finally able to get both features working using the boolean helper and the input_datetime helper. The binary_switch was a typo.

The boolean helper was easy to figure out. I added a card to the dashboard to toggle the helper.

The input_datetime helper took some time to figure out. I setup a condition to check if the input_datetime helper was unknown or if now() >= the helper timestamp. If the condition was true, I reset the timestamp with now() + deltatime of 5 minutes.

Here is the automation if anyone is interested.

- id: '123456789'
  alias: Motion Sensor1 Alert
  description: ''
  trigger:
  - platform: state
    entity_id:
    - binary_sensor.motion1
    from:
    to: 'on'
  condition:
  - condition: or
    conditions:
    - condition: state
      entity_id: input_datetime.hold_down_timer
      state: unknown
    - condition: template
      value_template: '{{ now().timestamp() >= as_timestamp(states(''input_datetime.hold_down_timer''))
        }}'
  action:
  - choose:
    - conditions: []
      sequence:
      - service: notify.persistent_notification
        data:
          message: Motion Detected
          title: Motion Detected
      - service: input_datetime.set_datetime
        metadata: {}
        data:
          datetime: '{{ now() + timedelta( minutes = 5 ) }}'
        target:
          entity_id: input_datetime.hold_down_timer
      - choose:
        - conditions:
          - condition: state
            entity_id: input_boolean.sms_boolean
            state: 'on'
          sequence:
          - service: notify.earthlink
            metadata: {}
            data:
              message: Motion Sensor Tiggered
              target: [email protected]
  mode: single

Now Fido can chase all the squirrels he wants without driving me nuts. :slight_smile:

Thanks,
Brian

No need for a datetime helper and the associated actions if the hold off time is fixed at five minutes. Just use this condition:

- id: '123456789'
  alias: Motion Sensor1 Alert
  description: ''
  trigger:
  - platform: state
    entity_id:
    - binary_sensor.motion1
    to: 'on'
  condition:
  - condition: template
    value_template: "{{ now() - this.attributes.last_triggered|default(as_datetime(0),1) > timedelta(minutes=5) }}"
  action:
  - if:
    - condition: state
      entity_id: input_boolean.sms_boolean
      state: 'on'
    then:
    - service: notify.earthlink
      metadata: {}
      data:
        message: Motion Sensor Tiggered
        target: [email protected]
  mode: single