SgtBatten / HA_blueprints

Somewhere to store automation blueprints
151 stars 55 forks source link

Cool down is applied even though previous event did not trigger notification #219

Open JesusSanchezLopez opened 1 month ago

JesusSanchezLopez commented 1 month ago

Description

The automation is set up to only notify if a person is within the front yard/driveway area. The street beyond the yard is masked off as I don't want notifications when someone walks by. I have a 60 second cool down specified to avoid back to back notifications while someone taking time to unlock the door. Notification is via Pushover (custom_auto and custom_multi), HA notification is disabled with an empty notification_group.

I had 2 back to back events happen, neither triggered a notification:

1) Delivery guy got out of his van -> No notification fired as person was not in required zone. 2) 47 seconds later, delivery guy walked up the driveway and dropped off package. -> No notification fired as cool down was still in effect (60 seconds)

Version

0.12.0.4a

Automation Config

alias: Frigate Notification - Front Door
description: ""
use_blueprint:
  path: SgtBatten/Stable.yaml
  input:
    camera: camera.front_door
    alert_once: true
    attachment: snapshot.jpg?bbox=1
    update_thumbnail: false
    icon: >-
      mdi:{{'account-outline' if label == 'Person' else 'dog' if label == 'Dog'
      else 'cat' if label == 'Cat' else 'car' if label == 'Car' else
      'home-assistant'}}
    zone_filter: true
    zones:
      - zone_front_door
    loiter_timer: 5
    notify_device: ed62b0b294f1b932b812b5c072a79c65
    message: >-
      A {{ label }} {{ 'is loitering' if loitering else 'was detected' }} on the
      {{ camera_name }} camera.
    tv: false
    debug: true
    tap_action: /lovelace
    android_auto: false
    labels:
      - person
      - dog
    custom_action_auto:
      - service: shell_command.url_to_file
        data:
          url: >-
            http://homeassistant.horvath.co:5000/api/events/{{trigger.payload_json['after']['id']}}/snapshot.jpg?bbox=1
          to_file: /config/snapshots/{{camera}}-{{id}}.jpg
      - service: notify.pushover
        data:
          title: "{{title}}"
          message: "{{message}}"
          data:
            sound: bugle
            attachment: /config/snapshots/{{camera}}-{{id}}.jpg
            url: homeassistant://navigate/ccab4aaf_frigate/ingress
            url_title: Check Frigate
    notify_group: doNotNotify
    initial_delay: 0
    custom_action_auto_multi:
      - service: shell_command.url_to_file
        data:
          url: >-
            http://xxx.yyy.com:5000/api/events/{{trigger.payload_json['after']['id']}}/snapshot.jpg?bbox=1
          to_file: /config/snapshots/{{camera}}-{{id}}.jpg
      - service: notify.pushover
        data:
          title: "{{title}}"
          message: "{{message}}"
          data:
            sound: bugle
            attachment: /config/snapshots/{{camera}}-{{id}}.jpg
            url: homeassistant://navigate/ccab4aaf_frigate/ingress # how to navigate directly to camera's events???
            url_title: Check Frigate
    silence_timer: 30
    cooldown: 60

Frigate Config

#
# Event storage is minimized until a second internal drive can be configured for storage
#

mqtt:
  host: 192.168.0.251
  user: username
  password: secret

# This is intel cpu accelerator
# VAAPI supports automatic profile selection so it will work automatically 
# with both H.264 and H.265 streams. VAAPI is recommended for 
# all generations of Intel-based CPUs if QSV (gen 10+ only) does not work.
ffmpeg:
  hwaccel_args: preset-vaapi
  output_args:
    record: preset-record-generic-audio-copy

objects:
  track:
    - person
    - dog
  filters:
    person:
      min_score: 0.66
    dog:
      min_score: 0.66

snapshots:
  enabled: true
  timestamp: false
  bounding_box: true
  crop: false
  retain:
    default: 3  #was 14
    objects:
      person: 7 #was 120

record:
  enabled: true
  sync_recordings: false   # true: checks file system and deletes db entries that no longer exist on disk. Uses lot's of resources, only use as needed!
  retain:
    days: 2 # This saves all recordings for 2 days by default
    mode: active_objects #should be motion - https://docs.frigate.video/configuration/record/#what-do-the-different-retain-modes-mean
  events:
    # unit is seconds
    pre_capture: 15
    post_capture: 30
    objects:
      - person
      - dog
    retain:
      default: 3  # should be 7
      mode: motion
      objects:
        person: 6  #default should be 14, lowering to save on space for now
        dog: 3

# Frigate can restream your video feed as an RTSP feed for other applications 
# such as Home Assistant to utilize it at rtsp://<frigate_host>:8554/<camera_name>.
# Port 8554 must be open. This allows you to use a video feed for detection 
# in Frigate and Home Assistant live view at the same time without having 
# to make two separate connections to the camera. 
# The video feed is copied from the original video feed directly 
# to avoid re-encoding. This feed does not include any annotation by Frigate.

go2rtc:
  rtsp:
    username: camera_username
    password: camera_password
  streams:
    Front_Door_Sub: # <- for RTSP streams
    - rtsp://user1:pass1@192.168.0.96:554/live/sub
    Front_Door: # <- for RTSP streams
    - rtsp://user1:pass1@@192.168.0.96:554/live/main
    Front_Window_Sub: # <- for RTSP streams
    - rtsp://user2:pass2@192.168.0.95:554/live/sub
    Front_Window: # <- for RTSP streams
    - rtsp://user2:pass2@192.168.0.95:554/live/main

detectors:
  coral:
    type: edgetpu
    device: usb

# to trigger upstairs camera when front door camera detects a person:
# set up a new camera with
# - detect front door camera
# - record upstairs camera
# This will run detection twice on front door camera, but this is the only way at the moment

cameras:
  Front_Door:
    enabled: True
    ffmpeg:
      output_args:
        record: preset-record-generic-audio-copy
      inputs:
      - path: rtsp://user3:pass3@192.168.0.251:8554/Front_Door_Sub
        roles:
        - detect
      - path: rtsp://user3:pass3@192.168.0.251:8554/Front_Door
        roles:
        - record
    detect:
      width: 704
      height: 576
      fps: 5
    objects:
      track:
        - person
        - dog
    record:
      retain: # This config will discard video unless an event is ongoing.
        days: 0
        mode: all
      events:
        required_zones:
          - zone_front_door
        pre_capture: 15
        post_capture: 30
        objects:
          - person
          - dog
        retain:
          mode: motion
          objects:
            person: 6  # should be 60
            dog: 3  # should be 30
    motion:
      mask: 644,279,683,0,143,0,143,124
    zones:
      zone_front_door:
        coordinates: 253,576,324,515,249,365,153,376,175,548,222,576,0,576,0,92,137,78,140,124,704,320,704,576
  Front_Window:
    enabled: True
    ffmpeg:
      output_args:
        record: preset-record-generic-audio-copy
      inputs:
      - path: rtsp://user99:pass99@192.168.0.251:8554/Front_Window_Sub
        roles:
        - detect
      - path: rtsp://user55:pass55@192.168.0.251:8554/Front_Window
        roles:
        - record
    detect:
      width: 704
      height: 576
      fps: 5
    objects:
      track:
        - person
        - dog
    record:
      retain: # This config will discard video unless an event is ongoing.
        days: 0
        mode: all
      events:
        required_zones:
          - zone_front_window
        pre_capture: 15
        post_capture: 30
        objects:
          - person
          - dog
        retain:
          mode: motion
          objects:
            person: 6 #should be 60
            dog: 3   # should be 30
    motion:
      mask: 
        - 201,122,466,98,450,0,0,0,0,318
        - 593,109,552,290,620,314,662,168
    zones:
      zone_front_window:
        coordinates: 0,576,0,401,104,272,364,216,356,547,561,500,704,81,704,576,247,576
        objects:
          - person
          - dog

    # Optional: Configuration for the jpg snapshots published via MQTT
    mqtt:
      # Optional: Enable publishing snapshot via mqtt for camera (default: shown below)
      # NOTE: Only applies to publishing image data to MQTT via 'frigate/<camera_name>/<object_name>/snapshot'.
      # All other messages will still be published.
      enabled: True
      # Optional: print a timestamp on the snapshots (default: shown below)
      timestamp: True
      # Optional: draw bounding box on the snapshots (default: shown below)
      bounding_box: True
      # Optional: crop the snapshot (default: shown below)
      crop: True
      # Optional: height to resize the snapshot to (default: shown below)
      height: 270
      # Optional: jpeg encode quality (default: shown below)
      quality: 80
      # Optional: Restrict mqtt messages to objects that entered any of the listed zones (default: no required zones)
      required_zones:
        - zone_front_door
        - zone_front_window

# Optional: Telemetry configuration
telemetry:
  # Optional: Enabled network interfaces for bandwidth stats monitoring (default: empty list, let nethogs search all)
  network_interfaces:
    - eth
