CasaSmart guide
Guide for local lighting with a Zigbee sensor and reliable automations.
CasaSmart
Turning lights on with motion sounds trivial, yet in practice it is one of the most-used and most frequently misconfigured automations in Home Assistant. The naive version — “if the sensor sees motion, turn the light on” — works the first evening and then becomes annoying: the light stays on after you have left the room, switches off exactly when you sit still at your desk, or blasts on at full brightness at three in the morning on the way to the bathroom. A good automation cleanly separates three independent decisions: when to turn on, how long to stay on, and how bright to be depending on the time of day and the natural light in the room. In this guide we build exactly that scenario step by step, using a Zigbee motion sensor, a few helper entities, and a single clear automation that is easy to maintain. The approach is the same whether the sensor is an Aqara, a Sonoff, or another Zigbee-compatible model — what matters is how you integrate it through Zigbee2MQTT or ZHA and the logic you build on top. In the end you get a system that behaves naturally: light appears instantly, stays on for just the right time, and never dazzles you at night.
The key to a good result is separating the moment of turning on from the moment of turning off. Turning on should be instant and gated only by ambient light: you do not want to wait, and you do not want light during the day. Turning off, on the other hand, needs its own timer — a “quiet” interval after the last detected motion — so the light does not switch off while you are still in the room, nor stays on for hours after you have left. In Home Assistant this timer is built elegantly with wait_for_trigger and the for parameter, fed from an input_number helper you can adjust at any time. The third decision, brightness, is about comfort: the same motion should produce bright light by day and dim, warm light at night. An input_boolean helper called mod_noapte, or a simple time-of-day condition, handles this through a choose branch. All three decisions fit into a single, well-structured automation that is easy to read six months later. We also use mode: restart — a small but essential detail that stops parallel runs from stepping on each other and removes most flicker. Once you understand these three axes — trigger, duration, brightness — you can adapt the scenario to any room.
This guide is written for the enthusiast configuring their own home, but the logic is exactly the same one we use at CasaSmart in our turnkey installations across Moldova. A cheap motion sensor and a smart bulb may look like a toy, yet the difference between an automation that annoys and one the family stops noticing lies precisely in these details: a separate timer, a light condition, a night mode, and a single owner of the light’s state. Local reality adds a few practical considerations: long apartment-block corridors and house staircases need solid Zigbee coverage, which means a well-placed coordinator and possibly intermediate Zigbee routers; and for rooms where you sit still for long stretches — office, living room, bathroom — an mmWave sensor is worth the investment. If you would rather not build everything from scratch, CasaSmart can pick the right sensors for each room, mount and tune them, and deliver the automations either fully turnkey or as a clean starting point you maintain yourself. The initial consultation is free, while the on-site visit and detailed design are paid services. Either way, the principles in this guide still hold.
TL;DR
Separate three decisions: when to turn on (sensor trigger + sun/lux condition), how long to stay on (wait_for_trigger on off, duration from an input_number) and how bright (night mode with reduced brightness). Use a Zigbee sensor via Zigbee2MQTT/ZHA, helpers for duration and night mode, mode: restart against flicker, and mmWave for rooms where you sit still.
Step 1
Before any automation, add the motion sensor to your Zigbee network and check which entity it exposes. In Zigbee2MQTT, pair the sensor from the web interface (Permit join), rename it clearly, for example senzor_hol, and note the entity binary_sensor.senzor_hol_occupancy or ..._motion. With ZHA, find the device under Settings → Devices and you will see the same binary_sensor with a device_class of “motion” or “occupancy”. Open Developer Tools → States and wave your hand in front of the sensor: the state should toggle between off and on. Note the sensor’s “cooldown” time too — many PIR models report on, then only return to off after a fixed interval regardless of your configuration. This hardware detail directly shapes how you build the timer. Also check the battery level and signal quality (LQI) so the sensor does not drop off the network.
Step 2
Create two helper entities under Settings → Devices & Services → Helpers. First, a Toggle (input_boolean) named mod_noapte, which you will use to switch the light’s behaviour between day and night without rewriting the automation. Second, a Number (input_number) named timp_asteptare, with a minimum of 10, a maximum of 600 and a step of 10, in seconds — this controls how long the light stays on after the last motion. The advantage of helpers is that you can adjust the duration straight from the interface or a dashboard, without editing YAML each time. Optionally, add an input_datetime or use direct time-of-day conditions to switch mod_noapte automatically. These entities make the automation flexible and easy to tune for any family member, not just whoever set it up.
Step 3
Create a new automation and switch to YAML mode for full control. The trigger is the sensor turning on: platform: state, entity_id: binary_sensor.senzor_hol_occupancy, to: 'on'. The first action is simple — light.turn_on on the room’s light, for example light.hol. Do not add conditions yet; you want turning on to be instant and reliable. Set the automation’s mode: restart — we explain why below. Save and test: on the first motion, the light should appear with no perceptible delay. If the light comes on sluggishly, the problem is almost certainly in the Zigbee network or in the bulb/relay itself, not in the logic. Keep the turn-on trigger separate from the turn-off logic; we combine them in one automation but handle the two moments with distinct, clear actions.
Step 4
Now add the turn-off logic to the same automation. After light.turn_on, use the wait_for_trigger action, which waits for the sensor to go off and stay there for a while: trigger on binary_sensor.senzor_hol_occupancy, to: 'off', with a for taken from the helper via a template, for example {{ states('input_number.timp_asteptare') | int }} seconds. Only once that wait completes do you run light.turn_off on light.hol. The key is that the off timer is completely separate from turning on: the sensor may report motion many times, and mode: restart restarts the countdown each time. So the light stays on while you are in the room and switches off only after no motion for the chosen interval. Avoid hard-coding the seconds; always use the helper so you can tune it easily.
Step 5
There is no point turning the light on during the day when the room is already bright. Add a condition before turning on. The simplest option is a condition on the sun.sun entity, state: below_horizon, so the light only comes on after sunset. More precise is an illuminance condition, if your sensor reports lux (many combined models have sensor...illuminance_lux). Then set a numeric_state condition: turn on only if the value is below a threshold you set by watching the room at different times of day. Put the condition on the turn-on branch, not the turn-off one — otherwise, if it brightens up, the light would stay on indefinitely. The lux threshold varies a lot from room to room, so tune it empirically; do not copy a value from the internet. Combining sun + lux gives the most stable result.
Step 6
Use the mod_noapte helper to change brightness by time of day. In the action, replace the plain light.turn_on with a choose branch: if mod_noapte is on (or the time is between, say, 23:00 and 06:00), turn the light on at a low, warm brightness — a small brightness_pct and, if the bulb supports it, a warm colour temperature — so it does not dazzle you at night. Otherwise, turn on at normal daytime brightness. You can automate switching mod_noapte with a second automation based on time or on sun, so you never touch it manually. This is also the place to set a transition of one or two seconds on turn_on and turn_off, so the light fades in and out smoothly rather than snapping. This day/night distinction is exactly what turns a crude automation into one the family actually tolerates.
Step 7
Flicker happens when the automation restarts and re-runs turn_on/turn_off in short loops, or when you switch off a light another automation has just turned on. Three measures help. First, mode: restart on the automation: a new motion cancels the current wait and restarts it cleanly, instead of launching parallel runs that step on each other. Second, avoid turning off unconditionally — if you turned the light on manually, an over-aggressive automation can switch it off under you; mark manual turn-ons or check a “manual control” input_boolean. Third, if your bulb already has an internal timer or your Shelly relay has its own delay, disable it so you do not have two timers contradicting each other. A single owner of the light’s state prevents most flicker and unpredictable behaviour.
Step 8
Classic PIR sensors detect motion by heat change, so they “forget” you are in the room if you sit still — hence the light that switches off at your desk. mmWave (radar) sensors also detect static presence, keeping the light on while you are there, but they can react to unwanted small movements and need careful tuning of sensitivity and zone. For hallways and staircases, PIR is enough; for the office, sofa or bathroom, mmWave or a PIR + mmWave combination works much better. Against false triggers: keep the sensor away from heat sources, warm air currents, direct sunlight and pets; adjust the mounting angle and height; increase the timer slightly. Check the entity history for when the phantom on appeared, so you find the real cause before swapping hardware.
The classic mistake is a single “motion → turn on” rule with no separate timer and no light condition: the light switches off when you sit still, comes on pointlessly during the day, and dazzles you at night. Just as often, people hard-code the seconds instead of a helper, leave two timers (bulb and automation) contradicting each other, and forget mode: restart — which is what produces flicker and unpredictable parallel runs.
Because a PIR sensor detects heat change, not static presence; when you do not move, it reports “no motion” and the timer switches the light off. The fixes are: increase timp_asteptare, use an mmWave (radar) sensor that also sees static presence, or combine PIR with mmWave in rooms where you sit still for long stretches.
For hallways, staircases and storage rooms, a PIR is cheap, fast and enough. For the office, living room, bedroom or bathroom, where you sit still, mmWave (radar) keeps the light on more faithfully but needs sensitivity tuning so it does not react to minor movements. A PIR + mmWave combination gives both speed and static-presence detection.
Add a condition to the turn-on branch: either sun.sun below_horizon, or a lux threshold if your sensor reports illuminance. Put the condition on turn-on only, not turn-off, so an already-on light does not get stuck if it brightens outside. Tune the lux threshold by actually watching the room, not with a value copied from the internet.
Yes. The automation logic does not depend on the light’s technology — all that matters is that the light is exposed as a light entity in Home Assistant. You can use a Wi-Fi bulb, a Shelly relay or a smart switch. The sensor can be Zigbee while the light is on another technology; Home Assistant ties them together. Just make sure only one timer is active.
Yes. CasaSmart is a smart-home integrator in Moldova and installs solutions built on Home Assistant, Zigbee and Shelly. We can choose the right sensors for each room, mount and tune the mmWave, and build the automations either turnkey or as a starting point you maintain yourself. The initial consultation is free; the on-site visit and detailed design are paid services.
● CasaSmart · Chișinău
CasaSmart can configure the Home Assistant automation and test it on real devices.