Part XIV: Applications, Systems, and Frontiers
Chapter 71: Domain Playbooks: Wearables, Robotics, Vehicles, Smart Spaces, Environment, Security

Smart spaces and ambient intelligence (occupancy, non-camera sensing, placement)

"A camera in the ceiling knows what you look like. A CO2 sensor only knows that you are breathing. In a bedroom, that difference is the whole product."

A Tactful AI Agent

The Big Picture

A smart space is a building, room, or vehicle cabin that senses who and what is inside and adapts light, air, heat, and safety systems in response. The defining constraint of this domain is social, not technical: people accept sensors in their offices, hotel rooms, and homes only when those sensors cannot recognize them. That single constraint pushes the entire perception stack away from cameras and toward the physics of presence: heat, motion, exhaled gas, reflected radio waves, and sound. This section is a playbook for building perception when the most obvious sensor is off the table. We treat occupancy as the central quantity, survey the non-camera sensing menu and its failure modes, and then address the question that quietly determines whether any of it works: where do you put the sensors?

This section assumes you are comfortable with sensor measurement models and noise (Chapter 2), with change detection on streams (Chapter 12), and with the building-sensor context introduced in Chapter 39. Where we lean on radio and radar physics we point to the dedicated chapters rather than re-deriving them.

Occupancy is the atom of a smart space

Almost every smart-space behavior reduces to a question about people: is anyone here (presence), how many (count), where are they (localization), and what are they doing (activity). Presence is binary and cheap; count is a positive integer and much harder; localization and activity are progressively richer and progressively more invasive. The design discipline is to demand the weakest quantity that satisfies the use case. A corridor light needs presence. Demand-controlled ventilation needs count. A fall-response system for assisted living needs coarse localization plus an activity label, but deliberately not identity.

Why does this matter beyond privacy? Because each rung up the ladder costs sensing bandwidth, compute, and calibration effort, and each rung introduces new failure modes. A presence detector that mistakes a fluttering curtain for a person wastes a few watts. A count estimator that is off by two people can over-ventilate a room by fifty percent, or under-ventilate it into a stuffy, high-CO2 state that measurably degrades cognitive performance. The stakes rise with the richness of the claim, so you climb the ladder only as far as the application forces you.

Key Insight

In smart spaces, privacy is not a compliance checkbox bolted on at the end; it is a sensor-selection principle applied at the start. The right question is never "how do we anonymize the camera feed?" but "what is the least-informative signal that still answers the operational question?" A system that physically cannot form an image cannot leak one, cannot be subpoenaed for one, and does not need a data-retention policy for one. Designing for the weakest sufficient signal is the cheapest privacy engineering you will ever do.

The non-camera sensing menu

Each non-camera modality trades cost, coverage, and the richness of what it can infer. Knowing their failure modes is more useful than knowing their datasheets, because the failures are what your model has to survive in deployment.

Practical Example: demand-controlled ventilation in a graded office

A commercial landlord retrofits a floor of open-plan offices to cut HVAC energy without a single camera. The stack is deliberately layered. PIR sensors give sub-second presence for lighting. A ceiling grid of mmWave radar modules supplies stillness-robust presence and rough zone localization so an unoccupied quadrant can be throttled. NDIR CO2 sensors on each return-air duct anchor the actual headcount, correcting for the fact that radar over-counts a person waving their arms and under-counts a still one. A Kalman-style estimator (Chapter 9) fuses the fast-but-noisy radar count with the slow-but-truthful CO2 count. The building trims ventilation energy by roughly a third on partially occupied days, and the lease's privacy addendum can truthfully state that no device on the floor can identify a person.

Counting people from the air they breathe

CO2-based counting rests on a mass balance. At steady state, the CO2 an occupied room accumulates above outdoor levels is set by how many people exhale versus how fast fresh air dilutes them. If \(C_\text{in}\) and \(C_\text{out}\) are indoor and outdoor concentrations, \(G\) is the CO2 generation rate per person, and \(Q\) is the volumetric ventilation rate, then the steady-state occupant count is

$$ n \approx \frac{Q\,(C_\text{in} - C_\text{out})}{G}. $$

The transient before steady state follows a first-order response with time constant \(\tau = V/Q\) for room volume \(V\), which is why CO2 lags occupancy by several minutes. The estimator below inverts the steady-state relation and is the kind of physics-grounded baseline you should always build before reaching for a neural model.

import numpy as np

# Physical constants (SI-ish, tuned for a small meeting room)
G_PER_PERSON = 0.0052    # m^3/s of CO2 exhaled by a seated adult (~5.2e-3 L/s)
C_OUTDOOR    = 420e-6    # outdoor CO2 mole fraction (420 ppm)

def occupancy_from_co2(co2_ppm, ventilation_m3s):
    """Steady-state occupant count from indoor CO2 and known ventilation."""
    c_in = np.asarray(co2_ppm) * 1e-6            # ppm -> mole fraction
    excess = np.clip(c_in - C_OUTDOOR, 0, None)  # never negative
    n = ventilation_m3s * excess / G_PER_PERSON
    return np.round(n).astype(int)

# A room ventilated at 40 L/s, sampled every few minutes as it fills up
co2_trace = [430, 512, 640, 815, 980, 1120, 1090]  # ppm
counts = occupancy_from_co2(co2_trace, ventilation_m3s=0.040)
print(counts)   # -> [ 0  1  2  4  5  6  6 ]
A physics-first occupancy estimator: invert the steady-state CO2 mass balance to recover headcount. The printed trace shows the room filling to six people. Real deployments add the ventilation term as an online estimate and smooth the count with a filter, but this ten-line baseline already beats many black-box models and, unlike them, fails in ways you can explain to a facilities manager.

Notice what the baseline exposes: the estimate is only as good as your knowledge of \(Q\). In a variable-air-volume building the ventilation rate is itself a controlled, changing quantity, so a robust system co-estimates \(Q\) from damper positions or treats it as a latent state. This is exactly the kind of coupled-unknowns problem that pushes teams from a closed-form inverse toward the Bayesian filtering of Chapter 9.

Right Tool: fusing the sensor grid

Writing the multi-sensor occupancy fusion by hand (per-zone state, radar-count likelihood, CO2 transient model, cross-zone smoothing) runs to a few hundred lines. Expressing the whole building as a factor graph in gtsam or filterpy collapses the fusion to declaring one measurement factor per modality plus a between-zone motion factor: roughly 40 lines instead of 300, with the solver handling marginalization, missing sensors, and uncertainty propagation for you. The library owns the linear algebra; you own the physics of each factor. The same factor-graph machinery underlies the smoothing in Chapter 11.

Placement: the design decision that dwarfs the model

You can pick the perfect modality and the perfect model and still fail, because a sensor measures only the volume it can physically reach. PIR needs line of sight and is blinded by cubicle partitions; radar reflects off metal and floods small rooms with multipath; CO2 sensors near a doorway read the corridor, not the room. Placement is a coverage-optimization problem, and it usually matters more than a few points of model accuracy.

Formally, given candidate mounting locations and a set of zones that must be covered, choosing the fewest sensors that cover every zone is a set-cover problem: NP-hard in general, but its objective is submodular, so a greedy algorithm (repeatedly add the sensor that covers the most still-uncovered zones) is guaranteed to land within a factor of \((1 - 1/e)\), about 63 percent, of the optimum. That guarantee, plus its trivial implementation, makes greedy the default placement planner. For dense sensor networks whose readings are spatially correlated, the same submodular framing extends to placing sensors where they most reduce predictive variance, which connects to the graph and spatial models of Chapter 54.

Two placement rules earn their keep in practice. First, place the corroborating sensor and the anchor sensor to have independent failure modes: putting the CO2 sensor in the return duct (integrating the whole room) while the radar watches the seating zone means a curtain fooling the radar does not also fool the CO2. Second, mount for the physics, not for convenience: a thermopile array wants a top-down view of chairs, a PIR wants to look across the traffic it must catch, and neither belongs where the electrician finds it easiest to run conduit.

Ambient intelligence, on the edge and private by construction

The payoff of this modality discipline is that smart-space inference runs comfortably at the edge. PIR, CO2, thermopile, and even radar occupancy models are small enough for a microcontroller (Chapter 61), so the raw stream never leaves the room. When you do need to improve a model across a fleet of buildings, federated learning lets each site contribute gradients without shipping occupancy traces to a server, keeping the privacy promise intact end to end (Chapter 64). Ambient intelligence, done well, is a system that perceives just enough to act and forgets everything else by design.

Research Frontier

The active frontier is device-free sensing that reads vital signs and activity from ambient radio alone. Commodity WiFi CSI and single-chip 60 GHz radar (Google's Soli lineage, Infineon's BGT60 family) now support contactless respiration and heart-rate estimation, gesture recognition, and fall detection with no wearable and no camera. The open problems are cross-environment generalization (a model trained in one furnished room degrades badly in another, a domain-shift problem in the sense of Chapter 66) and the uncomfortable duality that a sensor sensitive enough to hear you breathe through a wall is also a surveillance tool. Self-supervised pretraining on unlabeled RF and radar streams is the current best hope for models that transfer across spaces.

Exercise

You are specifying occupancy sensing for a 12-room boutique hotel. Requirements: turn down HVAC in empty rooms, never switch off climate while a guest sleeps (stillness-robust), and a contractual guarantee that no device can identify or image a guest. (a) Choose a primary modality and one corroborating modality per room, and justify each against the stillness and privacy constraints. (b) Using the greedy set-cover idea, sketch how you would decide sensor count and mounting points for an irregular top-floor suite. (c) The CO2 estimator from this section reads two occupants in a single room where housekeeping reports one guest. List three physical explanations and how you would disambiguate them.

Self-Check

  1. Why does a PIR sensor make a poor primary detector for a reading room or a bedroom, and which two modalities in this section fix that specific failure?
  2. The CO2 count estimator depends on the ventilation rate \(Q\). Explain why a variable-air-volume building turns occupancy estimation into a coupled-unknowns problem, and name the tool from Part III you would reach for.
  3. Greedy sensor placement is guaranteed to reach at least what fraction of the optimal coverage, and what mathematical property of the coverage objective makes that guarantee hold?

What's Next

In Section 71.5, we step outdoors and scale up: environmental and climate sensing, where the room becomes a watershed or a city. We will trade the placement problem for spatial interpolation across sparse stations, add early-warning detection for floods and air-quality events, and confront the messy, wonderful world of citizen-sensing networks where the sensors are cheap, plentiful, and only sometimes trustworthy.