Can an automation be paused when camera field detection is detection is on

Admittedly “your topic is similar to” probably has the answer, but it’s not getting through my thick head.

My scenario is a camera that has an intrusion field set. I have triple checked that there are no other “crossings” enabled in Hikvision. The field area is for when the dog is at the back door. I have the automation turn on certain lights. The lights stay on for 6 seconds.

What I think is happening is the dog is in and out of the set field, which starts the automation over again. When the dog is inside and not triggering the intrusion, the lights still turn on again, sometimes twice.

Can I have the automation not run for say a minute after the first time it’s run?

alias: Bella ready to come in
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.mpr_field_detection_5
    from:
      - "off"
      - "on"
conditions:
  - condition: time
    after: "07:00:00"
    before: "22:00:00"
    weekday:
      - sun
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
actions:
  - alias: Turn on the light
    action: light.turn_on
    target:
      entity_id:
        - light.switchlinc_dimmer_43_28_d0
        - light.lamplinc_dimmer_3a_25_f8
    data: {}
  - alias: Wait until there is no motion from device
    wait_for_trigger:
      trigger: state
      entity_id: binary_sensor.mpr_field_detection_5
      from: "on"
      to: "off"
    continue_on_timeout: true
    timeout:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 0
  - alias: Wait the number of seconds that has been set
    delay:
      hours: 0
      minutes: 0
      seconds: 6
      milliseconds: 0
  - alias: Turn off the light
    action: light.turn_off
    target:
      entity_id:
        - light.switchlinc_dimmer_43_28_d0
        - light.lamplinc_dimmer_3a_25_f8
    data: {}
mode: restart
max_exceeded: silent

Yes, you can add a template condition:

  - condition: template
    value_template: "{{ now()|as_timestamp - state_attr('automation.THIS_AUTOMATIONS_ID','last_triggered')|as_timestamp(0) > 60 }}"

The poorly-named last_triggered attribute is the last time the action block was reached.

1 Like

Quick & dirty way to fix this is to add a 60s delay at the very end and change your mode to single.

@Troon’s suggestion is more elegant and is the proper way to handle it though.

2 Likes

How I throttle my stuff…
The ‘silent’ stops it from spamming the log, and I suggest that as well…

# This is at the end of the automation
  delay: 00:01:00
mode: single
max_exceeded: silent

Bella likes to play. Anything wrong with triggering the lights as an action/reward system?

That’s exactly what it does. The action is I get up let her in and the reward is the treat she gets!

Adding this did not work. I added the condition via the “add condition” button. Not sure if I was supposed to edit the phrase THIS_AUTOMATIONS_ID, I did not.

alias: Bella ready to come in
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.mpr_field_detection_5
    from:
      - "off"
      - "on"
conditions:
  - condition: time
    after: "07:00:00"
    before: "22:00:00"
    weekday:
      - sun
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
  - condition: template
    value_template: >-
      {{ now()|as_timestamp -
      state_attr('automation.THIS_AUTOMATIONS_ID','last_triggered')|as_timestamp(0)
      > 60 }}
actions:
  - alias: Turn on the light
    action: light.turn_on
    target:
      entity_id:
        - light.switchlinc_dimmer_43_28_d0
        - light.lamplinc_dimmer_3a_25_f8
    data: {}
  - alias: Wait until there is no motion from device
    wait_for_trigger:
      trigger: state
      entity_id: binary_sensor.mpr_field_detection_5
      from: "on"
      to: "off"
    continue_on_timeout: true
    timeout:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 0
  - alias: Wait the number of seconds that has been set
    delay:
      hours: 0
      minutes: 0
      seconds: 6
      milliseconds: 0
  - alias: Turn off the light
    action: light.turn_off
    target:
      entity_id:
        - light.switchlinc_dimmer_43_28_d0
        - light.lamplinc_dimmer_3a_25_f8
    data: {}
mode: restart
max_exceeded: silent

The history indicates the state being changed a second time within seconds of the first.

You were supposed to replace that, yes. I cannot tell from your post what the entity ID of the automation is.

Probably automation.bella_ready_to_come_in but you’ll have to check that.

Thank you. Editing the YAML I discovered that my trigger was formatted wrong. I had trigger ‘from detected’ and ‘from clear’. I changed it to ‘from detected to clear’. Problem solved, for now. It will depend on how antsy Bella is waiting for me to let her in.