Track front door visits across away sessions

master
Carlo Costanzo 4 weeks ago
parent aa57360b46
commit 9a656563c4

@ -4,9 +4,12 @@
# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
# -------------------------------------------------------------------
# Home Stats Automation - arrival briefing with weather and safety checks
# Related Issue: 364
# Announces key home status after family returns or on manual trigger.
# -------------------------------------------------------------------
# Notes: Waits for garage doors to close before speaking.
# Automatic first-household returns include the last trip's recorded doorstep
# visits. Manual briefings do not repeat it; the next departure resets the count.
######################################################################
- alias: 'Home Stats'
id: f98e1ef4-051b-4214-908d-d8b35f076a3e
@ -32,6 +35,15 @@
- service: script.speech_engine
data:
value1: >-
{% set visits = states('counter.front_door_visits_while_away') | int(0) %}
{% if trigger is defined and trigger.platform == 'state'
and trigger.entity_id == 'group.family' and visits > 0 %}
While everyone was out, {{ visits }} doorstep
{{ 'visit was' if visits == 1 else 'visits were' }} recorded.
Review the footage in Clips using the Doorstep visits filter.
[Report recorded visits, not distinct people or doorbell presses.]
{% endif %}
call_inside_weather: 1
call_garbage_day: 1
call_outside_weather: 1

