How to Automate a Smart Bulb with a Motion Sensor in Home Assistant

Hallway that has a motion sensor that automates turning on a light.
Hallway that has a motion sensor that automates turning on a light.

In This Article

Want your lights to turn on automatically when you walk into a room? In this guide, we’ll walk through how to use a motion sensor and a smart bulb in Home Assistant to create a responsive, hands-free lighting setup, complete with easy-to-use YAML code at the bottom of this article so you can copy and customize.

Jump To

Smart lighting is one of the most satisfying upgrades you can make to your home. With the right automation, your lights can turn on exactly when you need them and turn off when you leave. No more fumbling for switches or wasting energy when accidentally leaving lights on. In this guide, I’ll show you how to connect a motion sensor and a smart bulb in Home Assistant so that walking into a room automatically triggers the light. We’ll keep things simple but also explain each step, so even if you’re new to Home Assistant, you’ll understand how it works.

Step 1: Choose Your Devices

Before we create the automation, you’ll need two compatible devices:

For the best reliability, I recommend Zigbee or Z-Wave motion sensors paired with bulbs connected directly to your hub. Wi-Fi devices work too, but they may have slightly more delay.

Step 2: Connect Devices to Home Assistant

Open Home Assistant and make sure both the motion sensor and the smart bulb appear in Settings → Devices & Services. If either device is missing, follow the manufacturer’s pairing instructions to add it.
Once paired, test them individually:

  • Wave your hand in front of the motion sensor and confirm it shows as “Detected” or “On” in Home Assistant.
  • Turn your smart bulb on and off from the dashboard to make sure it responds.

Step 3: Plan Your Automation

Our automation will work like this:

  1. When the motion sensor detects movement, the light turns on.
  2. If no motion is detected for a set time (like 2-5 minutes depending on the room), the light turns off automatically.

This setup is ideal for spaces like hallways, closets, garages, or bathrooms where you don’t want lights on all the time. Rooms like a living room where you will be sitting down, will become frustrating because the motion sensor won’t see you sitting down for long periods of time. In that case, I’d recommend using a presence sensor.

Step 4: Create the Automation in YAML

You can make this automation in the visual editor, but YAML gives you more control and is easier to share. Here’s a simple example:

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:
          minutes: 2
  - service: light.turn_off
    target:
      entity_id: light.hallway_bulb
mode: restart

Be sure to replace any entity ids with your own entity ids.

How It Works

  • Trigger: The automation starts when the motion sensor turns “on.”
  • Action Step 1: The light is turned on immediately.
  • Wait for Trigger: Home Assistant waits until the motion sensor is “off” for 2 minutes (in this example).
  • Action Step 2: Once no motion is detected for that time, the light turns off.
  • Mode Restart: This ensures that if motion happens again while the timer is running, the timer resets instead of turning the light off prematurely.

Step 5: Save and Test

After saving the automation, walk into the room to trigger it. Then leave and wait the set amount of time to see if the light turns off automatically. If there’s a delay, check the motion sensor’s responsiveness and battery level.

Conclusion

Automating a smart bulb with a motion sensor is one of the simplest ways to make your home feel truly “smart.” It’s energy efficient, convenient, and once you’ve got the basics down, you can add extra features like dimming at night, only triggering during certain hours, or using multiple sensors.

With Home Assistant’s flexibility, this basic automation can become part of a much larger smart home ecosystem, all starting from a single motion sensor and light.

FAQs: Motion Sensor Light Automation in Home Assistant

Can I use more than one motion sensor for a single light?

Yes. You can add multiple motion sensors to the automation’s trigger list in YAML or the visual editor. This is useful for larger spaces where a single sensor may not detect motion from every angle.

How do I make the light turn on only at night?

You can add a condition to check for the sun’s position or use time-based conditions. For example, you could set the automation to run only after sunset or between certain hours.

Will this work with multiple smart bulbs or switches?

Yes. Instead of one entity_id for the light, you can use a light group or add multiple entity IDs to the target section so they all turn on and off together.

What if the motion sensor keeps the light on when I don’t want it to?

You can adjust the wait_for_trigger time or the motion sensor’s built-in “clear” time. Shortening these times will make the light turn off faster after motion stops.

Can I make the light dim instead of turning off completely?

Yes. Instead of using light.turn_off in the final action, you can use light.turn_on with a lower brightness level. This works well for night lighting so the room isn’t completely dark.

Share the Post:

Disclaimer: Some of the links in this post are affiliate links, including Amazon. If you click through and make a purchase, we may earn a small commission at no extra cost to you. This helps support the site and allows us to continue providing helpful content. We only recommend products we personally use or trust.

Jump To

Related Posts

smart home automation that is running in the home
Automation Ideas

5 Smart Home Automations That Actually Improves Your Daily Life

Smart home automations go beyond convenience and focus on making daily life smoother and more efficient. From lighting that adjusts to your routine to systems that improve security and save energy, the right automations work quietly in the background. When designed thoughtfully, they reduce effort rather than add complexity and make a home feel intuitive instead of technical.

Read More »
room that has smart lights vs room with smart switch
Smart Home Basics

Smart Switches vs Smart Bulbs: Which is Better For Your Smart Home?

Choosing between smart switches and smart bulbs affects your smart home’s cost, functionality, and convenience. By understanding how each option works, their advantages and limitations, and which rooms need which solution, you’ll make the right decision for your home and save money while getting the features you actually need.

Read More »