Beyond Occupancy: Designing a Resilient Spatial Presence System in Home Assistant

Edit — 2026-11-28: Added a link to the companion article, Beyond Occupancy: Design Retrospective — How the Architecture Evolved.

Edit — 2026-11-26: All three parts are finally available. My first post had to go through manual moderation, so the article itself ended up spending some time in an incomplete state.
I’ve also moved the topic to the Share your Projects! category, added links to the table of contents and cross-references throughout the article, and made some minor formatting adjustments for better readability.


Introduction

This is my first article sharing my smart home experience, and hopefully the first of many. Please go easy on me!

This article was prepared with the assistance of ChatGPT in organizing, writing, and translating my ideas.

What happens when a presence sensor is wrong?

Most presence-based automations assume that the sensor provides a sufficiently reliable representation of whether a room is occupied. When that assumption fails, we usually adjust sensitivity, extend occupancy timeouts, add more sensors, or introduce additional conditions to individual automations. I started with those approaches too.

Over time, however, I ended up building a presence system that separates sensor observations, spatial inference, internal state memory, and the effective presence used by device controllers. The system uses the physical layout of my home to evaluate whether occupancy transitions are plausible. It can actively refresh questionable sensor observations, temporarily change its output policy without destroying internal state, and recover from system interruptions or unusual operating conditions.

This article describes how and why I developed these mechanisms, the problems they address, and the limitations that remain. It is not a step-by-step installation guide. Instead of sharing configuration files specific to my home, I want to explain the underlying architecture so that individual mechanisms can be adapted to different homes, sensors, and automation requirements.

For a shorter account of how this architecture emerged, including the earlier approaches, design decisions, and mechanisms that were eventually removed, see Beyond Occupancy: Design Retrospective — How the Architecture Evolved.

Due to the forum’s character limit, this article is divided into three consecutive posts within the same topic. The table of contents below covers all three parts.

Table of Contents

Part I — The Problem and Core Architecture
1. Why Presence Detection Is Still a Problem
2. System Overview: Observation, State, and Output
3. Filtered Presence: Handling Unreliable Observations
4. Spatial Presence: Giving Occupancy a Memory

Part II — Error Handling and Recovery
5. Active Refresh: Asking the Sensor to Observe Again
6. Presence Fallback: Retaining Memory Without Getting Stuck
* 6.5 Quiet Mode (Optional)
7. Bypass: When the Normal Spatial Model Does Not Apply
8. Rebuilding: Recovering Without Resetting Everything

Part III — Application and Design Review
9. Extending the Model Across Spatial Scales (Optional)
10. Putting the System Together
11. Limitations, Adaptability, and Observability
12. Conclusion

Suggested Reading Paths

This is a fairly long article, and not every section will be relevant to everyone.

If you are interested in… Suggested sections
Understanding the overall architecture 1, 2, 10
Preventing false detections and unexpected lights-off 3, 4, 6
Using spatial relationships to infer occupancy 4
Recovering stuck mmWave sensors 3.3, 5
Handling robot vacuums 7, 8
Recovering from HA or Z2M interruptions 3.2, 8
Combining rooms or determining whole-home occupancy 9
Practical timing parameters 10.3
Adapting the system to PIR sensors 11.2
Troubleshooting and manual recovery 11.3, 11.4
Understanding the overall design philosophy 2, 10, 12

1. Why Presence Detection Is Still a Problem

Presence detection is probably one of the most fundamental functions of a smart home. It is also one of the hardest to get right. With mmWave presence sensors becoming increasingly accessible, detecting someone sitting on a sofa, working at a desk, or lying in bed is no longer as difficult as it was with traditional PIR motion sensors. At least in theory.

In practice, I still encountered several problems:

  • Lights turning off while I was sitting quietly in a room.
  • Sensors reporting presence long after I had left.
  • Curtains, fans, and robot vacuums triggering presence detection.
  • Sensor states becoming unavailable during system interruptions.
  • Different rooms producing inconsistent presence states as I moved between them.

Some of these problems can be mitigated by adjusting sensor sensitivity, detection range, or occupancy timeout. However, tuning these parameters only gets you so far. At some point, I started questioning whether the problem was actually the sensor itself, or how I was using its output.

A sensor reporting presence is not the same as a room being occupied.

One is an observation. The other is a state that we infer from available information. That distinction eventually became the foundation of my presence system.

Consider a typical presence-based lighting automation. When the sensor detects someone, the lights turn on. When it stops detecting someone, the lights turn off after a delay. If the lights occasionally turn off while someone is still in the room, the usual solution is to increase the delay.

But how long should that delay be? A longer delay helps prevent false offs, but it also makes the system slower to respond when someone actually leaves. These are two different situations with two different requirements.

Situation Desired behavior
Someone is still in the room, but the sensor misses them Retain presence for as long as necessary
Someone has actually left the room Clear presence as soon as reasonably possible

A single time parameter cannot reliably satisfy both requirements. Increasing the delay does not improve the system’s understanding of whether someone has left. It simply postpones the consequences of that decision.

The Off-Delay Trade-off

Instead of continuing to adjust the delay, I wanted to find another way to distinguish these situations. The physical layout of my home turned out to be useful information.


2. System Overview: Observation, State, and Output

My smart home runs on Home Assistant, with Zigbee2MQTT (Z2M) managing most of my Zigbee sensors. The SONOFF SNZB-06P is my primary presence sensor.

Over time, my presence system evolved into three main layers:

  • Filtered Presence (F): the sensor observation after filtering and validity checks.

  • Internal Presence (IP): the remembered occupancy state, maintained using spatial evidence.

  • Effective Presence (EP): the presence state actually used by downstream device controllers.

The main information flow is:

F can also provide EP directly when Fallback or Bypass is active. In addition, the relationship between F and IP provides feedback to the sensor refresh mechanism. Each layer answers a different question.

Layer Question
Raw Presence What is the sensor reporting?
Filtered Presence What observation can currently be used?
Internal Presence What occupancy state should the system remember?
Effective Presence What presence state should downstream controllers use right now?

I did not start with this architecture. Each layer was introduced to solve a problem that the previous design could not adequately handle. The important part is that these states do not always have to agree. Separating them allows the system to handle uncertainty, exceptions, and recovery without making every device automation responsible for those problems.

Sections 3 and 4 describe the observation and inference layers. Sections 5–8 explain how the system handles errors, exceptions, and recovery.


3. Filtered Presence: Handling Unreliable Observations

3.1 Known Interference

One advantage of building presence detection within a smart home system is that the system already knows about many of the activities that might interfere with its sensors. For example, when an automated curtain starts moving, Home Assistant knows that the curtain is moving. If testing confirms that this movement affects a nearby presence sensor, I can account for that interference before the sensor output reaches the rest of the system.

This is one of the purposes of Filtered Presence. Rather than adding curtain-related exceptions to every lighting or HVAC automation, I handle confirmed interference at the observation layer. I use a noise window to represent periods during which sensor observations may be affected by known activities.

During these periods, F can retain its previous state instead of accepting potentially unreliable changes from Raw. I refer to this behavior as Freeze.

F is not intended to eliminate every possible false detection. It deals with conditions that the system already knows can make an observation unreliable. Unknown false positives and missed detections are handled separately.

3.2 Unavailable Does Not Mean Unoccupied

Another problem comes from the architecture of Home Assistant and Zigbee2MQTT.

Home Assistant and Z2M can restart independently. Communication between them can also be interrupted. When Z2M goes offline, sensor entities in Home Assistant may become unavailable. Consider a simple Home Assistant template:

{{ is_state('binary_sensor.presence', 'on') }}

If the sensor becomes unavailable, this expression returns False. But that does not mean the sensor has detected an empty room. It means the system cannot currently obtain the observation. If that result is directly used for device control, a Z2M interruption could cause lights to turn off throughout the home. To avoid this, F also uses Freeze when reliable observations are unavailable.

Strategy Implicit assumption
Force Off No observation means nobody is present
Force On No observation means someone is present
Freeze No reliable new observation is available

Freezing does not guarantee that the retained state is still correct. Someone could move between rooms while the system is offline. However, it prevents a communication failure from being interpreted as a physical change in occupancy. It also creates another requirement: when communication is restored, the system needs a way to recover from potentially outdated states. This recovery process is addressed in Section 8.1.

3.3 Refresh Can Also Introduce Unreliable Observations

As described in Section 5, my system can actively refresh a presence sensor by temporarily changing its sensitivity. In my experience with the SNZB-06P, this operation generally causes Raw Presence to return to Off before the sensor begins detecting again. This is useful when a sensor is stuck in the On state. However, it can also temporarily produce an Off observation while someone is actually in the room.

Without additional handling, the refresh mechanism could introduce the same kind of unwanted state transition that it is intended to help prevent. I therefore include the refresh script’s execution period in the noise window. In my current implementation, this period lasts approximately 12 seconds. During that period, F is frozen and retains its previous state. Once the refresh operation is complete, F resumes accepting observations.

This means the system can actively intervene in the sensor’s detection process without immediately propagating the temporary effects of that intervention. The same filtering mechanism handles both environmental interference and interference introduced by the system’s own recovery operations.

3.4 The Responsibility of Filtered Presence

The general filtering logic can be summarized as follows:

Short filtering delays can also be applied to suppress brief changes.

Condition F behavior
Normal sensor operation Accept Raw with configured filtering
Confirmed environmental interference Freeze during the noise window
Active sensor refresh Freeze during the refresh window
Z2M unavailable or system not ready Freeze until observations become usable

The purpose of F is not to determine whether a room is occupied. Its purpose is to provide a usable observation to the rest of the system.


4. Spatial Presence: Giving Occupancy a Memory

Even after filtering known interference and handling unavailable states, F can still be wrong. A sensor can detect something that is not a person, or fail to detect someone who is still in the room. Instead of trying to eliminate every sensor error, I wanted to control when an observation was allowed to change the remembered occupancy state.

4.1 Rooms Are Connected Spaces

A home is not simply a collection of independent sensor coverage areas. Rooms are connected through doors, corridors, and open spaces. People generally need to move through these connections to enter or leave a room.

Suppose someone is inside a bedroom and the door remains closed. If the presence sensor suddenly reports Off, there is no additional evidence that the person has actually left the room. The opposite situation is also worth considering. If an empty room suddenly reports presence while its door has remained closed, that observation may be a false positive.

The layout of the home provides information about whether an occupancy transition is physically plausible.

For example:

The spatial relationships do not prove that someone has entered or left, but they give the system something more than the presence sensor alone.

4.2 Door Sensors as Transition Evidence

In my system, door sensors (DRS) are not used as presence sensors. They provide information about the possibility of movement across a spatial boundary.

Door state What it tells the system
Open Movement across the boundary is possible
Closed Movement across the boundary is normally restricted
Recently opened Movement may have occurred recently

A door opening does not prove that someone has passed through it. It does not indicate direction or the number of people involved. For this reason, I also use activity in adjacent spaces as additional evidence. If someone has entered or left a room, there is a reasonable chance that the movement also produces a presence observation in an adjacent space.

4.3 Adjacent Source

Not every occupied adjacent room should continuously provide transition evidence. For example, someone working in a bedroom with the door closed should not continuously provide evidence that people may be entering or leaving the living room. To address this, I introduced an entity called Adjacent Source.

For a typical room with a door:

Adjacent Source = EP AND Door Open

For an open space without a door:

Adjacent Source = EP


Room presence Door Adjacent Source
Off Closed Off
Off Open Off
On Closed Off
On Open On

This allows each space to expose its own usable transition evidence without requiring every neighboring space to understand its internal configuration. It also avoids treating occupancy behind a closed spatial boundary as continuously available evidence of movement.

4.4 Recent Windows

Physical movement, door events, and presence sensor updates do not happen at exactly the same time. Someone might leave a bedroom, close the door, and walk through the corridor before the bedroom sensor finally reports Off. By that time, both the door and the adjacent presence sensor might no longer provide active evidence.

To accommodate these timing differences, I introduced two types of recent windows:

  • Door Recent Window
  • Adjacent Recent Window

These windows retain evidence from recent events for a configurable period.

For example:

A recent window is different from an off delay. It does not keep a device running for a fixed period. It preserves the relevance of an event so that subsequent observations can still be evaluated against it.

The appropriate duration depends on the physical layout, sensor occupancy timeout, and actual reporting behavior. My representative timing parameters are provided in Section 10.3.

4.5 Allow to Change

Different rooms have different spatial configurations. Some have doors, some are open spaces, and some connect to multiple adjacent areas. Rather than making a generic state machine understand every possible room configuration, I encapsulate the spatial conditions in a Boolean entity called Allow to Change.

For a typical room with a door:

Spatial Evidence and Recent Windows


This is not a universal rule for every room. An entrance, corridor, or open living area may require different conditions. The state machine does not need to know how Allow is calculated. It only needs to know whether a transition is currently permitted. This keeps the spatial configuration separate from the state transition logic.

4.6 Internal Presence as a State Machine

The actual state machine is quite simple. It evaluates IP when either of the following occurs:

  • F changes to a valid On or Off state.
  • Allow to Change becomes On.

The second trigger is important because transition evidence and sensor observations do not necessarily arrive in the expected order.

At each evaluation:

Current IP F Allow Resulting IP
Off On On On
Off On Off Off
On Off On Off
On Off Off On
On On Either On
Off Off Either Off

This handles two different sensor problems.

IP Off, F On

The sensor reports activity, but there is no supporting transition evidence. IP remains Off, preventing a potential false positive or non-human activity from reaching downstream controllers. If Allow subsequently becomes On, IP can accept the existing F On observation. F does not need to change again.

IP On, F Off

The sensor stops detecting activity, but there is no supporting departure evidence. IP remains On, preventing a temporary missed detection from turning off devices. If valid departure evidence subsequently becomes available while F remains Off, IP can change to Off.

Unlike a conventional off delay, IP is retained because the system lacks sufficient transition evidence, not simply because a timer has not expired.

Conventional Off Delay Spatial State Machine
State retention Fixed duration Until an eligible transition
Transition evidence Sensor and time Sensor and spatial context
Normal departure Waits for delay Can respond when evidence is available
Main limitation Delay duration trade-off Incomplete transition evidence

The state machine does not make the sensor more accurate. It makes the system less dependent on every individual sensor update being correct. However, it also introduces another problem: F and IP can remain inconsistent. The two directions of inconsistency are addressed differently, as described in Section 5 and Section 6.


Part 2


5. Active Refresh: Asking the Sensor to Observe Again

5.1 Using Inferred State as Feedback

When IP is Off and F is On without valid transition evidence, the state machine can prevent the observation from affecting downstream devices. This does not mean Refresh is required for the presence system to continue operating. If someone subsequently enters the room and Allow becomes On, IP can accept the existing F On observation.

However, a sensor that remains incorrectly On is still a problem. It provides less useful information about subsequent activity and may continue reporting an occupied room long after it has become empty. I therefore use the inferred occupancy state as feedback to identify observations that may deserve another look.

The purpose of Refresh is not to force IP and F to agree. It is to improve the underlying observation when the relationship between F, IP, and the spatial context suggests that the sensor may be wrong. The state machine and Refresh remain separate processes.

Process Responsibility
State Machine Determine whether IP should accept F
Refresh Attempt to improve a questionable sensor observation

While experimenting with the SNZB-06P, I found that temporarily changing its sensitivity and then restoring the original setting could sometimes resolve persistent false detections. I call this operation a Sensitivity Bump.

5.2 Sensitivity Bump

The operation consists of three steps:


In my setup, the sensitivity change is maintained for approximately five seconds. The complete refresh script takes around 12 seconds, including the additional waiting periods.

This serves a different purpose from requesting the current occupancy state through MQTT /get. A state request may help if the problem is related to reporting or communication. However, if the sensor itself still believes the room is occupied, reading its current state again may simply return the same incorrect result.

A Sensitivity Bump attempts to influence the sensor’s detection process. In my experience, Raw generally returns to Off during the operation and then begins detecting again.

I do not know exactly what happens inside the sensor firmware when its sensitivity changes. I only know that the operation has helped resolve certain persistent detection problems in my setup. It is an empirical workaround, not a guaranteed sensor reset. As explained in Section 3.3, F is frozen during the refresh script so that temporary changes in Raw do not immediately affect the rest of the system.

5.3 Separating Refresh Execution from Refresh Strategy

I use a reusable script blueprint to implement the Sensitivity Bump. Each room has a refresh entry point configured for its own sensor. Higher-level automations decide when to call that entry point.

This means I can independently modify how a sensor is refreshed and when it should be refreshed. The execution mechanism can remain the same even when new refresh strategies are introduced.

5.4 Different Refresh Strategies

Not every refresh is triggered for the same reason.

Strategy Purpose
Conflict Refresh Re-observe a sensor when IP Off / F On persists
Stale Refresh Re-evaluate observations that may no longer be reliable
Door Refresh Re-observe after relevant boundary events
Adjacent Refresh Re-observe in response to relevant neighboring activity
Environmental Refresh Re-observe after known interference ends
Global Refresh Coordinate re-observation across multiple spaces
Manual Refresh Allow the user to investigate an unexpected sensor state

Conflict Refresh and Stale Refresh are particularly important to distinguish. Conflict Refresh responds to an inconsistency between F and IP. Stale Refresh does not necessarily require such an inconsistency. Both F and IP could be On, while the surrounding spatial conditions suggest that the sensor observation deserves another look.

For example, activity in another room combined with the absence of valid transition conditions in the current room can help identify a potentially stale detection. The refresh strategies can have different waiting periods, eligibility conditions, retry intervals, and execution limits. Some are immediate event-driven operations. Others monitor a persistent condition and retry when necessary.

I have also considered unconditional periodic refresh, but it is not my preferred approach. Refreshing a sensor can itself introduce temporary state changes. Even with a noise window, there is little reason to continuously intervene when the system is operating normally.

5.5 When Refresh Does Not Work

Sensitivity Bump does not resolve every persistent detection problem. For a continuing conflict, the system can perform a limited number of refresh attempts. If the inconsistency remains, it eventually notifies the user. There is no guaranteed automatic sensor repair beyond that point.

The system cannot conclusively determine whether the sensor is wrong or the remembered occupancy state is wrong simply by observing their disagreement. Forcing them to agree could introduce a different error. Repeatedly refreshing the sensor without a limit would also be undesirable. This is an intentional limitation of the system. It attempts recovery where possible, but stops when it no longer has a reliable way to improve the observation.

Manual recovery options are discussed in Section 11.4.


6. Presence Fallback: Retaining Memory Without Getting Stuck

The opposite inconsistency, IP On and F Off, requires a different strategy. In this case, retaining IP is exactly what I want the state machine to do when a sensor temporarily misses someone. However, the same mechanism can also retain IP when someone has actually left but the system failed to obtain valid departure evidence.

6.1 Spatial Evidence Can Be Missed

The state machine depends on the availability and timing of spatial evidence.

There are several ways this can fail:

  • Someone moves faster than the sensor’s occupancy timeout.
  • Adjacent presence disappears too early.
  • A recent window expires before F changes.
  • A sensor misses activity in a transition area.
  • Neighboring spaces create dependencies that prevent a valid transition.

In these situations, IP can remain On even after the room becomes empty. Without an additional mechanism, that state could continue indefinitely.

6.2 Why Not Simply Clear IP After a Timeout?

A straightforward solution would be to force IP Off after F has remained Off for a certain period. But consider what happens if someone is actually still in the room.

Once IP has been forcibly cleared, the next F On observation may not have valid transition evidence. The door has not opened, and there may be no adjacent activity. The state machine could therefore reject the new observation. By clearing IP, the system has destroyed the memory that was originally intended to protect against missed detection.

I wanted to limit the effect of stale IP without necessarily changing IP itself. This is why Effective Presence exists.

6.3 Effective Presence and Fallback

Under normal conditions, EP follows IP. When Fallback is enabled, EP follows F instead.

Non-destructive Fallback

When IP remains On while F remains Off beyond a configurable threshold, Fallback can be activated. IP continues to remember the previous occupied state, but EP is now allowed to follow the current observation. Downstream devices can turn off without the system clearing its internal memory.

Stage IP F Fallback EP
Normal occupancy On On Off On
Missed detection or missed departure On Off Off On
Persistent inconsistency On Off On Off
Presence detected again On On On On
Alignment confirmed On On Off On

If F later returns to On, EP immediately follows it, even if there is no new Allow to Change. F and IP are now aligned, so Fallback can be disabled and EP can return to IP.

Recovery can also occur if the state machine obtains valid departure evidence and changes IP to Off while F is already Off. In either case, F and IP naturally converge. The system does not need to force a state transition just to exit Fallback.

Forced IP Timeout Presence Fallback
Persistent F Off Clears IP Changes EP source
Original memory Lost Retained
Subsequent F On May require Allow EP can recover directly
Recovery Rebuild IP Wait for alignment
Modifies internal state Yes No

This is one of the most useful consequences of separating internal state from effective output.

6.4 Redistributing the Responsibility of Time Delays

The system still uses time delays. However, they no longer serve exactly the same purpose as a conventional off delay.

A conventional approach treats all F Off events in the same way:

When valid departure evidence exists, the state machine can accept the observation without waiting for the Fallback threshold. Only when the transition cannot be established does the longer time threshold become relevant.

A five-minute Fallback threshold is therefore not equivalent to a five-minute lighting off delay. One limits the impact of a persistent inconsistency. The other delays every departure. This allows me to retain occupancy during temporary missed detection without unnecessarily slowing down normal departure detection.

6.5 Quiet Mode (Optional)

Even a persistent F Off is not always a good reason to activate Fallback. During sleep or other low-activity periods, a sensor may repeatedly or continuously miss someone who is still in the room. In these situations, the remembered occupancy state can be more useful than the current observation. I therefore use Quiet Mode as an optional additional condition for automatic Fallback activation.

Automatic Fallback Entry:

    IP is On
    AND F is Off
    AND Quiet Mode is Off
    AND the condition persists for the configured duration

Quiet Mode does not force presence On. It does not create a separate occupancy state machine either. It simply prevents a particular recovery policy from overriding the remembered state under circumstances where missed detection is expected.

Context Fallback behavior
Normal operation Persistent IP On / F Off can activate Fallback
Quiet Mode Normal automatic Fallback entry is inhibited
Existing Fallback Can still exit through state alignment
Explicit system rebuilding Fallback can be activated by the recovery process

The state machine itself remains unchanged. Quiet Mode is not required to implement Spatial Presence. It is an extension for situations where long periods of limited human movement are expected. The same Fallback mechanism is also used during system rebuilding, as described in Section 8.


7. Bypass: When the Normal Spatial Model Does Not Apply

The spatial state machine is based on assumptions about human movement. However, not all activity in a smart home comes from humans, and ordinary presence sensors cannot reliably distinguish between human and non-human movement. Robot vacuums are a particularly useful example.

7.1 Robot Vacuums and the Problem of Activity Origin

A robot vacuum can start cleaning while nobody is home. Unlike a person entering the home, the robot does not arrive through the entrance or necessarily move into its first cleaning area from an adjacent space. It starts moving from its dock. From the perspective of the spatial state machine, activity has effectively appeared inside a previously empty space. The sensor may correctly detect that movement, but the spatial model has no corresponding human entry evidence.

Under the normal Conflict Refresh policy, the system could interpret this as a questionable sensor observation. It may refresh the sensor repeatedly, but the robot is still moving. The sensor will continue detecting activity. Eventually, the system could generate unnecessary notifications.

Stage Normal inference behavior
Robot leaves dock F detects activity
No valid transition evidence IP retains Off
Persistent inconsistency Conflict Refresh becomes eligible
Robot continues moving Refresh does not eliminate detection
Retry limit reached Unnecessary fault notification

The problem is not necessarily that the sensor is wrong. The problem is that a valid observation is being evaluated using an inappropriate movement model.

7.2 Context-Specific Bypass

When the robot vacuum is away from its dock, I allow the relevant effective presence states to follow F instead of IP. I also bypass the normal conflict handling that would otherwise treat robot-generated movement as a sensor problem.

This serves two purposes:

  • Avoid inappropriate refresh attempts and fault notifications caused by expected robot activity.
  • Allow downstream devices to respond to detected activity when useful.

For example, presence-based lighting can provide illumination to a robot vacuum cleaning a dark room. The lighting assistance is a useful consequence of the Bypass policy, rather than the primary reason for introducing it.

Both Fallback and Bypass can make EP follow F, but they exist for different reasons.

Mechanism Reason Purpose
Fallback Persistent inconsistency Limit the impact of stale internal state
Bypass Known operating context Temporarily use a more appropriate output policy

The general output selection can be expressed as:

IF Bypass OR Fallback:
    EP = F
ELSE:
    EP = IP

The exact bypass conditions can remain specific to each space or control requirement. There is no need to incorporate all these exceptions into the generic state machine. This also illustrates why EP should not necessarily be interpreted as a strict representation of human occupancy. EP is the effective presence signal used for a particular control purpose.

7.3 Returning from Bypass

Starting the robot is only half of the problem. The other half is ensuring that the system converges correctly when cleaning ends.

Consider a robot cleaning an empty home. During cleaning, sensor observations and remembered occupancy states may change. Someone could also leave the home while cleaning is already in progress. When the robot returns to its dock, immediately switching EP back to IP could expose internal states that no longer represent the current situation.

I therefore use the completion of robot activity as an opportunity to re-evaluate presence. Once the relevant robots have remained docked for a configured period, the system initiates presence re-evaluation and provides the appropriate transition eligibility for House Presence.

The objective is to allow the system to return to a consistent state even when cleaning begins and ends while nobody is home. The recovery process is shared with other rebuilding scenarios and is described in Sections 8.2–8.4. The application of transition evidence at the whole-home scale is discussed in Section 9.2.


8. Rebuilding: Recovering Without Resetting Everything

8.1 System Initialization

As described in Section 3.2, when Z2M is offline or the system is not ready, F retains its previous observation. Once Z2M reconnects, the system needs to allow time for sensor information to become usable again.

There are two separate recovery problems:

  1. When should F resume accepting observations?
  2. How should existing IP states be reconciled with those observations?

My initialization process handles these separately.

By enabling Fallback before normal observation updates resume, the system can use newly available observations without requiring every internal state to be corrected first. IP remains under the control of the normal state machine.

The initialization delay in my setup is 30 seconds. This is not a guarantee that every sensor has produced a new observation. It is a stabilization period before normal observation updates resume.

8.2 Whole-Home Presence Evaluation

Another situation that benefits from explicit re-evaluation is leaving the home. Sometimes, individual rooms retain occupancy states after everyone has left.

My initial approach was to clear all internal presence states. However, this could interfere with transitions that were still in progress. For example, manually clearing the entrance IP while someone is still standing at the entrance does not necessarily produce a new F or Allow event that would restore it. I eventually replaced the destructive reset approach with a whole-home evaluation process.

The system enables Fallback across the relevant spaces and establishes an evaluation window. Sensor refresh can also be coordinated as part of the wider re-evaluation process where appropriate. This allows F to provide effective output while IP continues to be maintained by its state machine. My current evaluation window is 30 seconds.

If a room’s F and IP align before the evaluation window ends, its Fallback can exit early. There is no requirement for every room to remain in Fallback for the entire duration.

8.3 Presence Rebuilding

System initialization, whole-home evaluation, and recovery after robot vacuum activity have different triggers. However, they share a common requirement: existing internal states may no longer be reliable enough to immediately resume normal output. I represent this shared recovery phase using a Presence Rebuilding state.

Conceptually:

Presence Rebuilding =
    NOT System Ready
    OR Presence Evaluating

This provides a common recovery lifecycle without requiring the individual room state machines to understand why rebuilding was initiated.

The mechanisms that initiate rebuilding can remain independent. The reconciliation mechanism does not need to distinguish whether the system has recovered from a communication interruption, completed robot cleaning, or initiated a whole-home evaluation.

8.4 Reconciliation

Normally, Fallback exits when F and IP become aligned. However, when Fallback is explicitly enabled during initialization or evaluation, some rooms may already have matching F and IP states. In an event-driven system, there may be no new alignment event to trigger Fallback exit. An explicit reconciliation check addresses this.

After rebuilding ends and the system has had time to stabilize:

IF F and IP are valid and equal:
    Disable Fallback
ELSE:
    Retain the existing Fallback state

This check does not modify IP. It also does not require the system to remember which process originally enabled Fallback.

F IP Reconciliation result
Off Off Disable Fallback
On On Disable Fallback
Off On Retain existing Fallback
On Off Retain existing Fallback
Invalid Any Do not reconcile

In my setup, the reconciliation check occurs after Presence Rebuilding has remained Off for 30 seconds. The evaluation timer is not intended to enforce Fallback for a fixed duration. Its purpose is to provide an explicit reconciliation opportunity after the evaluation process.

Rooms that recover earlier can exit earlier. Rooms that remain inconsistent can continue using Fallback until they recover naturally.


Part 3


9. Extending the Model Across Spatial Scales (Optional)

A presence zone does not necessarily have to correspond to an individual room. This section describes how I apply the same design principles to connected living spaces and the entire home.

9.1 Living and Dining Areas

My living and dining areas are physically connected. They have separate lighting and other device control requirements, but there is no clear physical boundary between them.

Initially, I maintained separate spatial presence state machines for both areas. This created an unnecessary dependency: the disappearance of presence in one area could remove transition evidence required by the other.

I could have addressed this by extending recent windows or adding more exceptions. Instead, I reconsidered whether the two areas actually needed separate inferred occupancy states.

Combining the two sensor observations into a shared Living Area Presence removes the need for unnecessary transition restrictions between these spaces. Individual observations can still be retained where finer-grained information is useful. The lighting and other device controllers can also retain their own illuminance thresholds, operating modes, and local conditions. This distinction is important:

Spatial unit Purpose
Sensor coverage area Where an observation originates
Presence zone Where an occupancy state is evaluated
Device control zone Where a particular control policy applies

These units do not necessarily need to match. Sometimes, the best way to resolve a complicated state dependency is to reconsider whether the underlying spatial distinction is useful at all.

9.2 House Presence

The same design philosophy can be applied at the scale of the entire home. Instead of using a single sensor observation, House Presence can aggregate observations from multiple spaces. The main physical boundary is the entrance door.

If all room observations temporarily disappear while the entrance door has not provided departure evidence, the home does not necessarily need to be considered empty.

Design element Room Scale House Scale
Observation Local presence sensors Aggregated spatial observations
Boundary Room door or adjacent space Entrance
Transition Entering or leaving a room Arriving or leaving home
Memory Room occupancy Home occupancy
Recovery Local refresh and Fallback Whole-home evaluation

Robot vacuum activity introduces an additional consideration. Someone may leave the home while the robot is cleaning. The entrance event provides departure evidence, but the aggregated sensor observations may continue indicating activity because of the robot. By the time cleaning ends, the original departure evidence may no longer be available. Allowing House Presence to be re-evaluated when the robot has returned to its dock addresses this problem.

This does not mean that the robot docking event proves someone has left. It simply provides a justified opportunity to reconsider the existing House Presence state after an exceptional operating context ends. The implementation does not have to be identical at both spatial scales. What is reusable is the distinction between observation, spatial transition evidence, remembered state, and effective output.


10. Putting the System Together

Looking back at the development of this system, almost every additional mechanism was introduced to address a limitation of an earlier one. Filtering handles known unreliable observations, but cannot eliminate unknown sensor errors. The spatial state machine handles those errors, but can retain outdated states. Refresh attempts to improve questionable observations, but cannot guarantee recovery.

Fallback limits the impact of stale memory without clearing it. EP provides a common output interface that makes Fallback, Bypass, and system recovery possible without repeatedly modifying the state machine.

10.1 Problems, Causes, and Responses

Problem Cause Design response
Known false detection Automated equipment interference Raw to F filtering
Unexpected device shutdown Unavailable interpreted as Off Freeze / System Ready
Temporary changes during refresh Sensor re-observation process Refresh Noise Window
False occupancy Sensor error or non-human activity Restrict IP On transitions
False vacancy Missed detection during inactivity Restrict IP Off transitions
Persistent false detection Sensor state or environmental interference Active Refresh
Refresh fails repeatedly Limited sensor recovery capability Bounded retries / Notification
Occupancy remains after departure Missing spatial evidence Fallback
Presence returns without transition evidence Retained IP during Fallback F-driven EP / Natural recovery
Persistent missed detection during rest Low human activity Optional Quiet Mode
Unexpected activity origin Robot starts from its dock Context-specific Bypass
Unnecessary conflict notifications Human inference applied to robot activity Bypass conflict handling
Potentially outdated internal states Initialization or context change Rebuilding / Reconciliation
Unnecessary spatial dependencies Presence zones defined too narrowly Redefine spatial scale
State inference cannot converge Insufficient or mutually dependent evidence Manual IP correction

10.2 Asymmetric Handling of Inconsistent States

The two directions of F/IP inconsistency represent different problems and should not necessarily be handled in the same way.

IP F Interpretation Primary strategy
Off Off Consistent vacancy Retain
On On Consistent occupancy Retain
Off On Possible false positive or missed entry evidence Retain IP / Consider Refresh
On Off Possible missed detection or missed departure evidence Retain IP / Fallback

For IP Off and F On, the state machine protects downstream devices from potentially incorrect observations. The inconsistency also provides feedback that can be used to identify a sensor that may benefit from Refresh.

For IP On and F Off, the system first preserves memory and eventually changes the effective output source if the inconsistency persists. There is no need to use Refresh to resolve the second type of inconsistency. Both types can also resolve naturally when valid transition evidence becomes available.

Fig. Asymmetric Conflict Handling

The distinction is not simply between turning devices on and off. It is between improving an observation, retaining useful memory, and limiting the consequences of an unresolved inconsistency.

10.3 Different Time Parameters Serve Different Purposes

The system still contains quite a few time parameters. The difference is that each one has a specific responsibility. The following are representative settings from my current implementation. They are provided as practical references, not universal recommendations.

Parameter Reference setting Responsibility
Sensor Occupancy Timeout 15 s Sensor-level vacancy detection
Filtered Presence Delay 2 s Suppress brief observation changes
Door Recent Window 30 s Preserve recent boundary evidence
Adjacent Recent Window 90 s Preserve recent neighboring activity
Sensitivity Bump Duration 5 s Active re-observation
Refresh Noise Window Approx. 12 s Protect F during sensor refresh
Refresh Trigger Delay Strategy-dependent Avoid premature intervention
Refresh Retry Interval Room-dependent; 30 s or longer suggested Allow time between refresh attempts
Refresh Retry Limit Strategy-dependent Prevent endless intervention
Fallback Entry 5 min Limit the impact of persistent inconsistency
Fallback Exit 1 s Confirm valid F/IP alignment
Z2M Initialization Delay 30 s Allow observations to recover
Evaluation Window 30 s Provide an opportunity for re-evaluation
Reconciliation Delay 30 s Check remaining aligned states

These values are not necessarily identical across every room. Presence behavior is influenced by many factors, including:

  • Sensor technology and firmware.
  • Sensor occupancy timeout.
  • Actual detection and reporting response.
  • Sensor placement and coverage.
  • Room size and spatial layout.
  • Typical movement patterns.
  • Environmental interference.
  • Communication latency.

For example, a recent window needs to accommodate the time difference between physical movement, door events, adjacent activity, and the sensor’s eventual Off report. A longer sensor occupancy timeout may require a longer recent window. However, making that window unnecessarily long can also allow unrelated activity to provide transition evidence.

Similarly, a refresh retry interval needs to allow enough time for the refresh operation to complete and for the sensor to produce a meaningful new observation. I generally suggest starting with a retry interval of at least 30 seconds and adjusting it according to the actual behavior of the sensor and room.

The Fallback threshold serves a different purpose. It determines how long the system tolerates a particular inconsistency, not how long every departure should take. The evaluation window and reconciliation delay are different again. They provide opportunities for the system to re-evaluate and reconcile existing states. These parameters should therefore be tuned according to their relationships and observed system behavior, rather than copied as fixed values.

The system does not eliminate time parameters. It gives each time parameter a specific responsibility.

10.4 Handling Exceptions at the Appropriate Layer

One of the most useful aspects of the architecture is that not every exception needs to be added to the same automation.

Situation Layer Mechanism
Known interference Observation Filter / Noise Window
Communication interruption Observation Freeze
Temporary refresh interference Observation Refresh Noise Window
Missing spatial evidence State Inference Retain IP
Persistent false detection Active Observation Refresh
Stale occupancy memory Output Selection Fallback
Low-activity context Recovery Policy Optional Quiet Mode
Robot vacuum activity Output and Recovery Policy Bypass
System recovery Recovery Lifecycle Rebuilding
Automatic recovery fails Human Intervention Notification / Manual Recovery

If the problem is with the observation, I handle it at the observation layer. If the problem is with the long-term effect of state memory, I handle it at the output layer. If a specific context requires a different policy, I do not necessarily need to change the normal inference rules. This is how I try to keep the system manageable despite the number of mechanisms involved.


11. Limitations, Adaptability, and Observability

11.1 Limitations

This system is not intended to accurately track every person in the home. It does not identify individuals, count occupants, or reconstruct their exact movement paths.

Door events and adjacent presence provide transition evidence, not proof of movement. Their usefulness can decrease in situations involving multiple occupants, doors that remain open for long periods, overlapping sensor coverage, or complex spatial layouts.

Sensitivity Bump is also device-dependent and does not guarantee recovery. Fallback still involves a trade-off. If someone remains undetected for long enough outside Quiet Mode, EP may eventually switch Off even though the room is occupied. Spatial dependencies can also create situations in which neighboring rooms fail to provide the evidence required by each other.

The architecture does not eliminate uncertainty. It limits where uncertainty affects the system and provides ways to recover from it.

11.2 Applicability Beyond mmWave Sensors

Although I primarily use mmWave sensors, the core architecture is not dependent on mmWave technology. The spatial state machine only requires an observation that can be represented as On or Off, together with appropriate transition evidence. Traditional PIR motion sensors can also be used. In fact, state memory may be particularly useful with PIR sensors because they cannot continuously detect stationary occupants.

Mechanism PIR mmWave
Filtered Presence Applicable Applicable
Freeze Applicable Applicable
Spatial State Machine Applicable Applicable
Door / Adjacent Evidence Applicable Applicable
Recent Windows Applicable Applicable
Internal State Memory Particularly useful Useful
Active Refresh Device-dependent; often unavailable Device-dependent
Fallback Applicable with careful policy selection Applicable
Bypass Context-dependent Context-dependent
Rebuilding Applicable Applicable

The main difference is how sensor observations should be interpreted. For a PIR sensor, F Off is a normal result when someone stops moving. It does not necessarily indicate a sensor problem. Consequently, applying the same Fallback threshold used for a mmWave sensor could reintroduce the problem of lights turning off while someone is still in the room. Active Refresh may also be unavailable or unnecessary, depending on the device.

The architecture can be adopted incrementally.

Adoption level Mechanisms
Basic observation handling Raw to F, filtering, Freeze
Spatial inference F, Allow, IP
Resilient output EP, Fallback
Active sensor recovery Refresh, retries, notification
Context-specific extensions Quiet Mode, Bypass
Shared recovery lifecycle Initialization, Evaluation, Reconciliation

Not every home needs every mechanism. For example, a PIR-based implementation in a room with a door may benefit from spatial state memory without requiring active sensor refresh. A simpler installation may only need the observation layer and a spatial state machine. The individual mechanisms should be selected according to the problems that actually need to be solved.

11.3 Making the System Observable

Separating F, IP, and EP would make troubleshooting difficult if only the final output were visible. My Home Assistant dashboard therefore exposes the different states, along with manual controls and history. The main presence card shows EP, while additional controls expose IP, F, and Fallback.

This helps distinguish several otherwise similar problems:

  • A sensor observation is incorrect.
  • A transition has been rejected.
  • Internal occupancy memory is outdated.
  • Fallback or Bypass is controlling the effective output.
  • A downstream controller is behaving unexpectedly despite correct presence information.

For example:

EP IP F Fallback Possible explanation
On On Off Off IP is protecting against missed detection
Off On Off On Fallback is limiting stale memory
Off Off On Off A potential false positive has been rejected
On Off On Off A context-specific Bypass may be active

State history is particularly useful because it shows not only whether presence changed, but which layer changed first and how the other layers responded. Observability is important when the system deliberately allows different states to disagree.

11.4 Manual State Recovery

Automatic recovery cannot resolve every possible spatial inference problem. For example, two adjacent spaces may lose the evidence required by each other, leaving their internal states unable to converge even though the sensors themselves are functioning correctly. Refreshing the sensors does not necessarily solve this problem.

I therefore expose IP directly in my presence dashboard and allow it to be manually toggled. This gives me a way to correct internal occupancy memory when the normal inference mechanism has reached its limits. The dashboard provides different manual recovery operations for different types of problems.

Manual action What it changes Intended use
Refresh sensor Raw observation Questionable or stuck sensor state
Toggle IP Remembered occupancy Incorrect or locked internal state
Toggle Fallback Effective output source Temporarily bypass unreliable memory
Global Re-evaluation Recovery context Multiple potentially outdated states

These operations are not interchangeable. Refreshing a sensor is an attempt to obtain better information. Toggling IP is a direct correction of the remembered state. Toggling Fallback changes which state is used by downstream controllers without necessarily correcting either state.

Global Re-evaluation provides an opportunity for multiple spaces to recover without manually clearing their internal states. A manual IP correction does not necessarily trigger a new state machine evaluation. Subsequent valid F and Allow events return control to the normal inference process. The limited refresh retries and notifications described in Section 5.5 are therefore not isolated troubleshooting features. They form part of a wider recovery strategy that recognizes when human intervention is appropriate.

I consider manual recovery an explicit part of the system rather than an improvised response to an unexplained failure.


12. Conclusion: Designing a System That Can Tolerate Errors

I did not initially intend to build a presence system with multiple state layers, spatial inference, active sensor refresh, Fallback, Bypass, and a shared recovery lifecycle. Most of these mechanisms emerged from trying to solve specific problems in my own home.

Filtering was introduced to handle known interference and unavailable sensor states. Spatial inference was introduced to prevent missed detections and false positives from immediately affecting devices. Refresh was introduced because rejecting a questionable observation did not necessarily improve the observation itself. Fallback was introduced because retaining state indefinitely could become a problem of its own.

Separating IP from EP then made it possible to handle additional operating contexts and system recovery without repeatedly changing the core state machine. Looking back, I would summarize the design principles as follows.

Principle Meaning
Observation is not state Sensor reports are evidence, not necessarily occupancy
Transition requires evidence State changes should have a reasonable basis
Memory matters Temporary missed detection should not automatically erase occupancy
Active observation Inferred states can help identify questionable observations
Memory without permanent lock-in Retained state should not indefinitely constrain device control
Non-destructive recovery Preserve useful state while recovering from inconsistency
Abstraction with local exceptions Reuse common semantics without forcing identical configurations
Bounded automation Recognize when automatic recovery has reached its limits

This is obviously more complicated than connecting a presence sensor directly to a light. For many homes, a reliable sensor and a reasonable off delay may already provide a perfectly satisfactory experience. I do not think every smart home needs this architecture, or every mechanism described in this article.

For my own home, however, separating these responsibilities has made the system easier to extend and maintain. New requirements do not always require new state machines. Often, they only require a different observation condition, an additional refresh trigger, or a different output policy.

More importantly, the system no longer depends on the assumption that every sensor observation and every inferred state must always be correct. Observations can be wrong. Spatial evidence can be missed. Internal states can become outdated. Different layers can temporarily disagree. What matters is whether the system can continue operating, limit the consequences of those errors, and recover when better information becomes available.

The goal is not to build a presence system that never makes mistakes. It is to build one that knows how to deal with them.

Thank you for taking the time to read this rather lengthy article. I hope it offers some useful insights or inspires new ideas for your own smart home.