Update: Home Assistant Blueprint - Advanced Motion Detection
Optimize Home Assistant blueprints with dual sensors, switches, and automation logic. Helpers simplify conditions, boost reusability, and avoid clutter. Real-world 'Mode' helper controls lighting, climate, security. For HA enthusiasts seeking clean, scalable setups.
Featured Home Assistant Blueprint
Recently, my home assistant blueprint was featured on XDA (No. 1 on this list), which was a pleasant surprise since XDA is a site I regularly read. I’m always interested in learning about new containers, open source software solutions, and their staple “7 best ...” articles.
However, I do wonder why so many articles never link back to the original source—but whatever, I can always Google it.
The blueprint in question lets you use motion detectors, along with an optional entity state condition and sun position, to determine if certain lights should be switched on. It also allows you to configure light settings (such as color and brightness), if applicable.
Home Assistant is moving into the voice game!
Unfortunately, when I returned to the blueprint exchange a few months later, I realized there were several responses that needed to be addressed. I also needed to enable notifications so I’d receive emails about replies in the future.
There were several requests for enhancements. While some were great ideas, others seemed to overcomplicate a standard blueprint. With that in mind, I’d like to review some recent changes and discuss the power of helpers.
Motion Sensor Blueprint Updates
The two biggest requests were:
- Expand the input domains from motion to also include occupancy
- Expand target entity's from lights to also include switches
Expanding Sensor Domains
The original code limited selections to motion sensors:
input:
motion_sensors:
name: Motion Sensors
description: Select one or more motion sensors.
selector:
entity:
domain: binary_sensor
device_class: motion
multiple: trueI updated this section to include occupancy sensors:
input:
motion_sensors:
name: Motion and Occupancy Sensors
description: Select one or more motion or occupancy sensors.
selector:
entity:
domain: binary_sensor
device_class:
- motion
- occupancy
multiple: trueHandling Lights vs. Switches
The more complex update involved supporting both lights and switches. First, I expanded the target entities:
entity_target:
name: Lights and Switches
description: Select one or more lights or switches to control.
selector:
target:
entity:
domain:
- light
- switchThen added conditional logic to handle different entity types:
- choose:
- conditions:
- condition: template
value_template: "{{ 'light.' in entity_target.entity_id|string }}"
sequence:
- service: light.turn_on
target: !input entity_target
data:
brightness: !input brightness
rgb_color: !input color
- conditions:
- condition: template
value_template: "{{ 'switch.' in entity_target.entity_id|string }}"
sequence:
- service: switch.turn_on
target: !input entity_targetAnd since we are evaluating the target, we need to define it as a variable:
variables:
entity_target: !input entity_targetHelpers Are Your Friends
One frequent request I received was enhancing conditional entities to accept light sensors (evaluating luminance percentages) or time-of-day checks to avoid automation triggers during specific hours. While I could have modified the blueprint to handle these edge cases, I chose a simpler path: helpers.
Here’s why I recommended helpers instead of overcomplicating the blueprint:
- Reduced complexity: No need to overhaul existing blueprints for niche use cases.
- Reusability: Custom helpers work across multiple automations, not just one.
- Flexibility: Users can manually adjust helper states or automate them independently.
Real-World Example: The "Mode" Helper
My mode helper acts as a universal condition for automations, representing household states like:
- 🌅 Morning
- 🌆 Evening
- 🛌 Bedtime
- 🛋️ Relaxing
- 🌙 Goodnight
I update this helper through:
- Motion/activity triggers
- Alexa voice commands
- Scene activations
This single helper then controls lighting routines, thermostat adjustments, and security automations, creating a cohesive system without blueprint spaghetti.
