docker-apps/home-assistant/FRIGATE- Person Detect Logic - Patio Camera.yml

119 lines
5.1 KiB
YAML

alias: "FRIGATE: Person Detect Logic - Patio Camera"
description: >-
This automation is used to send a notification when a person is detected by
Frigate. It uses the frigate MQTT event stream to trigger the notification and
includes a snapshot of the detected object. The notification will be sent to
all devices with the specified group and will include a video clip of the
detection if available.
triggers:
- topic: homeassistant/events
id: frigate-event
value_template: "{{ value_json[\"after\"][\"camera\"] }}"
variables:
after_zones: "{{ trigger.payload_json[\"after\"][\"entered_zones\"] }}"
before_zones: "{{ trigger.payload_json[\"before\"][\"entered_zones\"] }}"
camera: "{{ trigger.payload_json[\"after\"][\"camera\"] }}"
id: "{{ trigger.payload_json[\"after\"][\"id\"] }}"
label: "{{ trigger.payload_json[\"after\"][\"label\"] }}"
score: "{{ trigger.payload_json[\"after\"][\"score\"] }}"
time_clip_start: "{{ trigger.payload_json[\"after\"][\"start_time\"] - 10.0 }}"
detect_time: "{{trigger.payload_json[\"after\"][\"start_time\"]|int}}"
trigger: mqtt
payload: Patio
conditions:
- condition: or
conditions:
- condition: template
value_template: "{{ trigger.payload_json['type'] == 'new' }}"
alias: New message
- condition: template
value_template: "{{ before_zones | length == 0 }}"
alias: No zones in before segment
enabled: true
- alias: Object is on Patio
condition: template
value_template: >-
{{ ["patio_z1", "Patio_Gate"] | select("in", after_zones) | list | length
> 0 }}
enabled: true
actions:
- choose:
- conditions:
- condition: trigger
id: frigate-event
- condition: or
conditions:
- condition: template
value_template: "{{ trigger.payload_json[\"before\"][\"stationary\"] != 'true' }}"
- condition: template
value_template: "{{ trigger.payload_json[\"after\"][\"stationary\"] != 'true' }}"
alias: Object is moving
sequence:
- action: script.person_detect_actions
data:
send_to_nova_4k: "false"
id: "{{ id }}"
title: >-
{{ label }} was detected on {{ camera | replace("_", " ") |
title }} camera
message: >-
"{{ label }} detected in the {{ after_zones[0] | replace("_", "
") | title }} zone"
notifTag: "{{ id }}"
notifIcon: mdi:alarm-light
group: frigate-notification-{{ camera }}
channel: alarm
importance: max
priority: critical
image: /api/frigate/notifications/{{ id }}/snapshot.jpg
video: null
base_url: https://home-assistant.sthome.org
when: "{{ detect_time }}"
camera: "{{ camera }}"
- repeat:
sequence:
- wait_for_trigger:
- topic: homeassistant/events
payload: "{{ trigger.payload_json[\"after\"][\"id\"] }}"
value_template: "{{ value_json[\"after\"][\"id\"] }}"
trigger: mqtt
continue_on_timeout: false
timeout: "00:02:00"
alias: 2 min timeout
- condition: template
value_template: "{{ wait.trigger.payload_json['type'] == 'end' }}"
alias: Wait for end event
- action: script.person_detect_actions
data:
send_to_nova_4k: "false"
id: "{{ id }}"
title: >
{% if (wait.trigger.payload_json["after"]["sub_label"] !=
None) -%} {{
(wait.trigger.payload_json["after"]["sub_label"]) | title
}} {%- else -%} {{ label | replace("_", " ") | title }}
{%- endif %} was detected in the {{ after_zones[0] |
replace("_", " ") | title }} zone
message: >-
Detected with {{ int(score | round(2) * 100) }}%
confidence
notifTag: "{{ id }}"
notifIcon: mdi:cctv
group: >
frigate-notification-{{
trigger.payload_json["after"]["camera"] }}
channel: alarm
priority: high
importance: default
image: /api/frigate/notifications/{{ id }}/snapshot.jpg
video: /api/frigate/notifications/{{ id }}/{{ camera }}/clip.mp4
base_url: https://home-assistant.sthome.org
when: "{{ detect_time }}"
camera: "{{ camera }}"
until:
- condition: template
value_template: "{{ wait.trigger.payload_json[\"type\"] == \"end\" }}"
default: []
mode: parallel
max: 10