8 min read

How to Automate Your Lights with Home Assistant in Minutes

Table of Contents

Introduction

Tired of fumbling for a light switch in the dark? Or maybe you’re just fed up with finding the hallway light left on… again. Smart lighting is one of the most practical and satisfying upgrades you can make to your home, and with Home Assistant, it’s easier than you think to get started.

This guide will walk you through creating a simple yet powerful automation: turning a light on when you enter a room and turning it off automatically after you leave. We’ll keep it simple, explaining each step so that even if you’re new to Home Assistant, you can build a responsive, hands-free lighting system in minutes. Let’s dive in and make your home a little smarter.

Safety First

While this project doesn’t involve high-voltage wiring, it’s always smart to follow some basic precautions to protect your setup and your data.

  • Backup Your System: Before adding new automations or devices, always create a fresh backup of your Home Assistant configuration. Go to Settings > System > Backups.
  • Start Small: Test your automation with a single motion sensor and light before applying the concept to your entire home. This makes troubleshooting much easier.
  • Check Compatibility: Ensure the smart devices you choose are fully compatible with your Home-Assistant setup (Zigbee, Z-Wave, Matter, or Wi-Fi).
  • Secure Your Network: Your smart home is only as secure as your Wi-Fi network. Use a strong password and keep your router’s firmware up to date.

Tools & Materials List

The “tools” for this project are primarily the hardware and software components that make up your smart home.

Hardware:

  • A Home Assistant Installation: This can be on a dedicated device like Home Assistant Green, a Raspberry Pi, or any other supported server.
  • A Compatible Motion Sensor: Zigbee or Z-Wave sensors are often recommended for their speed and reliability.
    • Example: Aqara Motion Sensor P1 (Zigbee), Philips Hue Motion Sensor (Zigbee)
  • A Compatible Smart Light: This can be a smart bulb, a smart switch, or a smart plug connected to a lamp.
    • Example: Philips Hue White and Color Ambiance Bulb, Sengled Smart Bulb, TP-Link Kasa Smart Switch

Software:

  • A web browser to access your Home Assistant dashboard.

Project Prep

Before you can build the automation, you need to make sure Home Assistant can see and control your devices.

  1. Connect Your Devices: Follow the manufacturer’s instructions to pair your motion sensor and smart light with Home Assistant. You should see them appear in Settings > Devices & Services.
  2. Identify Your Entity IDs: Every device in Home Assistant has a unique entity_id. This is how you’ll tell your automation which sensor to listen to and which light to control.
    • Find your motion sensor in the Devices list, click on it, and look for the entity that represents motion (e.g., binary_sensor.hallway_motion).
    • Do the same for your light (e.g., light.hallway_bulb).
    • Pro Tip: Click the gear icon on the entity’s pop-up window to rename the entity_id to something simple and memorable.
  3. Test Your Devices: Manually test each device from the dashboard to confirm they’re working correctly. Wave your hand in front of the sensor and watch its state change to “On” or “Detected.” Use the dashboard to toggle your light on and off. If both work, you’re ready to automate!

Step-by-Step Guide: Creating Your Motion-Light Automation

We’ll use Home Assistant’s visual editor, which makes creating automations a breeze.

  1. Start a New Automation Navigate to Settings > Automations & Scenes. Click the blue + Create Automation button and select Create new automation.

  2. Define the Trigger (The “When”) The trigger is the event that starts your automation. In our case, it’s detecting motion.

    • Under Triggers, click + Add Trigger.
    • Select State as the trigger type.
    • For Entity, choose your motion sensor’s entity ID (e.g., binary_sensor.hallway_motion).
    • In the To field, type on. This tells Home Assistant to run the automation the moment the sensor’s state changes to “on.”
  3. Add the “Turn On” Action (The “Do This”) Now, let’s tell Home Assistant what to do when motion is detected.

    • Scroll down to the Actions section.
    • Click + Add Action and select Call service.
    • In the Service dropdown, find and select light.turn_on.
    • Under Targets, click Choose entity and select your smart light’s entity ID (e.g., light.hallway_bulb).
  4. Add the “Turn Off” Logic (The Smart Part) This is where the magic happens. We don’t want to just turn the light off after a fixed delay; we want to turn it off only when the room has been empty for a while.

    • Click + Add Action again.
    • Select Wait for a trigger.
    • For the trigger, configure it as follows:
      • Trigger Type: State
      • Entity: Your motion sensor entity ID.
      • To: off
      • For: 00:02:00 (This sets a 2-minute timer. The light will only turn off if the sensor has been continuously “off” for 2 minutes). Feel free to adjust this duration.
    • Finally, click + Add Action one last time. Select Call service, choose the light.turn_off service, and target the same light entity as before.
  5. Set the Automation Mode This is a crucial final touch. At the top right of your automation, click the three-dot menu and select Change mode. Choose Restart. This ensures that if new motion is detected while the “turn off” timer is counting down, the entire automation restarts, keeping the light on.

  6. Save and Test Click the Save button at the bottom right. Give your automation a descriptive name like “Hallway Motion Lights.” Now, walk into the room to test it out!

For those who prefer YAML, here is the code for the automation we just built. You can paste this into your automations.yaml file or by switching to YAML mode in the editor. Just remember to replace the entity_ids with your own.

alias: Motion Sensor Light Automation
description: Turn on light when motion is detected, turn off after 2 minutes of no motion.
trigger:
  - platform: state
    entity_id: binary_sensor.hallway_motion
    to: "on"
condition: []
action:
  - service: light.turn_on
    target:
      entity_id: light.hallway_bulb
  - wait_for_trigger:
      - platform: state
        entity_id: binary_sensor.hallway_motion
        to: "off"
        for:
          hours: 0
          minutes: 2
          seconds: 0
  - service: light.turn_off
    target:
      entity_id: light.hallway_bulb
mode: restart

Finishing Touches & Cleanup

Once your automation is saved, it’s time for real-world testing and refinement.

  • Test the “On” State: Walk into the designated area. The light should turn on almost instantly. If it doesn’t, double-check that your entity IDs are correct and the sensor’s battery is good.
  • Test the “Off” State: Leave the area and start a timer. The light should turn off after the duration you specified (e.g., 2 minutes).
  • Adjust the Timer: If the light turns off too quickly, increase the for: duration in the “Wait for a trigger” step. For a busy hallway, 1-2 minutes is good. For a bathroom or closet, 3-5 minutes might be better.
  • Consider Room Type: This automation is perfect for transient spaces like hallways, laundry rooms, and closets. For rooms where you might sit still for long periods (like a living room or office), a standard motion sensor can be frustrating. For those areas, consider upgrading to a presence sensor (like the Aqara FP2) that can detect you even when you’re not moving.

Conclusion

Congratulations! You’ve just created a practical, energy-saving automation that makes your home feel more intuitive and responsive. This simple motion-activated light is a foundational project in home automation. From here, you can expand on it by adding conditions (like only running it at night), controlling multiple lights at once with light groups, or even changing the light’s color and brightness based on the time of day.

Welcome to the endlessly creative world of Home Assistant. Happy automating