@ -0,0 +1,331 @@
######################################################################
# @CCOSTAN - Follow Me on X
# For more info visit https://www.vcloudinfo.com/click-here
# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
# -------------------------------------------------------------------
# Front Door Visits - Frigate doorstep alerts and away visit counting.
# Related Issue: 364
# Reuses the shared notification engine and welcome-home Home Stats.
# -------------------------------------------------------------------
# Notes: A person must first enter Frigate's person-only doorstep zone.
# One episode stays open until the zone has been clear for 90 seconds.
# Away visits settle after 60 seconds; a return cancels the pending visit.
# Presence must be stable for two minutes; guest mode suppresses alerts
# and counting. These are recorded visits, not distinct people or presses.
# Notes: Helpers persist episode, pending visit, and away-session state.
# Frigate's instantaneous occupancy/count cannot supply that history.
# Startup reconciles restored helpers without resetting an ongoing trip.
######################################################################
counter:
front_door_visits_while_away:
name: Front Door Visits While Away
icon: mdi:doorbell-video
restore: true
minimum: 0
input_boolean:
front_door_visit_open:
name: Front Door Visit Open
front_door_away_session:
name: Front Door Away Session
front_door_away_visit_pending:
name: Front Door Away Visit Pending
input_datetime:
front_door_away_started:
name: Front Door Away Started
has_date: true
has_time: true
input_text:
front_door_last_visit_event:
name: Front Door Last Visit Event
max: 80
timer:
front_door_alert_snooze:
name: Doorstep Alerts Snooze
icon: mdi:bell-sleep
duration: '01:00:00'
restore: true
front_door_visit_clear:
name: Front Door Visit Clear
duration: '00:01:30'
restore: true
front_door_away_confirmation:
name: Front Door Away Confirmation
duration: '00:01:00'
restore: true
script:
front_door_notify_visit:
alias: Front Door Notify Visit
mode: parallel
max: 5
sequence:
- delay: '00:00:05'
- condition: state
entity_id: input_boolean.guest_mode
state: 'off'
- condition: state
entity_id: timer.front_door_alert_snooze
state: idle
- condition: template
value_template: >-
{{ states('group.family') in ['home', 'not_home']
and as_timestamp(now()) - as_timestamp(states.group.family.last_changed) > 120 }}
- action: script.notify_engine
data:
title: 'Someone is at the front door'
value1: 'A person reached the doorstep. Tap to review the recorded visit.'
who: parents
group: front_door_visits
tag: "front_door_{{ event_id }}"
notification_icon: mdi:doorbell-video
color: '#00796B'
level: active
image: "/api/frigate/notifications/{{ event_id }}/snapshot.jpg"
url: "/api/frigate/notifications/{{ event_id }}/clip.mp4"
title1: Snooze 1 hour
action1: SNOOZE_DOORSTEP_ALERTS_1H
icon1: sfsymbols:bell.slash
title2: Snooze 4 hours
action2: SNOOZE_DOORSTEP_ALERTS_4H
icon2: sfsymbols:bell.slash
automation:
- alias: 'Front Door - Record doorstep visit'
id: front_door_record_doorstep_visit
mode: queued
max: 10
triggers:
- trigger: mqtt
topic: frigate/events
payload: doorstep
value_template: >-
{% set event = value_json | default({}, true) %}
{% set after = event.get('after', {}) %}
{% set before = event.get('before', {}) %}
{{ 'doorstep' if event.get('type') in ['new', 'update']
and after.get('camera') == 'frontdoorbell'
and after.get('label') == 'person'
and not after.get('false_positive', true)
and 'doorstep' in after.get('current_zones', [])
and (event.get('type') == 'new' or before.get('false_positive', false)
or 'doorstep' not in before.get('entered_zones', [])) else 'ignore' }}
actions:
# Action conditions are evaluated when dequeued, after the previous latch.
- condition: state
entity_id: input_boolean.front_door_visit_open
state: 'off'
- variables:
event_id: "{{ trigger.payload_json.after.id }}"
event_age: "{{ as_timestamp(now()) - (trigger.payload_json.after.frame_time | float(0)) }}"
- condition: template
value_template: >-
{{ event_id != states('input_text.front_door_last_visit_event')
and event_id | regex_match('^[0-9]+[.][0-9]+-[a-zA-Z0-9]+$')
and -2 <= event_age | float <= 30 }}
- action: input_boolean.turn_on
target:
entity_id: input_boolean.front_door_visit_open
- action: input_text.set_value
target:
entity_id: input_text.front_door_last_visit_event
data:
value: "{{ event_id }}"
- if:
- condition: state
entity_id: binary_sensor.doorstep_person_occupancy
state: 'off'
then:
# Covers a fast visit whose occupancy-clear update arrived first.
- action: timer.start
target:
entity_id: timer.front_door_visit_clear
- action: script.send_to_logbook
continue_on_error: true
data:
topic: FRONT DOOR
message: >-
Doorstep visit recorded. Review:
/api/frigate/notifications/{{ event_id }}/clip.mp4
- if:
- condition: state
entity_id: group.family
state: 'not_home'
- condition: state
entity_id: input_boolean.front_door_away_session
state: 'on'
- condition: state
entity_id: input_boolean.guest_mode
state: 'off'
- condition: template
value_template: >-
{{ as_timestamp(now()) - as_timestamp(states('input_datetime.front_door_away_started'), as_timestamp(now())) > 120 }}
then:
- action: input_boolean.turn_on
target:
entity_id: input_boolean.front_door_away_visit_pending
- action: timer.start
target:
entity_id: timer.front_door_away_confirmation
- action: script.turn_on
target:
entity_id: script.front_door_notify_visit
data:
variables:
event_id: "{{ event_id }}"
- alias: 'Front Door - Visit lifecycle'
id: front_door_visit_lifecycle
mode: queued
triggers:
- trigger: state
entity_id: binary_sensor.doorstep_person_occupancy
to: 'off'
id: clear
- trigger: state
entity_id: binary_sensor.doorstep_person_occupancy
to: 'on'
id: occupied
- trigger: event
event_type: timer.finished
event_data:
entity_id: timer.front_door_visit_clear
id: expired
- trigger: homeassistant
event: start
id: startup
- trigger: state
entity_id: group.family
to:
- home
- not_home
id: presence
- trigger: event
event_type: timer.finished
event_data:
entity_id: timer.front_door_away_confirmation
id: confirm
actions:
- choose:
- conditions: "{{ trigger.id == 'occupied' }}"
sequence:
- action: timer.cancel
target:
entity_id: timer.front_door_visit_clear
- conditions:
- condition: template
value_template: "{{ trigger.id in ['clear', 'expired', 'startup'] }}"
- condition: state
entity_id: binary_sensor.doorstep_person_occupancy
state: 'off'
- condition: state
entity_id: input_boolean.front_door_visit_open
state: 'on'
sequence:
- choose:
- conditions: "{{ trigger.id == 'expired' }}"
sequence:
- action: input_boolean.turn_off
target:
entity_id: input_boolean.front_door_visit_open
default:
- action: timer.start
target:
entity_id: timer.front_door_visit_clear
- if: "{{ trigger.id in ['presence', 'confirm', 'startup'] }}"
then:
- choose:
- conditions:
- condition: state
entity_id: group.family
state: 'home'
sequence:
- action: input_boolean.turn_off
target:
entity_id:
- input_boolean.front_door_away_session
- input_boolean.front_door_away_visit_pending
- action: timer.cancel
target:
entity_id: timer.front_door_away_confirmation
- conditions:
- condition: state
entity_id: group.family
state: 'not_home'
sequence:
- choose:
- conditions:
- condition: state
entity_id: input_boolean.front_door_away_session
state: 'off'
sequence:
- action: counter.reset
target:
entity_id: counter.front_door_visits_while_away
- action: input_datetime.set_datetime
target:
entity_id: input_datetime.front_door_away_started
data:
timestamp: "{{ as_timestamp(now()) }}"
- action: input_boolean.turn_on
target:
entity_id: input_boolean.front_door_away_session
- action: input_boolean.turn_off
target:
entity_id: input_boolean.front_door_away_visit_pending
- conditions:
- condition: state
entity_id: input_boolean.front_door_away_visit_pending
state: 'on'
sequence:
- choose:
- conditions: "{{ trigger.id == 'confirm' }}"
sequence:
- if:
- condition: state
entity_id: input_boolean.guest_mode
state: 'off'
then:
- action: counter.increment
target:
entity_id: counter.front_door_visits_while_away
- action: input_boolean.turn_off
target:
entity_id: input_boolean.front_door_away_visit_pending
default:
# A timer can finish while HA is stopped. Preserve its
# pending visit and allow another presence grace period.
- if:
- condition: state
entity_id: timer.front_door_away_confirmation
state: 'idle'
then:
- action: timer.start
target:
entity_id: timer.front_door_away_confirmation
- alias: 'Front Door - Snooze alerts from notification'
id: front_door_snooze_alerts_from_notification
mode: queued
triggers:
- trigger: event
event_type: mobile_app_notification_action
event_data:
action: SNOOZE_DOORSTEP_ALERTS_1H
id: '01:00:00'
- trigger: event
event_type: mobile_app_notification_action
event_data:
action: SNOOZE_DOORSTEP_ALERTS_4H
id: '04:00:00'
actions:
- action: timer.start
target:
entity_id: timer.front_door_alert_snooze
data:
duration: "{{ trigger.id }}"

