From e81c08505de2db098c0f364c5454c7cd7d7e9cb5 Mon Sep 17 00:00:00 2001 From: botastic Date: Tue, 16 Jul 2024 22:54:50 +0200 Subject: [PATCH 1/5] added custom mappings --- blueprints/hooks/light/light.yaml | 117 +++++++++++++++++++++++++----- 1 file changed, 100 insertions(+), 17 deletions(-) diff --git a/blueprints/hooks/light/light.yaml b/blueprints/hooks/light/light.yaml index 6af6907b..2ff61c97 100644 --- a/blueprints/hooks/light/light.yaml +++ b/blueprints/hooks/light/light.yaml @@ -38,7 +38,8 @@ blueprint: description: The model for the controller used in this automation. Choose a value from the list of supported controllers. selector: select: - options: + custom_value: true + options: - IKEA E1524/E1810 TRÅDFRI Wireless 5-Button Remote - IKEA E1743 TRÅDFRI On/Off Switch & Dimmer - IKEA E1743 TRÅDFRI On/Off Switch & Dimmer (#2) @@ -195,8 +196,9 @@ blueprint: variables: # convert blueprint inputs into variables to be used in templates controller_model: !input controller_model - # supported controllers and mappings - controller_mapping: + + # predefined controllers and mappings + controller_mapping: IKEA E1524/E1810 TRÅDFRI Wireless 5-Button Remote: brightness_up: button_up_short brightness_up_repeat: button_up_long @@ -348,19 +350,97 @@ variables: Xiaomi WXKG11LM Aqara Wireless Switch Mini: toggle: button_short color_up: button_double - # pre-choose actions for buttons based on configured controller - # no need to perform this task at automation runtime - brightness_up: '{{ controller_mapping[controller_model]["brightness_up"] | default(None) }}' - brightness_up_repeat: '{{ controller_mapping[controller_model]["brightness_up_repeat"] | default(None) }}' - brightness_down: '{{ controller_mapping[controller_model]["brightness_down"] | default(None) }}' - brightness_down_repeat: '{{ controller_mapping[controller_model]["brightness_down_repeat"] | default(None) }}' - color_up: '{{ controller_mapping[controller_model]["color_up"] | default(None) }}' - color_up_repeat: '{{ controller_mapping[controller_model]["color_up_repeat"] | default(None) }}' - color_down: '{{ controller_mapping[controller_model]["color_down"] | default(None) }}' - color_down_repeat: '{{ controller_mapping[controller_model]["color_down_repeat"] | default(None) }}' - toggle: '{{ controller_mapping[controller_model]["toggle"] | default(None) }}' - turn_on: '{{ controller_mapping[controller_model]["turn_on"] | default(None) }}' - turn_off: '{{ controller_mapping[controller_model]["turn_off"] | default(None) }}' + + # Check if the selected controller model is predefined + is_predefined: '{{ controller_model in controller_mapping }}' + + # TODO: unfortunately, there is no feedback other than the logs if the file does not exist - maybe there is a better way + # Load custom controller model mappings + custom_controller_mapping: !include_dir_named ahb_custom_mappings + + # Pre-choose actions for buttons based on configured controller if predefined + brightness_up: > + {% if is_predefined %} + {{ controller_mapping[controller_model]["brightness_up"] | default(None) }} + {% else %} + {{ custom_controller_mapping[controller_model]["brightness_up"] | default(None) }} + {% endif %} + brightness_up_repeat: > + {% if is_predefined %} + {{ controller_mapping[controller_model]["brightness_up_repeat"] | default(None) }} + {% else %} + {{ custom_controller_mapping[controller_model]["brightness_up_repeat"] | default(None) }} + {% endif %} + brightness_down: > + {% if is_predefined %} + {{ controller_mapping[controller_model]["brightness_down"] | default(None) }} + {% else %} + {{ custom_controller_mapping[controller_model]["brightness_down"] | default(None) }} + {% endif %} + brightness_down_repeat: > + {% if is_predefined %} + {{ controller_mapping[controller_model]["brightness_down_repeat"] | default(None) }} + {% else %} + {{ custom_controller_mapping[controller_model]["brightness_down_repeat"] | default(None) }} + {% endif %} + color_up: > + {% if is_predefined %} + {{ controller_mapping[controller_model]["color_up"] | default(None) }} + {% else %} + {{ custom_controller_mapping[controller_model]["color_up"] | default(None) }} + {% endif %} + color_up_repeat: > + {% if is_predefined %} + {{ controller_mapping[controller_model]["color_up_repeat"] | default(None) }} + {% else %} + {{ custom_controller_mapping[controller_model]["color_up_repeat"] | default(None) }} + {% endif %} + color_down: > + {% if is_predefined %} + {{ controller_mapping[controller_model]["color_down"] | default(None) }} + {% else %} + {{ custom_controller_mapping[controller_model]["color_down"] | default(None) }} + {% endif %} + color_down_repeat: > + {% if is_predefined %} + {{ controller_mapping[controller_model]["color_down_repeat"] | default(None) }} + {% else %} + {{ custom_controller_mapping[controller_model]["color_down_repeat"] | default(None) }} + {% endif %} + toggle: > + {% if is_predefined %} + {{ controller_mapping[controller_model]["toggle"] | default(None) }} + {% else %} + {{ custom_controller_mapping[controller_model]["toggle"] | default(None) }} + {% endif %} + turn_on: > + {% if is_predefined %} + {{ controller_mapping[controller_model]["turn_on"] | default(None) }} + {% else %} + {{ custom_controller_mapping[controller_model]["turn_on"] | default(None) }} + {% endif %} + turn_off: > + {% if is_predefined %} + {{ controller_mapping[controller_model]["turn_off"] | default(None) }} + {% else %} + {{ custom_controller_mapping[controller_model]["turn_off"] | default(None) }} + {% endif %} + + mapping_exists: > + {{ + brightness_up is not none or + brightness_up_repeat is not none or + brightness_down is not none or + brightness_down_repeat is not none or + color_up is not none or + color_up_repeat is not none or + color_down is not none or + color_down_repeat is not none or + toggle is not none or + turn_on is not none or + turn_off is not none + }} + light_color_mode: !input light_color_mode light: !input light light_transition: !input light_transition @@ -397,7 +477,10 @@ trigger: event_type: ahb_controller_event event_data: controller: !input controller_entity -condition: [] +condition: + # Fail if the mapping was unsuccessful + - condition: template + value_template: '{{ mapping_exists }}' action: - variables: action: '{{ trigger.event.data.action }}' From bb683615a4f17f6ba975f80a98423b24253bda04 Mon Sep 17 00:00:00 2001 From: botastic Date: Tue, 16 Jul 2024 23:40:16 +0200 Subject: [PATCH 2/5] improved missing file feedback --- blueprints/hooks/light/light.yaml | 75 +++++++++++++++++++------------ 1 file changed, 47 insertions(+), 28 deletions(-) diff --git a/blueprints/hooks/light/light.yaml b/blueprints/hooks/light/light.yaml index 2ff61c97..a18a32d0 100644 --- a/blueprints/hooks/light/light.yaml +++ b/blueprints/hooks/light/light.yaml @@ -354,7 +354,6 @@ variables: # Check if the selected controller model is predefined is_predefined: '{{ controller_model in controller_mapping }}' - # TODO: unfortunately, there is no feedback other than the logs if the file does not exist - maybe there is a better way # Load custom controller model mappings custom_controller_mapping: !include_dir_named ahb_custom_mappings @@ -362,85 +361,92 @@ variables: brightness_up: > {% if is_predefined %} {{ controller_mapping[controller_model]["brightness_up"] | default(None) }} - {% else %} + {% elif ( custom_controller_mapping[controller_model] | default(None)) is not none %} {{ custom_controller_mapping[controller_model]["brightness_up"] | default(None) }} + {% else %} + {{ none }} {% endif %} brightness_up_repeat: > {% if is_predefined %} {{ controller_mapping[controller_model]["brightness_up_repeat"] | default(None) }} - {% else %} + {% elif ( custom_controller_mapping[controller_model] | default(None)) is not none %} {{ custom_controller_mapping[controller_model]["brightness_up_repeat"] | default(None) }} + {% else %} + {{ none }} {% endif %} brightness_down: > {% if is_predefined %} {{ controller_mapping[controller_model]["brightness_down"] | default(None) }} - {% else %} + {% elif ( custom_controller_mapping[controller_model] | default(None)) is not none %} {{ custom_controller_mapping[controller_model]["brightness_down"] | default(None) }} + {% else %} + {{ none }} {% endif %} brightness_down_repeat: > {% if is_predefined %} {{ controller_mapping[controller_model]["brightness_down_repeat"] | default(None) }} - {% else %} + {% elif ( custom_controller_mapping[controller_model] | default(None)) is not none %} {{ custom_controller_mapping[controller_model]["brightness_down_repeat"] | default(None) }} + {% else %} + {{ none }} {% endif %} color_up: > {% if is_predefined %} {{ controller_mapping[controller_model]["color_up"] | default(None) }} - {% else %} + {% elif ( custom_controller_mapping[controller_model] | default(None)) is not none %} {{ custom_controller_mapping[controller_model]["color_up"] | default(None) }} + {% else %} + {{ none }} {% endif %} color_up_repeat: > {% if is_predefined %} {{ controller_mapping[controller_model]["color_up_repeat"] | default(None) }} - {% else %} + {% elif ( custom_controller_mapping[controller_model] | default(None)) is not none %} {{ custom_controller_mapping[controller_model]["color_up_repeat"] | default(None) }} + {% else %} + {{ none }} {% endif %} color_down: > {% if is_predefined %} {{ controller_mapping[controller_model]["color_down"] | default(None) }} - {% else %} + {% elif ( custom_controller_mapping[controller_model] | default(None)) is not none %} {{ custom_controller_mapping[controller_model]["color_down"] | default(None) }} + {% else %} + {{ none }} {% endif %} color_down_repeat: > {% if is_predefined %} {{ controller_mapping[controller_model]["color_down_repeat"] | default(None) }} - {% else %} + {% elif ( custom_controller_mapping[controller_model] | default(None)) is not none %} {{ custom_controller_mapping[controller_model]["color_down_repeat"] | default(None) }} + {% else %} + {{ none }} {% endif %} toggle: > {% if is_predefined %} {{ controller_mapping[controller_model]["toggle"] | default(None) }} - {% else %} + {% elif ( custom_controller_mapping[controller_model] | default(None)) is not none %} {{ custom_controller_mapping[controller_model]["toggle"] | default(None) }} + {% else %} + {{ none }} {% endif %} turn_on: > {% if is_predefined %} {{ controller_mapping[controller_model]["turn_on"] | default(None) }} - {% else %} + {% elif ( custom_controller_mapping[controller_model] | default(None)) is not none %} {{ custom_controller_mapping[controller_model]["turn_on"] | default(None) }} + {% else %} + {{ none }} {% endif %} turn_off: > {% if is_predefined %} {{ controller_mapping[controller_model]["turn_off"] | default(None) }} - {% else %} + {% elif ( custom_controller_mapping[controller_model] | default(None)) is not none %} {{ custom_controller_mapping[controller_model]["turn_off"] | default(None) }} + {% else %} + {{ none }} {% endif %} - mapping_exists: > - {{ - brightness_up is not none or - brightness_up_repeat is not none or - brightness_down is not none or - brightness_down_repeat is not none or - color_up is not none or - color_up_repeat is not none or - color_down is not none or - color_down_repeat is not none or - toggle is not none or - turn_on is not none or - turn_off is not none - }} - light_color_mode: !input light_color_mode light: !input light light_transition: !input light_transition @@ -480,7 +486,20 @@ trigger: condition: # Fail if the mapping was unsuccessful - condition: template - value_template: '{{ mapping_exists }}' + value_template: > + {{ + brightness_up is not none or + brightness_up_repeat is not none or + brightness_down is not none or + brightness_down_repeat is not none or + color_up is not none or + color_up_repeat is not none or + color_down is not none or + color_down_repeat is not none or + toggle is not none or + turn_on is not none or + turn_off is not none + }} action: - variables: action: '{{ trigger.event.data.action }}' From a5e5316df6564ebf54a6a83bfb76fd053fc4a3e1 Mon Sep 17 00:00:00 2001 From: botastic Date: Wed, 17 Jul 2024 01:00:56 +0200 Subject: [PATCH 3/5] added cycle scenes action --- blueprints/hooks/light/light.yaml | 39 +++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/blueprints/hooks/light/light.yaml b/blueprints/hooks/light/light.yaml index 6af6907b..1121902f 100644 --- a/blueprints/hooks/light/light.yaml +++ b/blueprints/hooks/light/light.yaml @@ -68,6 +68,13 @@ blueprint: selector: entity: domain: light + cycle_scene_dropdown: + name: (Optional) Helper - Scene Dropdown + description: Dropdown selection containing a list of scenes. Needed when one of the buttons is configured to cycle scenes. + default: '' + selector: + entity: + domain: input_select light_color_mode: name: (Optional) Light color mode description: Specify how the controller will set the light color. Choose "Color Temperature" and "Hue - Saturation" depending on the features supported by your light. If you are not sure you can select "Auto". "None" will disable color control features. @@ -206,7 +213,8 @@ variables: color_down_repeat: button_left_long color_up: button_right_short color_up_repeat: button_right_long - toggle: button_center_short + #toggle: button_center_short + cycle_scenes_forward: button_center_short IKEA E1743 TRÅDFRI On/Off Switch & Dimmer: turn_on: button_up_short brightness_up_repeat: button_up_long @@ -358,9 +366,12 @@ variables: color_up_repeat: '{{ controller_mapping[controller_model]["color_up_repeat"] | default(None) }}' color_down: '{{ controller_mapping[controller_model]["color_down"] | default(None) }}' color_down_repeat: '{{ controller_mapping[controller_model]["color_down_repeat"] | default(None) }}' + cycle_scenes_forward: '{{ controller_mapping[controller_model]["cycle_scenes_forward"] | default(None) }}' + cycle_scenes_backward: '{{ controller_mapping[controller_model]["cycle_scenes_backward"] | default(None) }}' toggle: '{{ controller_mapping[controller_model]["toggle"] | default(None) }}' turn_on: '{{ controller_mapping[controller_model]["turn_on"] | default(None) }}' turn_off: '{{ controller_mapping[controller_model]["turn_off"] | default(None) }}' + cycle_scene_dropdown: !input cycle_scene_dropdown light_color_mode: !input light_color_mode light: !input light light_transition: !input light_transition @@ -436,6 +447,30 @@ action: sequence: - service: light.turn_off entity_id: !input light + data: + transition: '{{ light_transition / 1000 }}' + - conditions: '{{ action == cycle_scenes_forward }}' + sequence: + - service: input_select.select_next + data: + cycle: true + target: + entity_id: '{{ cycle_scene_dropdown }}' + - service: scene.turn_on + target: + entity_id: "{{ states(cycle_scene_dropdown) }}" + data: + transition: '{{ light_transition / 1000 }}' + - conditions: '{{ action == cycle_scenes_backward }}' + sequence: + - service: input_select.select_previous + data: + cycle: true + target: + entity_id: '{{ cycle_scene_dropdown }}' + - service: scene.turn_on + target: + entity_id: "{{ states(cycle_scene_dropdown) }}" data: transition: '{{ light_transition / 1000 }}' - conditions: '{{ action == brightness_up }}' @@ -679,4 +714,4 @@ action: transition: 0.25 entity_id: !input light - delay: - milliseconds: 250 + milliseconds: 250 \ No newline at end of file From 97b764d17c4edd88af066a12b74a4bbc47489dd8 Mon Sep 17 00:00:00 2001 From: botastic Date: Wed, 17 Jul 2024 01:03:26 +0200 Subject: [PATCH 4/5] removed test mapping --- blueprints/hooks/light/light.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/blueprints/hooks/light/light.yaml b/blueprints/hooks/light/light.yaml index 1121902f..0ed4bba1 100644 --- a/blueprints/hooks/light/light.yaml +++ b/blueprints/hooks/light/light.yaml @@ -213,8 +213,7 @@ variables: color_down_repeat: button_left_long color_up: button_right_short color_up_repeat: button_right_long - #toggle: button_center_short - cycle_scenes_forward: button_center_short + toggle: button_center_short IKEA E1743 TRÅDFRI On/Off Switch & Dimmer: turn_on: button_up_short brightness_up_repeat: button_up_long From b901a2836c5612c408ad79a66ce8400be656228f Mon Sep 17 00:00:00 2001 From: botastic Date: Sat, 28 Sep 2024 10:34:48 +0200 Subject: [PATCH 5/5] "added minimal documentation" --- blueprints/hooks/light/light.yaml | 2 +- website/docs/blueprints/hooks/light.mdx | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/blueprints/hooks/light/light.yaml b/blueprints/hooks/light/light.yaml index 0ed4bba1..fd457cf7 100644 --- a/blueprints/hooks/light/light.yaml +++ b/blueprints/hooks/light/light.yaml @@ -69,7 +69,7 @@ blueprint: entity: domain: light cycle_scene_dropdown: - name: (Optional) Helper - Scene Dropdown + name: (Optional) Scene dropdown description: Dropdown selection containing a list of scenes. Needed when one of the buttons is configured to cycle scenes. default: '' selector: diff --git a/website/docs/blueprints/hooks/light.mdx b/website/docs/blueprints/hooks/light.mdx index 9c0f2591..a5834553 100644 --- a/website/docs/blueprints/hooks/light.mdx +++ b/website/docs/blueprints/hooks/light.mdx @@ -60,6 +60,11 @@ selector='entity' required /> +