I recently set up a motion sensor and lighting automation in my home, and I wanted to share my experience in case it helps others who are looking to achieve similar results. 
The Goal:
I wanted to create an automation where the lights in my hallway would turn on when motion is detected and stay on for 30 seconds before turning off automatically. This would provide enough light for me to navigate the space without needing to manually switch the lights on or off.
The Setup:
I’m using a Hue motion sensor and an Osram Classic A60 light bulb. The motion sensor detects occupancy and sends signals to Home Assistant, which then triggers the light to turn on and off based on the defined automation rules.
The Automation Rules:
Here’s the configuration I used in my configuration.yaml file:
yaml
alias: Motion Sensor Automation
description: “Turns hallway lights on when motion is detected and off after 30 seconds”
trigger:
- platform: device
device_id: my_motion_sensor_id
entity_id: binary_sensor.my_motion_sensor_occupancy
domain: binary_sensor
condition: - condition: or
conditions:- condition: sun
after: sunset - condition: sun
before: sunrise
action:
- condition: sun
- service: light.turn_on
data:
brightness_pct: 20
target:
entity_id: light.my_light_bulb - delay: 30 seconds
- service: light.toggle
data:
brightness_pct: 0
target:
entity_id: light.my_light_bulb
The Outcome:
This setup works perfectly! When I enter the hallway, the lights come on with a dimmed brightness, which is gentle on the eyes. After 30 seconds of no further motion, the lights turn off automatically. This has been a huge convenience, especially at night when I don’t want to fumble with switches in the dark.
Lessons Learned:
- Testing: I recommend testing your automation thoroughly to ensure it behaves as expected. I did this by manually triggering the motion sensor and observing the light’s behavior.
- Timing: The 30-second delay was crucial. It’s long enough to provide adequate lighting but short enough to prevent unnecessary energy consumption.
- Dimming: Starting with a dimmed brightness was a nice touch. It prevents sudden, blinding light in low-light conditions.
Tips for Others:
- If you’re using a different motion sensor, make sure to adjust the
device_idandentity_idin your configuration accordingly. - Consider integrating this automation with other smart home devices, such as door sensors, to create a more comprehensive smart home experience.
Overall, I’m thrilled with how this automation has improved my daily routine. It’s a simple yet effective way to make my home smarter and more convenient. 
If anyone has questions or suggestions for improving this setup, I’d love to hear them!