Measure the room, then check whether someone needs light

To make Home Assistant turn lights on only when dark, add a Numeric state condition for a light-level sensor before the turn-on action. Lux, written lx, describes how much light reaches that sensor. Use a reading from the room you want to light, then choose the threshold by observing when that room actually feels too dim.

There are two moments to handle: someone enters an already dark room, or the room becomes dark while someone is still there. A motion-only trigger handles the first. Add a lux-crossing trigger for the second, and require an occupied room in either case. Home Assistant’s trigger documentation explains this pattern: either event starts a check, but both conditions must pass.

The example below turns a lamp on when needed. It does not switch it off just because daylight returns. Its optional shutoff waits for the occupancy sensor to clear, avoiding a loop in which turning on the lamp immediately makes the room “too bright.”

Research basis: researched from Home Assistant documentation on October 6, 2026. The room readings are a worked example, not measurements from a Tara installation. No hardware testing is claimed. The cover is an AI-generated editorial illustration.

1. Choose a room sensor or a Sun condition

On a phone, swipe tables and code examples sideways to see every column or line.

Your requirementUseWhat to check
Respond to a dark room during the dayA numeric room illuminance sensorIt must expose a usable lux reading in Home Assistant, near the place where you need light.
Allow motion lights only at nightA Sun conditionHome Assistant’s home location must be correct. This follows the sun, not the room’s curtains or clouds.
Light the house before sunset until bedtimeAn evening scheduleUse the sunset and bedtime guide for that different routine.

The Sun integration calculates solar events from your configured location. It does not measure indoor brightness. For this walkthrough, use an existing numeric lux sensor; a device that reports only “light” or “dark” needs a state condition instead.

You also need a lamp you can already operate from Home Assistant and a motion or presence sensor. An entity is the individual reading or control shown in Home Assistant. A conventional motion sensor may clear while you sit still; use a suitable presence sensor for a reading chair, or start with a room where people keep moving. For several sensors, use the separate any-sensor-on, every-sensor-clear guide.

2. Pick the threshold with the lamp off

  1. Open the sensor’s history and watch its value with the room lamp off, first when daylight is comfortable and then when you would normally reach for the switch.
  2. Keep the sensor in a representative position. A sunny windowsill or the lamp’s direct beam can describe that small spot rather than the seating area.
  3. Turn the lamp on once and note how much the reported value changes. This reveals whether an automatic “too bright, turn off” rule would respond to the lamp itself.
  4. Choose a starting threshold between your comfortable and too-dim observations. Confirm the reading is in lx; do not paste a raw Zigbee value or a bright/dark label into this numeric example.

Worked example, not measured data: suppose a room reads 75 lx when comfortable, 18 lx when you want the lamp, and 140 lx with the lamp lit. Start by trying “below 30.” At 18 the lamp may turn on; at 140 it should stay on until the room is clear. The exact numbers belong to this illustration, not every home.

Also watch when readings arrive. Do not assume a sensor reports every small change immediately. If its displayed value does not follow your light changes, check that exact device’s integration and reporting options before changing the automation. A plausible old number can still pass a numeric condition; this example does not detect stale readings.

3. Create a visible pause and the turn-on routine

Go to Settings → Devices & services → Helpers → Create helper → Toggle. Name it “Room automatic lighting,” add it to your dashboard and switch it on. This Toggle helper gives the household one place to pause both routines.

Then open Settings → Automations & scenes and create a new automation. In the visual editor, add two starts under When: the occupancy sensor changes to occupied, or the lux reading crosses below 30. Under And if, require the helper on, occupancy detected, lamp off and lux below 30. Under Then do, turn on the lamp. Save as “Room lamp — on when occupied and dark.”

Search the editor for Numeric state if you cannot find the lux sensor under a device-specific choice. Current documentation calls the generic trigger Numeric state crossed threshold; labels vary with Home Assistant version. The generic option compares the raw number, without converting units.

For a copyable version, create a new empty automation, open its menu and choose Edit in YAML. Replace the four example entity IDs with yours. The helper name does not guarantee that Home Assistant assigned the exact ID shown. Use the States tool to confirm IDs and that your occupied/clear sensor uses raw states on and off. Current documentation places this tool under Settings → Tools → States; older releases label it Developer tools → States.

alias: Room lamp - on when occupied and dark
triggers:
  - trigger: state
    entity_id: binary_sensor.room_occupancy
    to: "on"
  - trigger: numeric_state
    entity_id: sensor.room_illuminance
    below: 30
