A recent LED strip exit-warning setup checks window contacts and room presence before someone leaves. That raised a separate edge case for me: if one contact or presence sensor has stopped reporting, “all closed” or “nobody else home” may not be a confirmed result.
I would want a distinct unknown indication at the door rather than treating a stale reading as closed or empty. How would you decide when a sensor state is too old to trust, and what should the LED strip do in that case without creating constant false alarms? If you have built this in Aqara Home or Home Assistant, how do you handle a delayed update versus a truly unavailable sensor?
1 Like
In Home Assistant, handling sensor staleness requires decoupling the native state (on , off , open , closed ) from the sensor’s reporting health (unavailable , unknown , or stale timestamp), especially for battery-powered Zigbee or Thread endpoints that report by exception.
1. Deciding When a State Is Too Old to Trust
Different sensor types require distinct staleness thresholds based on how their firmware communicates:
2. Differentiating Delayed Updates vs. Truly Unavailable
In Home Assistant, there is a key operational distinction:
-
Protocol-Level Availability (unavailable / unknown): Handled natively by ZHA, Zigbee2MQTT, or the Matter integration when a device misses its designated check-in window (e.g., ZHA active availability pings). The state string itself becomes 'unavailable' or 'unknown' .
-
Stale/Silent State: The device crashed or fell off the mesh cleanly without the coordinator noticing yet.The state remains 'off' or 'closed' , but last_updated has frozen.
To handle both cleanly, aggregate health into template binary sensors or an umbrella group.
A. Template Sensor for Stale / Dead Monitoring
Use last_reported (added in recent HA versions) rather than last_changed or last_updated , because last_reported updates even when attributes or heartbeats refresh without a state change:
`YAMLtemplate:
- binary_sensor:
-
name: “Perimeter Sensors Health Issue”
device_class: problem
state: >
{% set threshold_contact = 8 * 3600 %}
{% set threshold_presence = 30 * 60 %}
{% set ns = namespace(stale=false) %}
{# Check Contact Sensors #}
{% for entity_id in area_entities(‘Perimeter’) if entity_id.startswith(‘binary_sensor.’) and ‘contact’ in entity_id %}
{% set s = states[entity_id] %}
{% if s is defined %}
{% if s.state in [‘unavailable’, ‘unknown’] %}
{% set ns.stale = true %}
{% elif (now() - s.last_reported).total_seconds() > threshold_contact %}
{% set ns.stale = true %}
{% endif %}
{% endif %}
{% endfor %}
{# Check Presence / Occupancy #}
{% for entity_id in area_entities(‘House’) if entity_id.startswith(‘binary_sensor.’) and ‘occupancy’ in entity_id %}
{% set s = states[entity_id] %}
{% if s is defined %}
{% if s.state in [‘unavailable’, ‘unknown’] %}
{% set ns.stale = true %}
{% elif (now() - s.last_reported).total_seconds() > threshold_presence %}
{% set ns.stale = true %}
{% endif %}
{% endif %}
{% endfor %}
{{ ns.stale }}`
3. LED Indicator Behavior (Preventing Alarm Fatigue)
If a sensor goes stale at 3:00 AM, you do not want an aggressive flashing light or bright amber glow illuminating the entryway all night. The exit indicator should be gated by intent .
A. Multi-State Color Logic
Instead of a binary Green/Red, reserve distinct color patterns for ambiguity:
-
Green (Solid): All contacts confirmed closed , all target zones confirmed clear , all health checks pass.
-
Red (Solid or Slow Pulse): Confirmed issue — an active open contact or confirmed room occupancy.
-
Amber / Yellow (Slow Breathe / Pulse): Degraded / Unknown State. At least one sensor is stale,unavailable, or unconfirmed. It signals: “The house cannot confirm total closure.”
-
Off: Default resting state when no one is near the exit.
B. Context-Aware Gating (Avoiding False Alarms)
Do not keep the LED illuminated continuously:
-
Trigger on Exit Intent: Activate the LED strip/light only when presence is detected in the immediate foyer/front door transition zone, or when the front door deadbolt is unlocked.
-
Grace Periods for Delayed Packets: Before marking a sensor “stale” on the LED display, require that it fail its heartbeat by at least $1.5\times$ to $2\times$ its expected check-in interval to prevent transient mesh congestion from tripping amber lights.
-
Dashboard Visibility: Pair the amber LED with a persistent, conditional entity card on your exit dashboard that lists the exact offending sensor (e.g., “Basement Window: No check-in for 9h” ), so you can instantly verify whether it’s an actual security risk or just an aged coin-cell battery.
The separate amber/unknown state makes sense. One caveat with the HA template: last_reported records when an integration writes an entity state, not necessarily the sensor’s last packet; HA’s state-object docs note that some integrations do not rewrite unchanged values. I would check the actual reporting behavior of each device/integration before treating the 8-hour and 30-minute thresholds as health guarantees, and show which sensor’s freshness is unverified.