Skip to content

Instantly share code, notes, and snippets.

@WilliamBerryiii
Last active September 11, 2022 01:12
Show Gist options
  • Save WilliamBerryiii/98fb23f1fe3bcc7097e6a258872c9c1b to your computer and use it in GitHub Desktop.
Save WilliamBerryiii/98fb23f1fe3bcc7097e6a258872c9c1b to your computer and use it in GitHub Desktop.
blueprint:
name: Lights Off (No Motion)
description: Turn off lights when multiple motion sensors are nolonger occupied
domain: automation
input:
motion_sensors:
name: Motion Sensors
description: The pair of sensors that will control the light
selector:
entity:
domain: binary_sensor
target_light:
name: Lights
description: The lights to turn off when motion is no longer detected
selector:
entity:
domain: light
target_switch:
name: Switch
description: The light switch to turn on when motion is detected
selector:
entity:
domain: light
room_timer:
name: Timer
description: The room's boost timer
selector:
entity:
domain: timer
scene_selector:
name: Scene Selector Script
description: The room's scene selector script
selector:
entity:
domain: script
trigger:
- platform: state
entity_id:
- !input motion_sensors
to: "off"
- platform: state
entity_id:
- !input room_timer
from: active
to: idle
id: boost_timer_elapsed
condition: []
action:
- if:
- condition: state
entity_id: !input target_switch
state: "off"
then:
- stop: Lights already turned off
- if:
- condition: trigger
id: boost_timer_elapsed
- condition: state
entity_id: !input motion_sensors
state: "on"
then:
- service: script.turn_on
target:
entity_id: !input scene_selector
data: {}
- stop: Boost timer elapsed, and room occupied
- if:
- condition: state
entity_id: !input room_timer
state: "active"
then:
- stop: Boot timer still running
else:
- service: light.turn_off
target:
entity_id: !input target_light
- if:
- condition: state
entity_id: !input room_timer
state: "idle"
- condition: state
entity_id: !input motion_sensors
state: "off"
then:
- service: light.turn_off
target:
entity_id: !input target_light
mode: single
blueprint:
name: Room Motion Detected, Turn Lights On
description: Turn on lights when motion sensor(s) detects occupancy
domain: automation
input:
motion_sensors:
name: Motion Sensors
description: The sensor(s) that will control the light(s)
selector:
entity:
domain: binary_sensor
target_light:
name: Lights
description: The light(s) to use for boost mode
selector:
entity:
domain: light
target_switch:
name: Switch
description: The light switch to turn on when motion is detected
selector:
entity:
domain: light
room_timer:
name: Timer
description: The room's boost timer
selector:
entity:
domain: timer
scene_selector:
name: Scene Selector Script
description: The room's scene selector script
selector:
entity:
domain: script
trigger:
- platform: state
entity_id:
- !input motion_sensors
to: "on"
condition: []
action:
- if:
- condition: state
entity_id: !input room_timer
state: "active"
then:
- stop: Timer Still Active
- if:
- condition: state
entity_id: !input target_switch
state: "off"
then:
- service: light.turn_on
target:
entity_id:
- !input target_switch
# we delay for 2 seconds to allow the lights to re-join the zigbee network and for the scene to queue in the Hue Hub
- delay:
hours: 0
minutes: 0
seconds: 2
milliseconds: 0
- service: script.turn_on
target:
entity_id: !input scene_selector
data: {}
else:
- service: script.turn_on
target:
entity_id: !input scene_selector
data: {}
mode: single
blueprint:
name: Switch Tap for On or Boost
description: Turn on lights or boost when a wall switch is pressed. Boost can be set for upto 20 min. with two button presses
domain: automation
# This blueprint functions under the following home automation installation assumption:
# - Each room has smart lights controlled by Philips Hue
# - Each room has a zigbee/zwave switch that controls power to the smart lights, and that can fire repeated "on" or "off" events
# - Each room has a motion sensor that has both motion and occupancy (e.g. Aqara)
# - Each room has a timer "helper" assigned to it
#
# The script runs in a queue mode so that regardless of the order of Home Assistant firing the light switch's state change or
# the ZHA_Event, the script will likely do the right thing. Further it will ensure that multiple repeated presses of the switch
# "on" button/toggle the correct boost time is calcualted.
input:
zha_event_data:
name: ZHA Device Id
description: The event data blob from a light switch press
selector:
object:
motion_sensors:
name: Motion Sensors
description: The pair of sensors that will control the light
selector:
entity:
domain: binary_sensor
target_light:
name: Lights
description: The light(s) to turn on when motion is detected
selector:
entity:
domain: light
daytime_boost_scene:
name: Daytime Boost Scene
description: The scene to use for boosting during the day
selector:
target:
entity:
domain: scene
evening_boost_scene:
name: Nighttime Boost Scene
description: The scene to use for boosting during the night
selector:
target:
entity:
domain: scene
target_switch:
name: Switch
description: The light switch to turn on when motion is detected
selector:
entity:
domain: light
room_timer:
name: Timer
description: The room's boost timer
selector:
entity:
domain: timer
scene_selector:
name: Scene Selector Script
description: The room's selector script that determines the scene to set given the time of day
selector:
entity:
domain: script
variables:
room_timer: !input room_timer
trigger:
- platform: state
entity_id:
- !input target_switch
from: "off"
to: "on"
id: switch_turned_on
- platform: event
event_data: !input zha_event_data
event_type: zha_event
id: switch_on_event
- platform: state
entity_id:
- !input target_switch
from: "on"
to: "off"
id: switch_off_event
condition: []
action:
- if:
- condition: trigger
id: switch_off_event
then:
- service: timer.cancel
target:
entity_id: !input room_timer
- service: light.turn_off
target:
entity_id: !input target_light
- stop: Cancel execution as switch was turned off
- if:
# if the zha event fired and the ligths are on and the timer is running, set the boost timer to add time
- condition: trigger
id: switch_on_event
- condition: state
entity_id:
- !input target_light
state: "on"
- condition: state
entity_id:
- !input room_timer
state: "active"
then:
- if:
# if the timer addition of 10 minutes is less than 30 minutes, add the 10 min
- "{{ (as_datetime(state_attr(room_timer, 'finishes_at')) - now() + timedelta(minutes = 10)).seconds < 1800 }}"
then:
- service: timer.start
target:
entity_id: !input room_timer
data:
duration: "{{ (as_datetime(state_attr(room_timer, 'finishes_at')) - now() + timedelta(minutes = 10)).seconds | int(1200) }}"
else:
# else just set the timer to the max 30 minute value
- service: timer.start
target:
entity_id: !input room_timer
data:
duration: 1800
- stop: Boost timer set for extra time
- if:
# if the switch turned on event fired and the lights are off, wait 3 seconds and run the scene selector
- condition: trigger
id: switch_turned_on
- condition: state
entity_id:
- !input target_light
state: "off"
then:
- delay:
hours: 0
minutes: 0
seconds: 3
milliseconds: 0
- service: script.turn_on
target:
entity_id: !input scene_selector
data: {}
- stop: Running Scene Selector
- if:
# if the switch was pressed and the lights are on, set the boost for the room
- condition: trigger
id: switch_on_event
- condition: state
entity_id:
- !input target_light
state: "on"
then:
- if:
- condition: time
before: input_datetime.chill
after: 06:00:00
then:
- service: scene.turn_on
data: {}
target: !input daytime_boost_scene
else:
- service: scene.turn_on
data: {}
target: !input evening_boost_scene
- service: timer.start
data:
duration: 00:10:00
target:
entity_id: !input room_timer
mode: queued
max: 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment