alias: "FRIGATE: Person Detect Logic - Driveway 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: Driveway conditions: - condition: or conditions: - condition: template value_template: "{{ trigger.payload_json['type'] == 'new' }}" - condition: template value_template: "{{ before_zones | length == 0 }}" enabled: true - alias: Object is in Street or Front Yard condition: template value_template: >- {{ ["driveway_z1", "Driveway_Paving"] | select("in", after_zones) | list | length > 0 }} enabled: true - condition: or conditions: - condition: template value_template: "{{ label == 'person' }}" alias: Person detected - condition: template value_template: "{{ label == 'license_plate' }}" alias: License plate detected enabled: true actions: - choose: - conditions: - condition: trigger id: frigate-event sequence: - action: input_boolean.turn_on metadata: {} data: {} target: entity_id: input_boolean.driveway_motion_detected alias: Set Driveway 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.driveway_motion_detected alias: Reset Driveway motion detected default: [] mode: parallel max: 10