Turn off switch after timeout with no motion

This is a generic blueprint meant to turn off things that were left on.

Fill in the

  • Motion Detector
  • Switch
  • Stay On Time (minutes)
  • Grace Period (minutes, 0 to disable)
  • Delay before starting grace period (seconds)

and this blueprint will:

  • Turn off the switch after it has been on, without the motion detector firing, for at least “Stay On Time”
  • If, after turning off and waiting for “Arm Delay” second, motion is detected within “Grace Period” then the switch will turn back on.

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

blueprint:
  name: Turn off unoccupied switches
  source_url: https://gist.github.com/cobryan05/24f19bad93b642b7e0c5f8f1da0515d0
  description: Turn off a switch that has been left on with no motion
  domain: automation
  input:
    motion_entity:
      name: Motion Sensor
      selector:
        entity:
          domain: binary_sensor
          device_class: motion
    switch_entity:
      name: Switch
      selector:
          entity:
            domain: switch
    wait_time_selector:
      name: Stay On Time
      description: Time to keep switch on with no motion
      default: 30
      selector:
        number:
          min: 1
          max: 1440
          unit_of_measurement: minutes
    grace_period_selector:
      name: Grace Period
      description: After turning off the switch, turn it back on if motion is detected within grace period
      default: 30
      selector:
        number:
          min: 0
          max: 1440
          unit_of_measurement: minutes
    grace_arm_delay_selector:
      name: Grace Arm Delay Period
      description: Delay before starting grace period (to prevent the act of turning off the switch from triggering the sensor)
      default: 2
      selector:
        number:
          min: 0
          max: 60
          unit_of_measurement: seconds

mode: single


trigger:
  - platform: state
    entity_id: !input switch_entity
    to: 'on'
    for:
      minutes: !input wait_time_selector

  - platform: state
    entity_id: !input motion_entity
    to: 'off'
    for:
      minutes: !input wait_time_selector

condition:
  - condition: state
    entity_id: !input switch_entity
    state: 'on'
    for:
      minutes: !input wait_time_selector

  - condition: state
    entity_id: !input motion_entity
    state: 'off'
    for:
      minutes: !input wait_time_selector

action:
  - service: switch.turn_off
    entity_id: !input switch_entity

  - delay:
       seconds: !input grace_arm_delay_selector

  - wait_for_trigger:
    - platform: state
      entity_id: !input motion_entity
      to: 'on'
    - platform: state
      entity_id: !input switch_entity
      to: 'on'
    timeout:
      minutes: !input grace_period_selector
    continue_on_timeout: false

  - service: switch.turn_on
    entity_id: !input switch_entity
5 Likes

Simple works great but if you cold be so kind to how can i add a delay to restart my poblem is when the trigger goes off to trun the switch to off the sensor see a light change esp at night and resart the script when in fact it is not seeing rea motion just the light turning off so where would i put the delay to rerun thank you

That’s simple enough. My motion sensors are passive infrared, so they don’t usually ‘see’ light changes.

I don’t want to set a precedent that I’m going to be responsive in updating this (because I likely won’t be), but I went ahead and updated the blueprint with that delay for you.

I understand many thanks!..

This is Perfect ! Thanks!

Thank you for your great work.

I have a little question.

Is it also possible to add a domain selection.

because sometimes I have a switch that’s be recognized as a light.

Kind regards Chris from the Netherlands.

That would make it a different blueprint all together.
My suggestion is to make a copy of this blueprint and edit it.
Replace all the stuff where it references the switch and switch domain to light and light domain.
It would be a great learning experience, and the whole template and logic is already there.
And think how cool you would feel if you did it yourself!

I will try.
I will try to find out how it works.
thanks for your response.