conditions:
  - condition: state
    entity_id: input_boolean.room_automatic_lighting
    state: "on"
  - condition: state
    entity_id: binary_sensor.room_occupancy
    state: "on"
  - condition: state
    entity_id: light.room_lamp
    state: "off"
  - condition: numeric_state
    entity_id: sensor.room_illuminance
    below: 30
actions:
  - action: light.turn_on
    target:
      entity_id: light.room_lamp
mode: single

The numeric condition excludes the boundary: exactly 30 does not pass “below 30.” Keep the threshold identical in the trigger and condition. The lamp-off check prevents this routine from repeatedly sending turn-on commands to an already lit lamp.

A crossing from 40 to 25 can start a run; further readings of 24 and 23 do not each create another threshold crossing. If you save the routine when the room is already occupied and dark, it waits for a relevant new transition. Turning the pause helper back on also only permits future runs; it does not immediately operate the lamp.

4. Add shutoff without a darkness condition

If you want automatic shutoff, create a second automation. Its State changed trigger watches the occupancy sensor become off and remain there for three minutes. It checks the pause helper and clear state again before sending an explicit Light: Turn off action.

alias: Room lamp - off after room clears
triggers:
  - trigger: state
    entity_id: binary_sensor.room_occupancy
    to: "off"
    for: "00:03:00"
conditions:
  - condition: state
    entity_id: input_boolean.room_automatic_lighting
    state: "on"
  - condition: state
    entity_id: binary_sensor.room_occupancy
    state: "off"
actions:
  - action: light.turn_off
    target:
      entity_id: light.room_lamp
mode: single

There is deliberately no lux condition here. If the lit lamp makes the sensor read 140 lx, an “only below 30” check would block shutoff. Conversely, making “above 30” an immediate off trigger could turn the lamp off as soon as it illuminates the sensor.

Manual-use limit: this simple off routine also applies to a lamp someone switched on by hand. Switch the helper off first if you want to keep it on, or stay in darkness for a movie. It pauses future automatic actions without changing the lamp. For automatic detection of manual choices, use the manual override guide.

Restart limit: a pending for wait does not survive a Home Assistant restart or automation reload. This example has no catch-up routine; a lamp may stay on until another occupied-to-clear cycle. Check it manually after maintenance. Unknown occupancy is not confirmed vacancy, so do not add an “unknown means clear” shortcut.

5. Rehearse beside one nonessential lamp

Keep ordinary manual control available and start with a table lamp, away from stairs or essential route lighting. Pause other routines that control that same lamp during the test. The following are expected results of this example, not reported hardware measurements.

Try thisExpected resultIf it differs
With the lamp off and lux above 30, let occupancy go clear, then enter.The lamp stays off.Check the trace’s lux value and whether a different routine turned it on.
Make the room dimmer, verify a reading below 30, then cause a new occupancy event.The lamp turns on.Check the helper, entity IDs and raw occupancy state.
Remain detected with the lamp off; lower daylight so the reported value crosses from above 30 to below it.The lamp turns on without a new occupancy event.Check that the lux sensor actually reported a crossing and occupancy stayed on.
With the lamp lit, leave the sensor’s coverage until it has reported clear for three minutes.The lamp turns off even if the lux reading is high.Check for a misplaced darkness condition in the off routine.
Turn the helper off, then create a fresh occupancy or clear-state event.Neither routine changes the lamp.Check both routines use the same helper; inspect other controllers.

Inspect each real run under the automation’s Traces view. Run actions bypasses triggers and top-level conditions, so it cannot prove that the light stays off in a bright room. Test by changing the actual inputs instead.

Frequently asked questions

Should I use 30, 50 or 100 lux?

Use the reading that matches your room and sensor position. Start from observations with the lamp off. If comfortable daylight and uncomfortable dimness produce nearly the same reading, improve placement before endlessly adjusting the number.

What happens if the lux sensor becomes unavailable?

Automatic turn-on cannot pass its numeric check. The separate off routine can still run if occupancy is confirmed clear and the helper is on. Keep manual control available; do not convert a missing reading to zero, which would incorrectly treat it as darkness.

Does this need cloud access or a subscription?

The example uses built-in Home Assistant automation features. Whether the complete routine works during an internet outage depends on how your lamp and sensors connect. Check each integration’s control path; writing local automation logic does not turn a cloud-controlled device into a local one.

For room-by-room planning that includes sensor positions and everyday controls, see Tara’s smart lighting kit with presence detection.