#    - enp
#    - eno
#    - ens
#    - wl
    - lo
  # Optional: Configure system stats
  stats:
    # Enable AMD GPU stats (default: shown below)
    amd_gpu_stats: False
    # Enable Intel GPU stats (default: shown below)
    intel_gpu_stats: True
    # Enable network bandwidth stats monitoring for camera ffmpeg processes, go2rtc, and object detectors. (default: shown below)
    # NOTE: The container must either be privileged or have cap_net_admin, cap_net_raw capabilities enabled.
    network_bandwidth: False
  # Optional: Enable the latest version outbound check (default: shown below)
  # NOTE: If you use the HomeAssistant integration, disabling this will prevent it from reporting new versions
  version_check: True

Any other relevant information

There is only debug information from first event as second event skipped everything.

Frigate Notification DEBUG: Info: fps: 5, frigate event id: 1717450912.340242-ozvv8j, object (formatted): person (Person), Config: camera(formatted): front_door(Front Door), Base URL: , critical: False, alert once: True, Update Thumbnails: False, Video: , Target: group (input/formatted): doNotNotify/donotnotify, cooldown: 60s, loiter timer: 5s, initial delay: 0s, color: #03a9f4, sound: default, android_auto: False, Group: front_door-frigate-notification, Channel: , Sticky: False, Title: , Message: A Person was detected on the Front Door camera., Subtitle: , tap_action: /lovelace, button 1 Text/URL/Icon: View Clip (/api/frigate/notifications/1717450912.340242-ozvv8j/front_door/clip.mp4) , button 2 Text/URL/Icon: View Snapshot (/api/frigate/notifications/1717450912.340242-ozvv8j/snapshot.jpg) , button 3 Text/URL/Icon: Silence New Notifications (silence-front_door) , icon: mdi:account-outline tv: False, tv_position: center, tv_size: large, tv_duration: 10, tv_transparency: 0%, tv_interrupt: False, Filters: Zones: zone filter toggle on: True, Multi-Zone toggle on: False, Required zones: ['zone_front_door'], Entered Zones: [], Zone Filter TEST: FAIL, Required objects TEST: Input: ['person', 'dog'], TEST: PASS presence entity (not home): Entity: TEST: PASS, disabled times: [], State Filter: state filter toggle on: False, state filter entity: , required states: [], State Filter TEST: PASS, Custom Filter: True triggered by automation
mqtt topic frigate/events

Frigate Notification DEBUG (in loop): Send Notification: False Info: sublabel: None, image: "/api/frigate/notifications/1717450912.340242-ozvv8j/snapshot.jpg?bbox=1" Title: message: A Person was detected on the Front Door camera. iOS sound: disabled by alert once, Android Sound: disabled by alert once, iOS url: /api/frigate/notifications/1717450912.340242-ozvv8j/snapshot.jpg?bbox=1 video: "" critical: False, Triggers: New Snapshot: False - Disabled Presence Changed: False, Stationary Moved: False, Entered Zones Changed: False, sublabel changed: False, Conditions: Loitering: False or Filters: Zones: Zone Filter Enabled: True, Multi Zone Enabled: False, Required Zones: ['zone_front_door'], Last Zones: [], Entered zones: 0 - [], TEST: FAIL, Object Filter: Input: ['person', 'dog'], TEST: PASS, Presence entity (not home): Entity: , TEST: PASS, Time Filter: Disabled times: [], TEST: PASS State Filter: state filter toggle on: False, state filter entity: , required states: [], TEST: PASS, Custom Filter: PASS, triggered by automation
mqtt topic frigate/events
JesusSanchezLopez commented 1 month ago

Traces are already gone due to newer events :( pic

event 12

SgtBatten commented 1 month ago

With the way this is coded currently this is the expected result unfortunately

JesusSanchezLopez commented 1 month ago

With the way this is coded currently this is the expected result unfortunately

@SgtBatten: Is this something that can be incorporated in the future? Should I open a feature request?

JesusSanchezLopez commented 1 month ago

@SgtBatten: I added a datetime helper to my custom code. It gets set when a Pushover notification is sent then it is checked next time around with an if-then to make sure enough time has passed before allowing notification again.

However, I noticed another weird behavior: I set pushover delay to 120 seconds. Frigate fired an event and Pushover notification was sent. Frigate went on for 3+ minutes. I received a second Pushover notification even though it was the same event.

I would have expected to only get one notification per event, but this blueprint is firing multiple times. I assume this is because it is trying to update image or person, etc.

I guess, I can work around this by also storing event ID in a helper and making sure event ID is different before firing another pushover event.

SgtBatten commented 1 month ago

event ID in a helper and making sure event ID is different before firing another pushover event.

yes this would be a way to stop the loop from sending multiple