Fixed content of FRIGATE- Person Detect Logic - Backyard Camera.yml. Copied wrong scripts text.

This commit is contained in:
Chris Stuurman 2025-05-08 21:03:33 +02:00
parent 8e640c0acf
commit 84f530bfc4
2 changed files with 125 additions and 96 deletions

View File

@ -6,9 +6,14 @@ sequence:
{% set user_id = context.user_id %} {{ states.person |
selectattr('attributes.user_id', '==', user_id) |
map(attribute='attributes.friendly_name') | first }}
- condition: template
value_template: "{{ context_user == authorised_user }}"
alias: is user excuting script the authorised_user?
- condition: or
conditions:
- condition: template
value_template: "{{ context_user == authorised_user }}"
alias: is user excuting script the authorised_user?
- condition: template
value_template: "{{ context_user == 'Chris' }}"
alias: is user excuting script the admin user?
- choose:
- conditions:
- condition: template

View File

@ -1,100 +1,124 @@
alias: Action specified device for specified user
description: ""
sequence:
- variables:
context_user: >-
{% set user_id = context.user_id %} {{ states.person |
selectattr('attributes.user_id', '==', user_id) |
map(attribute='attributes.friendly_name') | first }}
alias: "FRIGATE: Person Detect Logic - Backyard 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: Backyard
conditions:
- condition: or
conditions:
- condition: template
value_template: "{{ context_user == authorised_user }}"
alias: is user excuting script the authorised_user?
value_template: "{{ trigger.payload_json['type'] == 'new' }}"
- condition: template
value_template: "{{ context_user == 'Chris' }}"
alias: is user excuting script the admin user?
value_template: "{{ before_zones | length == 0 }}"
enabled: true
- alias: Object is in Back Yard
condition: template
value_template: "{{ [\"backyard_z1\"] | select(\"in\", after_zones) | list | length > 0 }}"
enabled: true
- alias: Person detected
condition: template
value_template: "{{ label == 'person' }}"
enabled: true
actions:
- choose:
- conditions:
- condition: template
value_template: "{{ action_to_perform == 'toggle' }}"
alias: is toggle requested?
- condition: trigger
id: frigate-event
sequence:
- choose:
- conditions:
- condition: template
value_template: "{{ device == 'sm_n986b' }}"
alias: is device sm_n986b?
sequence:
- action: input_boolean.toggle
metadata: {}
data: {}
target:
entity_id: input_boolean.notify_sm_n986b
- conditions:
- condition: template
value_template: "{{ device == 'nokia_c20' }}"
alias: is device nokia_c20?
sequence:
- action: input_boolean.toggle
metadata: {}
data: {}
target:
entity_id: input_boolean.notify_nokia_c20
- conditions:
- condition: template
value_template: "{{ device == 'sm_x115' }}"
alias: is device sm_x115?
sequence:
- action: input_boolean.toggle
metadata: {}
data: {}
target:
entity_id: input_boolean.notify_sm_x115
- conditions:
- condition: template
value_template: "{{ device == 'sm_a032f' }}"
alias: is device sm_a032f?
sequence:
- action: input_boolean.toggle
metadata: {}
data: {}
target:
entity_id: input_boolean.notify_sm_a032f
- conditions:
- condition: template
value_template: "{{ device == 'sm_a245f' }}"
alias: is device sm_a245f?
sequence:
- action: input_boolean.toggle
metadata: {}
data: {}
target:
entity_id: input_boolean.notify_sm_a245f
- conditions:
- alias: is device sm_a042f?
condition: template
value_template: "{{ device == 'sm_a042f' }}"
sequence:
- action: input_boolean.toggle
metadata: {}
data: {}
target:
entity_id: input_boolean.notify_sm_a042f
fields:
authorised_user:
selector:
text: null
name: Authorised User
description: User who is allowed to execute script
required: true
action_to_perform:
selector:
text: null
name: Action to Perform
required: true
device:
selector:
text: null
name: Device
required: true
- action: input_boolean.turn_on
metadata: {}
data: {}
target:
entity_id: input_boolean.backyard_motion_detected
alias: Set Backyard motion detected
- action: script.person_detect_actions
alias: Trigger alarm and send critical priority event to devices
data:
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
alias: Send high priority notification to devices
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 }} 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\" }}"
alias: End event is detected
- action: input_boolean.turn_off
metadata: {}
data: {}
target:
entity_id: input_boolean.backyard_motion_detected
alias: Reset Backyard motion detected
default: []
mode: parallel
max: 10