From radar presence to a room occupancy state machine

A radar reports presence. An automation needs occupancy, and the two are not the same word. Presence is a sensor state at this instant; occupancy is a claim about a room over a period, and it has to survive a false clear, a fan and a person who stops moving.

This chapter builds the state machine in Home Assistant, using the sensor states the radar integrations already publish. It assumes the sensor side is working and verified with the checks in the tuning and validation chapters.

Three failure modes the sensor cannot fix

The state machine cannot repair the first two; only mounting and thresholds can. It can absorb the third, which is what the hold time is for.

Layer one: normalise each sensor

Do not wire the raw entity into every automation. Give each sensor a template entity with an explicit on-delay and off-delay, so the rest of the system sees one behaviour:

template:
  - binary_sensor:
      - name: "Study radar stable"
        state: "{{ is_state('binary_sensor.study_radar_presence', 'on') }}"
        delay_on: "0:00:02"
        delay_off: "0:00:20"

Two properties of those delays matter:

The template documentation defines both options as the time the condition must stay met, so a long off-delay does not delay the light turning on.

Layer two: aggregate the area

One room, one sensor is the simple case. Two cases need aggregation:

Entry plus interior. A doorway sensor and a ceiling sensor in the same room. Use OR, but with different delays: the doorway sensor can be fast, the interior sensor slow.

Two radars in one volume. Use a quorum instead of OR, so one noisy module cannot hold the room occupied alone:

{{ [is_state('binary_sensor.study_radar_a', 'on'),
    is_state('binary_sensor.study_radar_b', 'on')] | select('equalto', true) | list | count >= 2 }}

Two radars aimed at the same volume interfere, so read the coexistence chapter before adding the second one; the quorum is a filter, not a fix for a bad installation.

Layer three: hold the occupancy claim

Occupancy should end later than presence, and it should not end while someone is sitting still. Two mechanisms, use one:

Trigger with a hold time. The automation fires when the aggregated sensor turns off, but only after the state has persisted:

triggers:
  - trigger: state
    entity_id: binary_sensor.study_occupied_raw
    to: "off"
    for: "0:05:00"
actions:
  - action: input_boolean.turn_off
    target:
      entity_id: input_boolean.study_occupied

A timer helper. Start the timer on every presence event, cancel and restart it while presence continues, and treat expiry as the end of occupancy. This survives a Home Assistant restart better than a bare delay in some setups, because the timer is a stored entity.

Whichever you choose, the hold time belongs in one place. Duplicating a five-minute delay across three automations is how a room ends up with three different definitions of empty.

Manual override is part of the machine

A room with a desk and a sleeping cat will produce occupancy that the occupant disagrees with. Give the occupant a switch:

The override is also a diagnostic: if the room behaves correctly with the override on and wrongly with it off, the problem is in the sensor or the aggregation, not in the lights.

Pick numbers you can defend

A starting point, to be tuned with a week of logs:

Parameter Starting value Why
Sensor on-delay 2 s Rejects a single-frame spike
Sensor off-delay Sensor timeout plus 5 to 10 s Prevents a clear while the radar still holds
Occupancy hold 5 min Covers a person reading or typing
Cooldown after clearing 30 s Stops a re-trigger loop at the threshold

None of these are universal. They are defensible because each one has a reason, and the reason is written next to it.

Test the machine, not the sensor

Log transitions for a week and count three things:

  1. False ons per day, with nobody in the room.
  2. False offs while someone was present, evidenced by a manual override or a second sensor.
  3. The distribution of occupancy durations, which shows whether the hold time matches real behaviour.

A state machine that never logs its own transitions cannot be tuned, and a claim that "the automation works" without those counts is a feeling.

Related reading