Skip to content

Instantly share code, notes, and snippets.

@napalmz
Last active December 20, 2023 11:00
Show Gist options
  • Save napalmz/69b590d4736a94d34d80e16f81bcf7f4 to your computer and use it in GitHub Desktop.
Save napalmz/69b590d4736a94d34d80e16f81bcf7f4 to your computer and use it in GitHub Desktop.
# Blueprint metadata
blueprint:
name: Controller - IKEA E1744 SYMFONISK Rotary Remote MOD
description: |
# Controller - IKEA E1744 SYMFONISK Rotary Remote
Controller automation for executing any kind of action triggered by the provided IKEA E1744 SYMFONISK Rotary Remote. Allows to optionally loop a custom action during controller rotation.
Supports deCONZ, ZHA, Zigbee2MQTT.
Automations created with this blueprint can be connected with one or more [Hooks](https://epmatt.github.io/awesome-ha-blueprints/docs/blueprints/hooks) supported by this controller.
Hooks allow to easily create controller-based automations for interacting with media players, lights, covers and more.
See the list of [Hooks available for this controller](https://epmatt.github.io/awesome-ha-blueprints/docs/blueprints/controllers/ikea_e1744#available-hooks) for additional details.
📕 Full documentation regarding this blueprint is available [here](https://epmatt.github.io/awesome-ha-blueprints/docs/blueprints/controllers/ikea_e1744).
🚀 This blueprint is part of the **[Awesome HA Blueprints](https://epmatt.github.io/awesome-ha-blueprints) project**.
ℹ️ Version 2022.08.08
source_url: https://github.com/EPMatt/awesome-ha-blueprints/blob/main/blueprints/controllers/ikea_e1744/ikea_e1744.yaml
domain: automation
input:
integration:
name: (Required) Integration
description: Integration used for connecting the remote with Home Assistant. Select one of the available values.
selector:
select:
options:
- deCONZ
- ZHA
- Zigbee2MQTT
controller_device:
name: (deCONZ, ZHA) Controller Device
description: The controller device to use for the automation. Choose a value only if the remote is integrated with deCONZ, ZHA.
default: ''
selector:
device:
controller_entity:
name: (Zigbee2MQTT) Controller Entity
description: The action sensor of the controller to use for the automation. Choose a value only if the remote is integrated with Zigbee2MQTT.
default: ''
selector:
entity:
domain: sensor
helper_last_controller_event:
name: (Required) Helper - Last Controller Event
description: Input Text used to store the last event fired by the controller. You will need to manually create a text input entity for this, please read the blueprint Additional Notes for more info.
default: ''
selector:
entity:
domain: input_text
# inputs for custom actions
action_rotate_left:
name: (Optional) Rotate left
description: Action to run on rotate left.
default: []
selector:
action:
action_rotate_left_stop:
name: (Optional) Rotate left stop
description: Action to run when stopping to rotate left the remote.
default: []
selector:
action:
action_rotate_right:
name: (Optional) Rotate right
description: Action to run on rotate right.
default: []
selector:
action:
action_rotate_right_stop:
name: (Optional) Rotate right stop
description: Action to run when stopping to rotate right the remote.
default: []
selector:
action:
action_click_short:
name: (Optional) Remote short press
description: Action to run on short remote press.
default: []
selector:
action:
action_click_double:
name: (Optional) Remote double press
description: Action to run on double remote press.
default: []
selector:
action:
action_click_triple:
name: (Optional) Remote triple press
description: Action to run on triple remote press.
default: []
selector:
action:
# inputs for looping custom actions on long button press events until the corresponding release event is received
rotate_left_loop:
name: (Optional) Rotate left - loop until stop
description: Loop the rotate left action until the rotation is stopped.
default: false
selector:
boolean:
rotate_left_max_loop_repeats:
name: (Optional) Rotate left - Maximum loop repeats
description: >-
Maximum number of repeats for the custom action, when looping is enabled.
Use it as a safety limit to prevent an endless loop in case the corresponding stop event is not received.
default: 500
selector:
number:
min: 1
max: 5000
mode: slider
step: 1
rotate_right_loop:
name: (Optional) Rotate right - loop until stop
description: Loop the rotate right action until the rotation is stopped.
default: false
selector:
boolean:
rotate_right_max_loop_repeats:
name: (Optional) Rotate right - Maximum loop repeats
description: >-
Maximum number of repeats for the custom action, when looping is enabled.
Use it as a safety limit to prevent an endless loop in case the corresponding stop event is not received.
default: 500
selector:
number:
min: 1
max: 5000
mode: slider
step: 1
# helpers used to properly recognize the remote button events
helper_debounce_delay:
name: (Optional) Helper - Debounce delay
description:
Delay used for debouncing RAW controller events, by default set to 0. A value of 0 disables the debouncing feature. Increase this value if you notice custom actions or linked Hooks running multiple times when interacting with the device. When the controller needs to be debounced,
usually a value of 100 is enough to remove all duplicate events.
default: 0
selector:
number:
min: 0
max: 1000
unit_of_measurement: milliseconds
mode: box
step: 10
# Automation schema
variables:
# convert input tags to variables, to be used in templates
integration: !input integration
rotate_left_loop: !input rotate_left_loop
rotate_left_max_loop_repeats: !input rotate_left_max_loop_repeats
rotate_right_loop: !input rotate_right_loop
rotate_right_max_loop_repeats: !input rotate_right_max_loop_repeats
helper_last_controller_event: !input helper_last_controller_event
helper_debounce_delay: !input helper_debounce_delay
# integration id used to select items in the action mapping
integration_id: '{{ integration | lower }}'
# mapping between actions and integrations
actions_mapping:
deconz:
rotate_left: ['3001']
rotate_stop: ['3003', '2003']
rotate_right: ['2001']
click_short: ['1002']
click_double: ['1004']
click_triple: ['1005']
zha:
rotate_left: [move_MoveMode.Down_195_0_0]
rotate_stop: [stop_0_0]
rotate_right: [move_MoveMode.Up_195_0_0]
click_short: [toggle]
click_double: [step_StepMode.Up_1_0_0_0]
click_triple: [step_StepMode.Down_1_0_0_0]
zigbee2mqtt:
rotate_left: [brightness_move_down]
rotate_stop: [brightness_stop]
rotate_right: [brightness_move_up]
click_short: [toggle]
click_double: [brightness_step_up]
click_triple: [brightness_step_down]
# pre-choose actions for buttons based on configured integration
# no need to perform this task at automation runtime
rotate_left: '{{ actions_mapping[integration_id]["rotate_left"] }}'
rotate_stop: '{{ actions_mapping[integration_id]["rotate_stop"] }}'
rotate_right: '{{ actions_mapping[integration_id]["rotate_right"] }}'
click_short: '{{ actions_mapping[integration_id]["click_short"] }}'
click_double: '{{ actions_mapping[integration_id]["click_double"] }}'
click_triple: '{{ actions_mapping[integration_id]["click_triple"] }}'
# build data to send within a controller event
controller_entity: !input controller_entity
controller_device: !input controller_device
controller_id: '{% if integration_id=="zigbee2mqtt" %}{{controller_entity}}{% else %}{{controller_device}}{% endif %}'
mode: restart
max_exceeded: silent
trigger:
# trigger for zigbee2mqtt
- platform: event
event_type: state_changed
event_data:
entity_id: !input controller_entity
# trigger for other integrations
- platform: event
event_type:
- deconz_event
- zha_event
event_data:
device_id: !input controller_device
condition:
- condition: and
conditions:
# check that the button event is not empty
- >-
{%- set trigger_action -%}
{%- if integration_id == "zigbee2mqtt" -%}
{{ trigger.event.data.new_state.state }}
{%- elif integration_id == "deconz" -%}
{{ trigger.event.data.event }}
{%- elif integration_id == "zha" -%}
{{ trigger.event.data.command }}{{"_" if trigger.event.data.args|length > 0}}{{ trigger.event.data.args|join("_") }}
{%- endif -%}
{%- endset -%}
{{ trigger_action not in ["","None"] }}
# only for zigbee2mqtt, check if the event is relative to a real state change, and not only some minor changes in the sensor attributes
# this is required since multiple state_changed events are fired for a single button press, with the result of the automation being triggered multiple times
- '{{ integration_id != "zigbee2mqtt" or trigger.event.data.new_state.state != trigger.event.data.old_state.state }}'
action:
# debouncing - when automation is triggered multiple times, the last automation run is the one which completes execution, due to mode restart
# therefore previous runs must wait for the debounce delay before executing any other action
# if the delay expires and the automation is still running it means it's the last run and execution can continue
- delay:
milliseconds: !input helper_debounce_delay
# extract button event from the trigger
# provide a single string value to check against
- variables:
trigger_action: >-
{%- if integration_id == "zigbee2mqtt" -%}
{{ trigger.event.data.new_state.state }}
{%- elif integration_id == "deconz" -%}
{{ trigger.event.data.event }}
{%- elif integration_id == "zha" -%}
{{ trigger.event.data.command }}{{"_" if trigger.event.data.args|length > 0}}{{ trigger.event.data.args|join("_") }}
{%- endif -%}
trigger_delta: '{{ (as_timestamp(now()) - ((states(helper_last_controller_event) | from_json).t if helper_last_controller_event is not none and (states(helper_last_controller_event) | regex_match("^\{((\"a\": \".*\"|\"t\": \d+\.\d+)(, )?){2}\}$")) else as_timestamp("1970-01-01 00:00:00"))) * 1000 }}'
last_controller_event: '{{ (states(helper_last_controller_event) | from_json).a if helper_last_controller_event is not none and (states(helper_last_controller_event) | regex_match("^\{((\"a\": \".*\"|\"t\": \d+\.\d+)(, )?){2}\}$")) else "" }}'
# update helper
- service: input_text.set_value
data:
entity_id: !input helper_last_controller_event
value: '{{ {"a":trigger_action,"t":as_timestamp(now())} | to_json }}'
# choose the sequence to run based on the received button event
- choose:
- conditions: '{{ trigger_action | string in rotate_left }}'
sequence:
# fire the event only once before looping the action
- event: ahb_controller_event
event_data:
controller: '{{ controller_id }}'
action: rotate_left
- choose:
# if looping is enabled, loop the action for a finite number of iterations
- conditions: '{{ rotate_left_loop }}'
sequence:
- repeat:
while: '{{ repeat.index < rotate_left_max_loop_repeats | int }}'
sequence: !input action_rotate_left
# if looping is not enabled run the custom action only once
default: !input action_rotate_left
- conditions:
- '{{ trigger_action | string in rotate_stop }}'
# check the previous event to determine the event which the received stop action is relative to
- '{{ last_controller_event | string in rotate_left }}'
sequence:
# fire the event
- event: ahb_controller_event
event_data:
controller: '{{ controller_id }}'
action: rotate_left_stop
# run the custom action
- choose:
- conditions: []
sequence: !input action_rotate_left_stop
- conditions: '{{ trigger_action | string in rotate_right }}'
sequence:
# fire the event only once before looping the action
- event: ahb_controller_event
event_data:
controller: '{{ controller_id }}'
action: rotate_right
- choose:
# if looping is enabled, loop the action for a finite number of iterations
- conditions: '{{ rotate_right_loop }}'
sequence:
- repeat:
while: '{{ repeat.index < rotate_right_max_loop_repeats | int }}'
sequence: !input action_rotate_right
# if looping is not enabled run the custom action only once
default: !input action_rotate_right
- conditions:
- '{{ trigger_action | string in rotate_stop }}'
# check the previous event to determine the event which the received stop action is relative to
- '{{ last_controller_event | string in rotate_right }}'
sequence:
# fire the event
- event: ahb_controller_event
event_data:
controller: '{{ controller_id }}'
action: rotate_right_stop
# run the custom action
- choose:
- conditions: []
sequence: !input action_rotate_right_stop
- conditions: '{{ trigger_action | string in click_short }}'
sequence:
# fire the event
- event: ahb_controller_event
event_data:
controller: '{{ controller_id }}'
action: click_short
# run the custom action
- choose:
- conditions: []
sequence: !input action_click_short
- conditions: '{{ trigger_action | string in click_double }}'
sequence:
# fire the event
- event: ahb_controller_event
event_data:
controller: '{{ controller_id }}'
action: click_double
# run the custom action
- choose:
- conditions: []
sequence: !input action_click_double
- conditions: '{{ trigger_action | string in click_triple }}'
sequence:
# fire the event
- event: ahb_controller_event
event_data:
controller: '{{ controller_id }}'
action: click_triple
# run the custom action
- choose:
- conditions: []
sequence: !input action_click_triple
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment