Detecting Human Activity in Home Automation  Systems

Detecting Human Activity in Home Automation Systems

If you've been working with home automation systems, you have likely found out that detecting human activity can be tricky and error-prone. Relying on 'unambiguous', Boolean-based detection systems like motion sensors will introduce a flood of false positives, especially when a household is shared with non-humans (i.e. pets).

While there are mmWave sensors out there, they are generally aimed at in-door use, are more expensive and consume (quite a lot) more power, perhaps limiting you in either placement or budgetary affordance. In this article, I will outline the system I developed for more reliably detecting human activity using nothing more than basic entities/sensors already present in most home automation systems.

💡
TLDR? Skip to the flowchart at the bottom of this article.

Introduction

A key foundation for any home automation system is being able to establish a conclusive answer to three basic questions:

  • Is anybody home?

  • Are they awake?

  • Is there any human activity?

The first two can usually be answered fairly easily without implementing much 'intelligence', and using basic components like device trackers and motion sensors. The last one however is more tricky to answer because of the dynamic, unpredicatable and complex nature of human behavior (not to mention their pets).

My approach is designed to minimize false positives, account for intermittent activity patterns, and provide customization to accommodate diverse household needs. I'm not claiming it's the definitive way to detect activity, but I found it does a very good job and has proven reliable and accurate over time (2+ years).

Part A - Trigger Categorization

Before we dive into the mechanics of detecting human activity in a home automation environment, it's important to understand the two types of triggers used in this system, which I have dubbed Single Event triggers and Continuous State triggers.

  • Single Event triggers
    These consist of entities characterized by interactions. Their actions usually either lack a sustained 'on' state, their 'off' state may not reliably indicate that activity has ceased, their off-state might trigger too fast causing ‘bouncing’, or they’re entities of which any change in state could potentially signify activity.

  • Continuous State triggers
    These are entities that indicate prolonged activity. They have clearly defined 'on' and 'off' states, which can immediately be recognized as indications of sustained activity. This category is particularly effective for situations where occupants might remain stationary for extended periods (e.g., watching TV). Motion and occupancy sensors would also fall into this category.

Part B - Timer Logic

Another core component of the system is the use of two timers, which I call the Activity Trigger Easing Timer and the Activity Switching Delay Timer. The latter being the most important one

  • Activity Trigger Easing Timer

    As explained, the actual off-state (if any) of single event triggers is effectively ignored. Instead, a unified approach is used for all these entities: the Activity Trigger Easing Timer. This timer is (re)started each time a single event trigger fires, and effectively serves as a delayed 'off' state; if no further triggers occur before the timer expires, the system considers the activity to have ceased. This approach helps mitigate false positives from brief or incidental activations that do not correspond to sustained human activity.

  • Activity Switching Delay Timer
    This timer starts running when potential activity is detected by either type of trigger (possible activity), and runs parallel to the Activity Trigger Easing Timer.
    It uses a variable timeout to wait before actually setting activity as true. This timeout - and this is absolutely paramount - is based on the occupation (or 'home') and (if available) sleep states: it allows fast acting on signs of activity when there’s people at home and delayed when they’re not (or sleeping). This is essential in minimizing false positives, as it prevents pets from triggering activity.

Part C - The Detection Flow

With these definitions in place, let's explore how these triggers and timers work together to detect human activity effectively, while minimizing false positives. The flow is actually simple:

  1. A trigger (of either type) fires

    • Is it a single event trigger? Mark the event as possible activity and (re)start the Activity Trigger Easing Timer for 1m30s¹.

    • Is it a continuous event trigger? Mark the event as possible activity if the trigger changed to ON, and possible inactivity if the trigger changed to OFF.

  2. Evaluate two conditions:

    • Is anybody home?

    • Are they awake?

If both conditions are true, set variable timeout to zero.
If either one if false, set the variable timeout to 15 minutes ²

  1. Start the Activity Switching Delay Timer using the variable timeout

  2. Finally, if this timer finishes (which will be instantly when the variable timeout is zero), evaluate two conditions:

    • is there any Continuous State trigger (entity) in an ON state? Or;

    • is the Activity Trigger Easing Timer still running?

Is either of these true? Set activity to ON

Are both false? Set activity to OFF

And that's it! ³ The variable timeout delay makes sure pets don't trigger activity whenever you're either sleeping or not at home. This allows the home automation system to adjust dynamically to the household's living patterns, ensuring that activity detection is both sensitive and specific, bridging the gap between detecting an event and confirming genuine human activity.

Summary - System Overview

Perhaps the best way to understand how the system works is by visualising it, capturing the detection flow in a flowchart.

Note that in this flowchart, two triggers appear to occur at the same time. This is purely to demonstrate each flow, and unclutter the chart by combining common parts.

Conclusion

By intelligently distinguishing between types of triggers and employing adaptive switching delays, the system offers a tailored, responsive experience that aligns with the dynamic nature of both animal and human behavior.

You can use this foundation to build upon, for example by incorporating Bayesian sensors to further refine activity detection, adapting to occupants' habits and preferences for an even more seamless home automation experience.

Afterthought

You can apply this logic at home-level - such as in this article, which is likely what most people would do - as well as at area level (i.e. floors, or even rooms). This would require you to set up multiple detection flows, incorporating triggers specific for that area, resulting in activity states for each one.


Footnotes

¹ While this value seems arbitrary, it is based on the assumption that single event triggers are usually followed by either more single event triggers, or continuous event triggers. And if they’re not, there is probably no activity (anymore). No need to wait more than one and a half minute to figure this out. This is much like how most motion detectors work, which is the best comparison (and inspiration) for single event triggers.

² After experimenting with this setup for a few years, I found that 15 minutes works best in my own household (4 people, 2 cats). Set it too short, and you might notice the system detecting inactivity when you're stationary for too long; most humans move at least once every 15 minutes, unless they're sleeping ;-)

³ For the sake of brevity, I have left out some additional checks/actions. If for example there's a state-change in either Home or Sleep state, you can consider canceling all running timers and optionally force setting/unsetting activity state (effectively bypassing the logic).