Motion Light with Light Switch Override/Cooldown

My first blueprint. Yay!

This is a blueprint for having a motion activated light.

It works with a physical light switch entity (like Shelly) and when the switch is turned on or it has been turned off less than X seconds ago (configurable), the motion does not activate the light. Effectively this gives you a cooldown period before re-activating the light with motion.

The twist here is that it doesn’t use any helper entities, so you can just use it as it is. This is achieved by taking the switch state and checking for the last_changed property, then comparing it with the current time.

The blueprint takes 4 arguments:

  • The motion sensor
  • The light switch entity (not light itself, the position of the physical switch)
  • A light to control
  • Cooldown period after turning the switch off

hey buddy,

It’s strange because when I am trying to use blueprint it’s not possible to choose any light entity.
Looks like there is something wrong with domain of entities… :frowning:

Hey, @pedroza26! This is by design.

This does NOT use a light entity, but a light switch entity, like input from a Shelly.
This way turning it on/off from a phone or another automation does not interfere with the timer.
The only thing that overrides the motion sensor is the physical light switch.

All that aside, you absolutely can use it with a light entity directly, but you need to change the blueprint.
Copy the entire blueprint, save it in your blueprints folder and change the domain of the switch from power to light.

So replace this section:

            name: Light Switch Entity
            selector:
                entity:
                    domain: binary_sensor
                    device_class: power

with this:

            name: Light Entity
            selector:
                entity:
                    domain: light

Hi, I’m searching for automation that works with motion sensor. But additionally, if the light will be turned off (not from motion detection script, but from HA or physical switch) it will cool down for a defined time. Will this one work this way?

Example:
Motion detecion triggers the automation, light turn on. I switch the light off (from HA or from physical switch). The detection will be frozen - for X seconds the light will be turned off.

1 Like

Yes, based on my testing this works like that. You need to define the cooldown period yourself, in other words how long the system will wait.

I got this working fine, thank you!

However there is a clitch. The motion-controlled light newer switches off. I can’t figure it out (being a yaml newbie), your blueprint seems legit:
(…)
trigger:

  • platform: state
    entity_id:
    • !input input_motion_sensor_entity
      id: Motion Triggered
      from: ‘off’
      to: ‘on’
  • platform: state
    entity_id:
    • !input input_motion_sensor_entity
      id: Motion Cleared
      from: ‘on’
      to: ‘off’
      (…)

Don’t know how, but I accidentally got this working (=also switching off when no motion is detected) by changing this:

  • conditions:
    • condition: and
      conditions:
      • condition: trigger
        id: Motion Cleared
      • condition: state
        entity_id: !input input_light_switch_entity
        state: ‘off’
      • condition: template
        value_template: '{{ as_timestamp(now()) - as_timestamp(states[switchEntityVar].last_changed)

        cooldownPeriodVar }}’
        sequence:

    • service: light.turn_off
      target: !input target_light_entity
      to this:
  • conditions:
    • condition: and
      conditions:
      • condition: trigger
        id: Motion Cleared
      • condition: state
        entity_id: !input input_light_switch_entity
        state: ‘on’
      • condition: template
        value_template: '{{ as_timestamp(now()) - as_timestamp(states[switchEntityVar].last_changed)

        cooldownPeriodVar }}’
        sequence:

    • service: light.turn_off
      target: !input target_light_entity

Kinda makes sense to switch “off” from “on”, not from “off”.