@ -8,6 +8,7 @@
# Compose messages from value1/value2/value3 with optional actions.
# -------------------------------------------------------------------
# Notes: Optional notification tags let recovery actions target a specific push.
# Optional image/url fields attach an event snapshot and open its recorded clip.
# Tags control replacement; groups remain visual notification categories.
# Notes: Known groups receive colored MDI icons; other callers retain their payload.
# Explicit notification_icon/icon_url overrides are shared by both helpers.
@ -89,6 +90,14 @@ notify_engine:
} %}
{% set notification_tag = tag | default('', true) | string | trim %}
{% set payload = dict(payload, tag=notification_tag) if notification_tag else payload %}
{% set event_image = image | default('', true) | string | trim %}
{% set event_url = url | default('', true) | string | trim %}
{% if event_image %}
{% set payload = dict(payload, image=event_image) %}
{% endif %}
{% if event_url %}
{% set payload = dict(payload, url=event_url, clickAction=event_url) %}
{% endif %}
{% set styles = {
'360_alerts': {'notification_icon': 'mdi:map-marker-radius', 'color': '#1565C0'},
'battery_alert': {'notification_icon': 'mdi:battery-alert-variant-outline', 'color': '#C2410C'},
@ -174,6 +183,8 @@ notify_engine_two_button:
tag: "{{ tag | default('', true) }}"
level: "{{ level | default('active', true) }}"
camera_entity: "{{ camera_entity | default('', true) }}"
image: "{{ image | default('', true) }}"
url: "{{ url | default('', true) }}"
notification_icon: "{{ notification_icon | default(none) }}"
icon_url: "{{ icon_url | default('', true) }}"
notification_icon_color: "{{ notification_icon_color | default('', true) }}"

@ -0,0 +1,117 @@
# Doorstep visits and welcome-home summary
Related: [issue #364](https://github.com/CCOSTAN/Home-AssistantConfig/issues/364).
The [front door package](../config/packages/front_door_visits.yaml) records
visits to the doorstep, sends the parents a snapshot with a recorded-clip link,
and counts visits during a household absence. This counts visit episodes,
not distinct people or physical doorbell button presses.
## Frigate setup
Create a camera-specific `doorstep` zone on `frontdoorbell`, covering the porch
floor and final approach. Restrict it to `person`, use inertia `3`, and leave
loitering at `0` so quick deliveries qualify. Tune coordinates against actual
footage: zone entry uses the bottom center of the tracked bounding box.
Keep the public sidewalk and decorative figures outside the zone.
Require `doorstep` for the camera's person **alerts**. General detections,
recording retention, package classifiers, and existing object masks are
unchanged. The integration should expose
`binary_sensor.doorstep_person_occupancy` after loading the new configuration.
Reload the Frigate integration if it has not discovered the zone.
See the official [zone guide](https://docs.frigate.video/configuration/zones/)
and [notification guide](https://docs.frigate.video/guides/ha_notifications/).
## When the Halloween decorations come down
The person-object mask named `halloween_scarecrow_2026` under
`frontdoorbell.objects.filters.person.mask` is temporary. Disable or remove it
when the scarecrow has actually been removed, then verify a normal approach and
a sidewalk pass against the unobstructed view. A calendar date alone does not
establish that the decoration has been taken down.
Keep the permanent `doorstep` zone. It defines where visits count, while the
temporary mask suppresses a specific decoration's false person detections.
Recheck the zone boundary after removal, especially around the right side of
the porch, rather than leaving a seasonal blind spot in place.
## Visit lifecycle
- A fresh person event first entering the zone opens one visit episode.
Updates, repeated event IDs, and additional people in that episode do not
produce more alerts or counts. Events older than 30 seconds are ignored.
- The zone must remain clear for 90 seconds before another visit can start.
This groups people arriving together and brief tracking interruptions.
Separate visits within that interval are deliberately grouped.
- The existing notification engine delivers to `parents`, honors the global
text-notification switch, and uses the event snapshot and clip through the
existing Frigate notification proxy. Clips are limited by recording retention
and may need the active recording segment to finish before playback.
- Guest mode suppresses notifications and away counting. Notifications also
wait five seconds and require household presence to have been stable for
two minutes, reducing arrival/departure alerts.
## Snooze and clip filtering
Doorstep alerts apply both at home and away. Each mobile notification offers
**Snooze 1 hour** and **Snooze 4 hours** actions for a party or trick-or-treaters.
Snooze is controlled through actionable notifications; Clips contains no
snooze controls.
The shared `timer.front_door_alert_snooze` mutes these alerts for both parents,
restores across restarts, and resumes notifications automatically at expiry.
It does not stop recording or away counting. Guest mode and the existing global
notification switch still apply independently.
Choose **Doorstep visits** beside the camera filter in **Clips** to request
recorded person clips from the `doorstep` zone. Filtering happens in Frigate
before pagination, so older matching clips remain reachable with **Older**.
Changing the camera returns to **All activity**; clearing the zone filter keeps
the selected camera. This is a clip filter: several clips can belong to one
grouped visit episode. Clips created before the zone existed are not backfilled.
## Away count and briefing
`counter.front_door_visits_while_away` resets when `group.family` starts a new
absence. The group includes the existing four resident person entities; named
off-site zones still count as away from this house.
An episode can count only after the away session has lasted two minutes. It
remains pending for 60 seconds, and a household return in that interval cancels
it. This is a conservative presence grace period, not identity recognition:
very late location updates can still count a returning resident, and a real
visitor just before a return can be excluded.
The existing [Home Stats arrival briefing](../config/automation/Speech/home_stats.yaml)
includes a positive count after the first household return. Manual briefings
do not repeat it. The count remains available until the next departure.
Zero does not produce a claim that nobody visited; camera or HA downtime can
leave gaps. Visits before installation are not backfilled.
Episode, away-session, pending-visit, event ID, timers, and counter helpers
restore across restarts. Startup preserves an ongoing trip and gives a pending
confirmation whose timer expired offline a fresh grace period. Unknown presence
does not count or discard a pending visit until presence is known again.
## Validation and operations
The initial zone was compared with 225 recent person events. All 49 candidate
snapshots showed people at the doorstep; sampled sidewalk and decoration events
stayed outside. Quick-delivery, nighttime, and decoration-control video samples
were also checked. Stored paths are sparse, so this is geometric and footage
validation, not a complete detector replay or an accuracy benchmark.
An isolated check using the installed Home Assistant script and template engines
with captured service boundaries covers
zone filtering, episode grouping, stale/duplicate events, presence grace,
restart reconciliation, guest mode, briefing gating, and notification compatibility.
It also checks snooze delivery suppression, notification actions, and continued
away counting during a snooze.
The check never connects to live MQTT or sends notifications. The YAML DRY
verifier and Home Assistant configuration validation also pass.
For a physical acceptance check, walk past on the sidewalk, then visit the porch,
leave it clear for at least 90 seconds, and repeat. Check a real absence/return
for one counter increment and one arrival summary. Such a future physical test
is separate from the recorded-footage and isolated automation checks.
Loading…
Cancel
Save

Powered by TurnKey Linux.