docker-apps/home-assistant/Person Detect Logic.yml

98 lines
4.2 KiB
YAML

alias: "FRIGATE: Person Detect Logic"
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 }}"
trigger: mqtt
conditions:
- condition: or
conditions:
- condition: template
value_template: "{{ trigger.payload_json['type'] == 'new' }}"
- condition: template
value_template: "{{ before_zones | length == 0 }}"
enabled: false
- condition: template
value_template: "{{ trigger.payload_json[\"after\"][\"entered_zones\"]|length > 0 }}"
enabled: false
actions:
- choose:
- conditions:
- condition: trigger
id: frigate-event
sequence:
- action: script.person_in_driveway_detect_actions
data:
id: "{{ id }}"
title: >-
{{ label }} was detected on {{ camera | replace("_", " ") |
title }}
message: >-
{{ label }} detected in the {{ after_zones[0] | replace("_", "
") | title }}
notifTag: "{{ id }}"
notifIcon: mdi:doorbell-video
group: frigate-notification-{{ camera }}
importance: max
image: /api/frigate/notifications/{{ id }}/snapshot.jpg
video: ""
clickAction: ""
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"
- condition: template
value_template: "{{ wait.trigger.payload_json['type'] == 'end' }}"
- action: script.person_in_driveway_detect_actions
data:
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 }}
message: >-
Detected with {{ int(score | round(2) * 100) }}%
confidence
notifTag: "{{ id }}"
notifIcon: mdi:doorbell-video
group: >
frigate-notification-{{
trigger.payload_json["after"]["camera"] }}
importance: default
image: /api/frigate/notifications/{{ id }}/snapshot.jpg
video: >-
home-assistant.sthome.org/api/{{ id }}/{{ camera
}}/clip.mp4
clickAction: >
https://home-assistant.sthome.org/api/frigate/notifications/{{id}}/{{camera}}/clip.mp4
camera: "{{ camera }}"
until:
- condition: template
value_template: "{{ wait.trigger.payload_json[\"type\"] == \"end\" }}"
default: []
mode: parallel
max: 10