I’m using the alert integration in Home Assistant to notify me when any entrance door remains unlocked and closed for an extended period. However, I’m facing an issue with the alert’s deactivation behavior.
Current behavior:
- The alert activates when:
- The door has been closed for 10 minutes AND
- The door has been unlocked for 10 minutes
- The alert deactivates when:
- The door is opened OR
- The door is locked
Desired behavior:
- Activation remains the same
- The alert should deactivate ONLY when:
- The door is locked AND
- The door is closed
The purpose of the 10-minute delay is to avoid false triggers, such as when we’re actively using the door (e.g., bringing in items from the car) but it remains unlocked.
Here’s my current implementation:
# Binary Sensor (binary_sensor.front_door_unlocked)
{% set delay = 10 %}
{% set lock_open_duration = (now() - states.lock.front_door.last_changed) > timedelta(minutes = delay) %}
{% set lock_unlocked = is_state('lock.front_door', 'unlocked') %}
{% set door_closed_duration = (now() - states.binary_sensor.alarm_system_front_door.last_changed) > timedelta(minutes = delay) %}
{% set door_closed = is_state('binary_sensor.alarm_system_front_door', 'off') %}
{{ (lock_open_duration and lock_unlocked) and (door_closed_duration and door_closed) }}
# Alert
front_door_unlocked:
name: Front Door Unlocked
entity_id: binary_sensor.front_door_unlocked
state: "on"
repeat: 5
can_acknowledge: true
skip_first: false
title: "🚨 Alert"
message: "Front Door Unlocked"
done_message: "Issue cleared"
notifiers:
- me
data:
push:
sound:
name: "default"
critical: 1
volume: 1.0
tag: "alert-front-door-unlocked"
actions:
- action: ALERT_FRONT_DOOR_UNLOCKED_ACKNOWLEDGE
title: "Silence alert"
- action: ALERT_FRONT_DOOR_UNLOCKED_LOCK_DOOR
title: "Lock door"
Is it possible to achieve this using templates? I know I can do this via an automation with an input_boolean sensor, but I’m curious if there’s a template-based solution. Any help from template experts would be greatly appreciated!