Motion-activated light AND switches

A very basic blueprint for users who love the default “Motion-activated light” blueprint, but want to use switches too. I have elected to switch to an Entity selector instead of the Target selector used in the original (see note below for explanation).

blueprint:
  name: Motion-activated Light and Switch
  description: Turn on a light and/or switch when motion is detected.
  domain: automation
  input:
    motion_entity:
      name: Motion or Occupancy Sensor
      selector:
        entity:
          multiple: false
          filter:
            - device_class: occupancy
              domain: binary_sensor
            - device_class: motion
              domain: binary_sensor
    light_target:
      name: Light
      selector:
        entity:
          multiple: true 
          filter:
            - domain:
                - light
                - switch
    no_motion_wait:
      name: Wait time
      description: Number of seconds motion must be undetected for the light to be turned off.
      default: 120
      selector:
        number:
          min: 0
          max: 3600
          unit_of_measurement: seconds

mode: restart
max_exceeded: silent
triggers:
  - trigger: state
    entity_id: !input motion_entity
    from: "off"
    to: "on"
    id: "on"
  - trigger: state
    entity_id: !input motion_entity
    from: "on"
    to: "off"
    for:
      seconds: !input no_motion_wait
    id: "off"
actions:
  - alias: "Turn on or off the light based on motion"
    action: "homeassistant.turn_{{ trigger.id }}"
    target: 
      entity_id: !input light_target

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.


2024-12-14:

  • Corrected config error.

2024-12-21:

  • Switched to independent triggers to avoid the Wait in the automation.

Note: Explanation of selector change

The use of Area and Device targets will effect all light and/or switch entities in the respective Area/Device. Because the original blueprint could only target lights, there was only a small chance that would have any substantial, negative effects. However, many devices and integrations create virtual switches to cover secondary functions. Haphazardly turning on and off functions like “reset” or “Do Not Disturb” could cause serious issues for users.