Skip to content

Instantly share code, notes, and snippets.

@samuolis
Last active October 14, 2022 22:39
Show Gist options
  • Save samuolis/c357b00b2506fc86651f0feba442a2d0 to your computer and use it in GitHub Desktop.
Save samuolis/c357b00b2506fc86651f0feba442a2d0 to your computer and use it in GitHub Desktop.
Senic switch with default light
blueprint:
name: SENIC switch control buttons with default
description: 'Controller automation for executing press/hold/release EnOcean PTM 215Z (Friends of Hue) switch.'
domain: automation
input:
controller_entity:
name: (Zigbee2MQTT) Controller Entity
description: The action sensor of the controller to use for the automation.
default: ''
selector:
entity:
domain: sensor
hold_delay:
name: Hold delay
description: If the button has been held more than the configured Hold delay, the corresponding held action is triggered.
default: 500
selector:
number:
min: 100.0
max: 1000.0
unit_of_measurement: milliseconds
mode: box
step: 10.0
light_dim_step:
name: Dim step
description: If the button has been held light changes by dim step.
default: 10
selector:
number:
min: 0.0
max: 100.0
mode: box
step: 1.0
light_target_for_left:
name: Light to control with left button
default: []
selector:
target:
entity:
domain: light
light_target_for_right:
name: Light to control with right button
default: []
selector:
target:
entity:
domain: light
variables:
dim_input: !input light_dim_step
negative_dim_value: "{{ dim_input|float * (-1.0) }}"
light_target_for_left: !input light_target_for_left
light_target_for_left_entity_list: >-
{%- if light_target_for_left.entity_id is string -%}
{{ [light_target_for_left.entity_id] }}
{%- else -%}
{{ light_target_for_left.entity_id }}
{%- endif -%}
light_target_for_right: !input light_target_for_right
light_target_for_right_entity_list: >-
{%- if light_target_for_right.entity_id is string -%}
{{ [light_target_for_right.entity_id] }}
{%- else -%}
{{ light_target_for_right.entity_id }}
{%- endif -%}
all_entities: >-
{%- set data = namespace(e=light_target_for_left_entity_list) -%}
{%- for e in light_target_for_right_entity_list -%}
{%- set data.e = data.e + [e] -%}
{% endfor %}
{{ data.e }}
mode: restart
max_exceeded: silent
trigger:
- platform: event
event_type: state_changed
event_data:
entity_id: !input 'controller_entity'
condition: '{{ trigger.event.data.new_state.state not in ["","None"] }}'
action:
- variables:
trigger_action: '{{ trigger.event.data.new_state.state }}'
- choose:
- conditions: '{{ "press_" | string in trigger_action }}'
sequence:
- wait_for_trigger:
- platform: state
entity_id: !input 'controller_entity'
to: "release_1"
- platform: state
entity_id: !input 'controller_entity'
to: "release_2"
- platform: state
entity_id: !input 'controller_entity'
to: "release_3"
- platform: state
entity_id: !input 'controller_entity'
to: "release_4"
- platform: state
entity_id: !input 'controller_entity'
to: "release_1_and_3"
- platform: state
entity_id: !input 'controller_entity'
to: "release_2_and_4"
timeout:
milliseconds: !input 'hold_delay'
- choose:
- conditions: '{{ trigger_action == "press_1" and wait.trigger != None }}'
sequence:
- service: light.turn_on
data:
brightness_step_pct: 100
entity_id: "{{ light_target_for_left_entity_list }}"
- conditions: '{{ trigger_action == "press_2" and wait.trigger != None }}'
sequence:
- service: light.turn_off
data:
entity_id: "{{ light_target_for_left_entity_list }}"
- conditions: '{{ trigger_action == "press_3" and wait.trigger != None }}'
sequence:
- service: light.turn_on
data:
brightness_step_pct: 100
entity_id: "{{ light_target_for_right_entity_list }}"
- conditions: '{{ trigger_action == "press_4" and wait.trigger != None }}'
sequence:
- service: light.turn_off
data:
entity_id: "{{ light_target_for_right_entity_list }}"
- conditions: '{{ trigger_action == "press_1_and_3" and wait.trigger != None }}'
sequence:
- service: light.turn_on
data:
brightness_step_pct: 100
entity_id: "{{ all_entities }}"
- conditions: '{{ trigger_action == "press_2_and_4" and wait.trigger != None }}'
sequence:
- service: light.turn_off
data:
entity_id: "{{ all_entities }}"
- conditions: '{{ trigger_action == "press_1" and wait.trigger == None }}'
sequence:
- service: light.turn_on
data:
brightness_step_pct: !input 'light_dim_step'
entity_id: "{{ light_target_for_left_entity_list }}"
- conditions: '{{ trigger_action == "press_2" and wait.trigger == None }}'
sequence:
- service: light.turn_on
data:
brightness_step_pct: "{{ negative_dim_value }}"
entity_id: "{{ light_target_for_left_entity_list }}"
- conditions: '{{ trigger_action == "press_3" and wait.trigger == None }}'
sequence:
- service: light.turn_on
data:
brightness_step_pct: !input 'light_dim_step'
entity_id: "{{ light_target_for_right_entity_list }}"
- conditions: '{{ trigger_action == "press_4" and wait.trigger == None }}'
sequence:
- service: light.turn_on
data:
brightness_step_pct: "{{ negative_dim_value }}"
entity_id: "{{ light_target_for_right_entity_list }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment