Skip to content

Instantly share code, notes, and snippets.

@Hjord
Last active December 18, 2024 18:59
Show Gist options
  • Save Hjord/0b1e201f897f542dd253d28557f97717 to your computer and use it in GitHub Desktop.
Save Hjord/0b1e201f897f542dd253d28557f97717 to your computer and use it in GitHub Desktop.
blueprint:
domain: "automation"
name: "EnOcean Dimmer Switch"
input:
light_target_left:
name: Left light control
selector:
entity:
domain: light
light_target_right:
name: Right light control
selector:
entity:
domain: light
switch_entity_action:
name: Switch
description: This entity must end with _action
selector:
entity:
domain: sensor
input_boolean_longpress:
name: LongpressToggle
description: You need to create this helper toggle and select it here
selector:
entity:
domain: input_boolean
longpress_duration:
name: Long press duration (ms)
description: The amount of time to hold the button before long press is detected
default: 250
selector:
number:
min: 0
max: 1000
unit_of_measurement: "ms"
dimming_step_delay:
name: Dimming step delay (ms)
description: Delay between each dimming step
default: 250
selector:
number:
min: 0
max: 1000
unit_of_measurement: "ms"
dimming_step_size_pct:
name: The dimming step size in percent
default: 5
selector:
number:
min: 1
max: 100
unit_of_measurement: "%"
variables:
var_dimming_step_size_pct: !input dimming_step_size_pct
neg_dimming_step_size_pct: "{{ (var_dimming_step_size_pct | int) * -1 }}"
mode: restart
trigger:
- platform: state
entity_id: !input switch_entity_action
condition:
- condition: template
value_template: >-
{{ trigger.to_state.state.startswith('press_') or
trigger.to_state.state.startswith('release_') }}
action:
- variables:
command: "{{ trigger.to_state.state }}"
- choose:
- conditions:
- condition: template
value_template: "{{ command == 'release_1' or command == 'release_2' }}"
- condition: state
entity_id: !input input_boolean_longpress
state: "off"
sequence:
- service: light.toggle
data: {}
target:
entity_id: !input light_target_left
- conditions:
- condition: template
value_template: "{{ command == 'release_3' or command == 'release_4' }}"
- condition: state
entity_id: !input input_boolean_longpress
state: "off"
sequence:
- service: light.toggle
data: {}
target:
entity_id: !input light_target_right
- conditions:
- condition: template
value_template: >-
{{ command == 'press_1' }}
sequence:
- service: input_boolean.turn_off
data: {}
target:
entity_id: !input input_boolean_longpress
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: !input longpress_duration
- service: input_boolean.turn_on
data: {}
target:
entity_id: !input input_boolean_longpress
- repeat:
count: 6
sequence:
- service: light.turn_on
data:
brightness_step_pct: !input dimming_step_size_pct
transition: 0.25
entity_id: !input light_target_left
- delay:
milliseconds: !input dimming_step_delay
- conditions:
- condition: template
value_template: >-
{{ command == 'press_3' }}
sequence:
- service: input_boolean.turn_off
data: {}
target:
entity_id: !input input_boolean_longpress
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: !input longpress_duration
- service: input_boolean.turn_on
data: {}
target:
entity_id: !input input_boolean_longpress
- repeat:
count: 6
sequence:
- service: light.turn_on
data:
brightness_step_pct: !input dimming_step_size_pct
transition: 0.25
entity_id: !input light_target_right
- delay:
milliseconds: !input dimming_step_delay
- conditions:
- condition: template
value_template: >-
{{ command == 'press_2' }}
sequence:
- service: input_boolean.turn_off
data: {}
target:
entity_id: !input input_boolean_longpress
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: !input longpress_duration
- service: input_boolean.turn_on
data: {}
target:
entity_id: !input input_boolean_longpress
- repeat:
count: 6
sequence:
- service: light.turn_on
data:
brightness_step_pct: "{{ neg_dimming_step_size_pct }}"
transition: 0.25
entity_id: !input light_target_left
- delay:
milliseconds: !input dimming_step_delay
- conditions:
- condition: template
value_template: >-
{{ command == 'press_4' }}
sequence:
- service: input_boolean.turn_off
data: {}
target:
entity_id: !input input_boolean_longpress
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: !input longpress_duration
- service: input_boolean.turn_on
data: {}
target:
entity_id: !input input_boolean_longpress
- repeat:
while: "{{ true }}"
sequence:
- service: light.turn_on
data:
brightness_step_pct: "{{ neg_dimming_step_size_pct }}"
transition: 0.25
entity_id: !input light_target_right
- delay:
milliseconds: !input dimming_step_delay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment