Skip to content

Instantly share code, notes, and snippets.

@Phara0h
Last active January 16, 2021 00:18
Show Gist options
  • Save Phara0h/bd658769780d78db1c7360181862bdd2 to your computer and use it in GitHub Desktop.
Save Phara0h/bd658769780d78db1c7360181862bdd2 to your computer and use it in GitHub Desktop.
Turn on a entity when motion is detected, with optional night only mode
blueprint:
name: Motion-activated Switch/Light
description: Turn on a Switch or light when motion is detected, with optional night only mode
domain: automation
source_url: https://github.com/home-assistant/core/blob/dev/homeassistant/components/automation/blueprints/motion_light.yaml
input:
motion_entity:
name: Motion Sensor
selector:
entity:
domain: binary_sensor
device_class: motion
light_target:
name: Target
selector:
target:
night_only:
name: Only on at night?
default: false
selector:
boolean:
no_motion_wait:
name: Wait time
description: Time to leave the light on after last motion is detected.
default: 0
selector:
number:
min: 0
max: 3600
unit_of_measurement: seconds
# If motion is detected within the delay,
# we restart the script.
mode: restart
max_exceeded: silent
variables:
night_only: !input night_only
no_motion_wait: !input no_motion_wait
trigger:
platform: state
entity_id: !input motion_entity
from: "off"
to: "on"
condition:
condition: or
conditions:
- condition: and
conditions:
- condition: state
entity_id: sun.sun
state: below_horizon
- condition: template
value_template: "{{ night_only }}"
- condition: template
value_template: "{{ night_only == false }}"
action:
- service: homeassistant.turn_on
target: !input light_target
- wait_for_trigger:
platform: state
entity_id: !input motion_entity
from: "on"
to: "off"
for:
seconds: !input no_motion_wait
- service: homeassistant.turn_off
target: !input light_target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment