Skip to content

Instantly share code, notes, and snippets.

@codezz
Last active January 21, 2025 20:38
Show Gist options
  • Select an option

  • Save codezz/c125c10870376ff90d7a8db02c445eec to your computer and use it in GitHub Desktop.

Select an option

Save codezz/c125c10870376ff90d7a8db02c445eec to your computer and use it in GitHub Desktop.
Control a switch using a motion sensor with OFF/ON/AUTO modes.
blueprint:
name: Device Control with Mode Helper and Custom Actions
description: Control actions using any device's triggers with OFF/ON/AUTO modes.
domain: automation
input:
motion_occupied_trigger:
name: Occupied Trigger
description: Select the trigger for when motion/occupancy is detected
selector:
trigger: {}
motion_not_occupied_trigger:
name: Not Occupied Trigger
description: Select the trigger for when no motion/occupancy is detected
selector:
trigger: {}
mode_helper:
name: Mode Helper
description: The input_select entity used to control the mode (OFF, ON, AUTO).
selector:
entity:
domain: input_select
on_action:
name: Turn On Action
description: Action to execute when occupancy is detected (in AUTO mode) or when ON mode is selected
selector:
action: {}
off_action:
name: Turn Off Action
description: Action to execute when no occupancy is detected (in AUTO mode) or when OFF mode is selected
selector:
action: {}
occupied_delay:
name: Occupied Delay (seconds)
description: Additional delay after occupancy is detected before executing ON action (in AUTO mode).
default: 0
selector:
number:
min: 0
max: 3600
unit_of_measurement: seconds
mode: slider
not_occupied_delay:
name: Not Occupied Delay (seconds)
description: Additional delay after no occupancy is detected before executing OFF action (in AUTO mode).
default: 0
selector:
number:
min: 0
max: 3600
unit_of_measurement: seconds
mode: slider
trigger:
- platform: state
entity_id: !input mode_helper
id: mode_change
- platform: template
id: motion_occupied_trigger
value_template: "{{ true }}"
variables:
trigger_data: !input motion_occupied_trigger
- platform: template
id: motion_not_occupied_trigger
value_template: "{{ true }}"
variables:
trigger_data: !input motion_not_occupied_trigger
condition: []
action:
- choose:
- conditions:
- condition: template
value_template: >
{{ trigger.id == 'mode_change' and
trigger.to_state.state == 'OFF' }}
sequence: !input off_action
- conditions:
- condition: template
value_template: >
{{ trigger.id == 'mode_change' and
trigger.to_state.state == 'ON' }}
sequence: !input on_action
- conditions:
- condition: template
value_template: >
{{ trigger.id == 'motion_occupied_trigger' }}
- condition: state
entity_id: !input mode_helper
state: 'AUTO'
sequence:
- delay:
seconds: !input occupied_delay
- choose: []
default: !input on_action
- conditions:
- condition: template
value_template: >
{{ trigger.id == 'motion_not_occupied_trigger' }}
- condition: state
entity_id: !input mode_helper
state: 'AUTO'
sequence:
- delay:
seconds: !input not_occupied_delay
- choose: []
default: !input off_action
mode: restart
# Usage Instructions:
# 1. Select the appropriate triggers for occupied and not occupied states
# 2. Set up your mode helper with OFF/ON/AUTO options
# 3. Configure your desired actions for both ON and OFF states
# 4. Adjust delays if needed
# To create an input_select helper in Home Assistant:
# 1. Go to Settings > Devices & Services > Helpers
# 2. Click on "Create Helper" and select "Dropdown" (input_select)
# 3. Name the helper (e.g., Living Room Mode)
# 4. Add the options "OFF", "ON", and "AUTO"
# 5. Use this helper when setting up the blueprint by selecting it in the "Mode Helper" field
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment