Deze uitgebreide Home Assistant automatisering combineert een deursensor met meerdere bewegingssensoren tot een betrouwbare “bezet”-status voor een ruimte — ook bekend als het “wasp in a box”-patroon. Dit voorkomt het klassieke probleem van gewone PIR-sensoren: het licht dat halverwege uitgaat terwijl iemand nog stilzit in de ruimte (bijvoorbeeld bij een bureau of op het toilet), omdat er even geen beweging is. De verlichting gaat er bovendien alleen aan als het ook daadwerkelijk schemerig genoeg is.
Ten opzichte van de simpele PIR + verlichting variant voegt deze uitgebreide versie toe:
- Een deursensor die de status direct en betrouwbaar bepaalt bij het openen/sluiten van de deur
- Een “grace period” van 2 minuten na het sluiten van de deur, zodat kortstondig geen beweging de status niet meteen verstoort
- Een verlengbare “vacant-deadline” die telkens vooruitschuift zolang er beweging blijft, in plaats van een simpele vaste timer
- Schemerdetectie (lux-sensor of globale schemerstatus), zodat het licht overdag niet onnodig aangaat
Let op: de entity-ID’s in dit artikel zijn generiek gehouden (ruimte_1) zodat je dit voorbeeld op elke ruimte in huis kunt toepassen — badkamer, werkkamer, toilet, of iets anders met een deur en beweging.
In dit artikel krijg je een volledig werkend voorbeeld van de 3 automatiseringen die samen deze flow vormen, inclusief uitleg zodat ook beginners dit zelf kunnen opzetten. Onderaan kun je de complete, kant-en-klare YAML ook downloaden.
De 3 automatiseringen zijn: bezet-status bepalen (wasp in a box), bezet-status uitzetten op deadline, en lampen aansturen op basis van bezet-status en schemer.
⚙️ Wat heb je nodig?
In Home Assistant:
- Een
binary_sensorvoor de deursensor van de ruimte - Eén of meerdere
binary_sensor-entiteiten voor bewegings-/aanwezigheidsdetectie (dit voorbeeld ondersteunt er twee tegelijk, bijv. een PIR én een mmWave-sensor) - Een
sensorvoor de lichtsterkte (lux) in de ruimte, of de globaleinput_boolean.schemer-helper uit eerdere artikelen - Een
light-entiteit voor de verlichting
Zelf aan te maken helpers:
input_boolean.pir_ruimte_1— houdt bij of de ruimte als bezet geldtinput_datetime.ruimte_1_laatste_deur_dicht— tijdstip waarop de deur voor het laatst dichtginginput_datetime.ruimte_1_vacant_op— tijdstip waarop de ruimte als leeg mag worden beschouwdinput_boolean.schemer— globale schemerstatus in huis (kan je hergebruiken uit een eerder artikel)
🧩 De 3 automatiseringen
Automatisering: Bezet-status bepalen (wasp in a box)
Wat doet dit: bepaalt op basis van deur- én bewegingssensoren betrouwbaar of de ruimte bezet is, ook als iemand een tijdje stilzit. Dit is het hart van de “wasp in a box”-aanpak.
Hoe maak je dit:
yaml
trigger: state
entity_id: binary_sensor.ruimte_1_deursensor_contact
trigger: state
entity_id:
- binary_sensor.ruimte_1_bewegingssensor_1_occupancy
- binary_sensor.ruimte_1_multisensor_motion_status
to: "on"
trigger: state
entity_id: binary_sensor.ruimte_1_aanwezigheidssensor_1_presence
trigger: time_pattern
minutes: /1
Bepaal met een paar hulpvariabelen: of de deur zojuist gesloten is (dan alleen het sluitmoment onthouden), of de deur zojuist geopend is (dan direct bezet zetten, met een korte 120-seconden marge), of er beweging is terwijl de deur al open staat (bezet zetten), en of er beweging is terwijl de deur dicht is én de ruimte al bezet was of nog binnen de 2-minuten grace-periode na het sluiten valt (bezet zetten, met een langere 20-minuten marge — dit dekt het “stilzitten”-scenario). Gebruik mode: queued zodat snelle opeenvolgende events niet worden overgeslagen.
Automatisering: Bezet-status uitzetten op deadline
Wat doet dit: zet de bezet-status uit zodra de “vacant-deadline” bereikt is — dat tijdstip wordt door de vorige automatisering telkens vooruitgeschoven zolang er reden is om te denken dat de ruimte nog in gebruik is.
Hoe maak je dit:
yaml
trigger: time
at: input_datetime.ruimte_1_vacant_op
Actie: input_boolean.turn_off op input_boolean.pir_ruimte_1.
Automatisering: Lampen bij bezet-status en schemer
Wat doet dit: zet de verlichting aan zodra de ruimte bezet is én het schemerig genoeg is, en weer uit zodra dat niet meer zo is — identiek aan de simpele variant, maar nu gevoed door de robuustere bezet-status.
Hoe maak je dit:
yaml
trigger: state
entity_id:
- input_boolean.pir_ruimte_1
- sensor.ruimte_1_multisensor_illuminance
- input_boolean.schemer
Bepaal schemer_actief als de globale schemerstatus aan staat óf de lokale lux-waarde onder een drempel (bijv. 70) ligt. Zet de lamp aan als de ruimte bezet is én het schemerig is, maar de lamp nog uit staat; zet hem uit in het omgekeerde geval.
🧠 Gebruikte templates
- Deur-trigger herkenning — bepaalt of de huidige trigger van de deursensor kwam, en of de deur net open of net dicht ging, zodat elke situatie een eigen tak in de logica krijgt.
- Grace-periode berekening — berekent of het laatste sluitmoment van de deur nog binnen 120 seconden ligt, als extra marge naast de “al bezet”-status.
- Schemer-drempel — combineert een globale schemerstatus met een lokale lux-meting tot één schemer_actief-waarde.
❓ Veelgestelde vragen
Waarom heet dit “wasp in a box”? De term komt uit de Home Assistant-community en beschrijft het idee: een deursensor “vangt” de aanwezigheid zodra de deur dichtgaat (zoals een wesp in een doos), en beweging binnen die afgesloten ruimte bevestigt dat er nog iemand is, ook als die persoon even stilzit.
Kan ik dit ook met maar één bewegingssensor gebruiken? Ja, laat dan gewoon de tweede entity-ID in de trigger-lijst weg.
Is de schemerdetectie verplicht? Nee, je kunt de schemer_actief-conditie weglaten of vervangen door true als je het licht altijd wilt laten aangaan bij bezetting, ongeacht de lichtsterkte.
Kan ik de tijdswaarden aanpassen? Ja, de 120-seconden grace-periode en de 20-minuten vacant-marge zijn naar smaak in te stellen — kortere waarden voor een kleine ruimte zoals een toilet, langere voor een werkkamer.
Hieronder kun je bovenstaande flow downloaden incl. de genoemde helpers en de volledige YAML als Word-bijlage.
De genoemde helpers kun je zelf aanmaken in Home Assistant onder apparaten en diensten -> helpers -> Helper toevoegen.
Let op gebruik is op eigen risico!!
Home Assistant PIR motion and lighting: advanced version with door sensor, multiple motion sensors, and twilight detection
This advanced Home Assistant automation combines a door sensor with multiple motion sensors into a reliable “occupied” status for a room — also known as the “wasp in a box” pattern. It avoids the classic problem with plain PIR sensors: the light turning off midway while someone’s still sitting still in the room (e.g. at a desk or on the toilet), simply because there was no motion for a moment. On top of that, the light only turns on when it’s actually dim enough.
Compared to the simple PIR + lighting version, this advanced version adds:
- A door sensor that determines the status directly and reliably when the door opens/closes
- A 2-minute “grace period” after the door closes, so a brief pause in motion doesn’t immediately disrupt the status
- An extendable “vacant deadline” that keeps pushing forward as long as motion continues, instead of a simple fixed timer
- Twilight detection (lux sensor or global twilight status), so the light doesn’t turn on unnecessarily during the day
Note: the entity IDs in this article are kept generic (ruimte_1 / “room 1”) so you can apply this example to any room in your house — bathroom, office, toilet, or anything else with a door and motion.
This article gives you a fully working example of the 3 automations that make up this flow, with explanations so beginners can set it up too. At the bottom, you can also download the complete, ready-made YAML.
The 3 automations are: determine occupied status (wasp in a box), turn off occupied status on deadline, and control lights based on occupied status and twilight.
⚙️ What do you need?
In Home Assistant:
- A
binary_sensorfor the room’s door sensor - One or more
binary_sensorentities for motion/presence detection (this example supports two at once, e.g. a PIR and an mmWave sensor) - A
sensorfor light level (lux) in the room, or the globalinput_boolean.schemerhelper from earlier articles - A
lightentity for the lighting
Helpers to create yourself:
input_boolean.pir_ruimte_1— tracks whether the room counts as occupiedinput_datetime.ruimte_1_laatste_deur_dicht— timestamp of when the door last closedinput_datetime.ruimte_1_vacant_op— timestamp at which the room may be considered emptyinput_boolean.schemer— global twilight status in the house (can be reused from an earlier article)
🧩 The 3 automations
Automation: Determine occupied status (wasp in a box)
What it does: reliably determines, based on door and motion sensors, whether the room is occupied — even when someone sits still for a while. This is the heart of the “wasp in a box” approach.
How to build it:
yaml
trigger: state
entity_id: binary_sensor.ruimte_1_deursensor_contact
trigger: state
entity_id:
- binary_sensor.ruimte_1_bewegingssensor_1_occupancy
- binary_sensor.ruimte_1_multisensor_motion_status
to: "on"
trigger: state
entity_id: binary_sensor.ruimte_1_aanwezigheidssensor_1_presence
trigger: time_pattern
minutes: /1
Using a few helper variables, determine: whether the door just closed (then just record the close time), whether the door just opened (then mark occupied immediately, with a short 120-second margin), whether there’s motion while the door is already open (mark occupied), and whether there’s motion while the door is closed and the room was already occupied or still within the 2-minute grace period after closing (mark occupied, with a longer 20-minute margin — this covers the “sitting still” scenario). Use mode: queued so quick successive events aren’t skipped.
Automation: Turn off occupied status on deadline
What it does: turns off the occupied status once the “vacant deadline” is reached — that time gets pushed forward by the previous automation as long as there’s reason to think the room is still in use.
How to build it:
yaml
trigger: time
at: input_datetime.ruimte_1_vacant_op
Action: input_boolean.turn_off on input_boolean.pir_ruimte_1.
Automation: Lights based on occupied status and twilight
What it does: turns the lighting on once the room is occupied and it’s dim enough, and back off once that’s no longer true — identical to the simple version, but now fed by the more robust occupied status.
How to build it:
yaml
trigger: state
entity_id:
- input_boolean.pir_ruimte_1
- sensor.ruimte_1_multisensor_illuminance
- input_boolean.schemer
Determine schemer_actief as the global twilight status being on, or the local lux value being below a threshold (e.g. 70). Turn the light on if the room is occupied and it’s dim, but the light is still off; turn it off in the opposite case.
🧠 Templates used
- Door-trigger recognition — determines whether the current trigger came from the door sensor, and whether the door just opened or just closed, so each situation gets its own branch in the logic.
- Grace period calculation — calculates whether the door’s last close time still falls within 120 seconds, as an extra margin alongside the “already occupied” status.
- Twilight threshold — combines a global twilight status with a local lux reading into one schemer_actief value.
❓ Frequently asked questions
Why is this called “wasp in a box”? The term comes from the Home Assistant community and describes the idea: a door sensor “traps” presence once the door closes (like a wasp in a box), and motion within that enclosed space confirms someone’s still there, even if they’re sitting still for a moment.
Can I use this with just one motion sensor? Yes, just leave out the second entity ID in the trigger list.
Is twilight detection required? No, you can leave out the schemer_actief condition or replace it with true if you always want the light to turn on when occupied, regardless of light level.
Can I adjust the timing values? Yes, the 120-second grace period and the 20-minute vacant margin are adjustable to taste — shorter values for a small room like a toilet, longer for an office.
You can download the flow above, including the mentioned helpers and the full YAML as a Word attachment, below.
You can create the mentioned helpers yourself in Home Assistant under Settings -> Devices & Services -> Helpers -> Add Helper.
Please note: use is at your own risk!!

Geef een reactie