Skip to content

Instantly share code, notes, and snippets.

@cvele
Last active June 19, 2024 14:01
Show Gist options
  • Save cvele/f55cc01a3eb67a6e7bdfe125b7c1d0c7 to your computer and use it in GitHub Desktop.
Save cvele/f55cc01a3eb67a6e7bdfe125b7c1d0c7 to your computer and use it in GitHub Desktop.
blueprint:
name: Room Scene Selector
description:
Automate scene selection and light management in a room using button
presses, motion sensors, and optional hold actions.
domain: automation
input:
scene_helper:
name: Scene Selection Helper
description: Select the input helper that holds the scene IDs.
selector:
entity:
filter:
- domain:
- input_select
multiple: false
button_devices:
name: Button Devices
description:
Choose the button devices to trigger scene selection on a single
press.
selector:
entity:
domain:
- sensor
multiple: true
target_areas:
default: []
name: Target Areas for Light Control
description:
Select the areas where lights should be turned off on a double
press.
selector:
area:
multiple: true
target_lights:
default: []
name: Target Lights for Control
description:
Select the lights to turn off on a double press or automatically
if a delay is set.
selector:
entity:
domain:
- light
multiple: true
auto_off_delay:
name: Automatic Turn Off Delay
description:
Set the delay before lights turn off automatically (set to 0 to
disable).
default: 0:00:00
selector:
duration: {}
hold_action:
name: Hold Action
description: Select an optional automation or script to execute on a hold action.
default: ""
selector:
entity:
filter:
- domain:
- automation
- domain:
- script
- domain:
- scene
multiple: false
occupancy_sensor:
default: []
name: Motion Sensor
description:
Choose a motion sensor to monitor occupancy. Lights will turn off
if no motion is detected for a specified duration.
selector:
entity:
device_class:
- motion
multiple: false
occupancy_sensor_duration:
name: Motion Sensor Duration
description:
Specify the duration the motion sensor must stay clear to turn
off the lights.
default: 0:45:00
selector:
duration: {}
source_url: https://gist.github.com/cvele/f55cc01a3eb67a6e7bdfe125b7c1d0c7
mode: restart
variables:
scene_helper_entity: !input scene_helper
auto_off_delay: !input auto_off_delay
hold_action_entity: !input hold_action
occupancy_sensor_entity: !input occupancy_sensor
trigger:
- id: single
platform: state
entity_id: !input button_devices
to: single
- id: double
platform: state
entity_id: !input button_devices
to: double
- id: hold
platform: state
entity_id: !input button_devices
to: hold
- id: occupancy
platform: state
entity_id: !input occupancy_sensor
to: "off"
for: !input occupancy_sensor_duration
condition: []
action:
- if:
- condition: trigger
id:
- occupancy
then:
- service: light.turn_off
metadata: {}
data:
transition: 2
target:
area_id: !input target_areas
entity_id: !input target_lights
- if:
- condition: trigger
id:
- single
then:
- service: input_select.select_next
target:
entity_id: !input scene_helper
data:
cycle: true
- service: scene.turn_on
target:
entity_id: "{{ states(scene_helper_entity) }}"
- if:
- condition: trigger
id:
- double
then:
- service: light.turn_off
metadata: {}
data:
transition: 2
target:
area_id: !input target_areas
entity_id: !input target_lights
- service: input_select.select_first
metadata: {}
data: {}
target:
entity_id: input_select.livingroom_scene_helper
- if:
- condition: trigger
id:
- single
- condition: template
value_template: "{{ not (auto_off_delay == '0:00:00') }}"
then:
- delay: "{{ auto_off_delay }}"
- service: light.turn_off
data:
transition: 2
target:
entity_id: !input target_lights
- if:
- condition: trigger
id:
- hold
- condition: template
value_template: "{{ hold_action_entity != '' }}"
then:
- choose:
- conditions: "{{ hold_action_entity.startswith('automation.') }}"
sequence:
- service: automation.trigger
target:
entity_id: "{{ hold_action_entity }}"
- conditions: "{{ hold_action_entity.startswith('script.') }}"
sequence:
- service: script.turn_on
target:
entity_id: "{{ hold_action_entity }}"
- conditions: "{{ hold_action_entity.startswith('scene.') }}"
sequence:
- service: scene.turn_on
target:
entity_id: "{{ hold_action_entity }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment