Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Light.yaml custom mappings #18

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
188 changes: 170 additions & 18 deletions blueprints/hooks/light/light.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -68,6 +69,13 @@ blueprint:
selector:
entity:
domain: light
cycle_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:
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.
Expand Down Expand Up @@ -195,8 +203,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
Expand Down Expand Up @@ -348,19 +357,120 @@ 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 }}'

# 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) }}
{% 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) }}
{% 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) }}
{% 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) }}
{% 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) }}
{% 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) }}
{% 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) }}
{% 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) }}
{% elif ( custom_controller_mapping[controller_model] | default(None)) is not none %}
{{ custom_controller_mapping[controller_model]["color_down_repeat"] | default(None) }}
{% else %}
{{ none }}
{% endif %}
cycle_scenes_forward: >
{% if is_predefined %}
{{ controller_mapping[controller_model]["cycle_scenes_forward"] | default(None) }}
{% elif ( custom_controller_mapping[controller_model] | default(None)) is not none %}
{{ custom_controller_mapping[controller_model]["cycle_scenes_forward"] | default(None) }}
{% else %}
{{ none }}
{% endif %}
cycle_scenes_backward: >
{% if is_predefined %}
{{ controller_mapping[controller_model]["cycle_scenes_backward"] | default(None) }}
{% elif ( custom_controller_mapping[controller_model] | default(None)) is not none %}
{{ custom_controller_mapping[controller_model]["cycle_scenes_backward"] | default(None) }}
{% else %}
{{ none }}
{% endif %}
toggle: >
{% if is_predefined %}
{{ controller_mapping[controller_model]["toggle"] | default(None) }}
{% 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) }}
{% 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) }}
{% elif ( custom_controller_mapping[controller_model] | default(None)) is not none %}
{{ custom_controller_mapping[controller_model]["turn_off"] | default(None) }}
{% else %}
{{ none }}
{% endif %}

cycle_scene_dropdown: !input cycle_scene_dropdown
light_color_mode: !input light_color_mode
light: !input light
light_transition: !input light_transition
Expand Down Expand Up @@ -397,7 +507,25 @@ trigger:
event_type: ahb_controller_event
event_data:
controller: !input controller_entity
condition: []
condition:
# Fail if the mapping was unsuccessful
- condition: template
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
cycle_scenes_forward is not none or
cycle_scenes_backward 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 }}'
Expand Down Expand Up @@ -436,6 +564,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 }}'
Expand Down Expand Up @@ -679,4 +831,4 @@ action:
transition: 0.25
entity_id: !input light
- delay:
milliseconds: 250
milliseconds: 250
8 changes: 8 additions & 0 deletions website/docs/blueprints/hooks/light.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ selector='entity'
required
/>
<Input
name='(Optional) Scene dropdown'
description='Dropdown selection containing a list of scenes. Only when one of the buttons is configured to cycle scenes.'
selector='select'
/>
<Input
name='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.'
selector='select'
Expand Down Expand Up @@ -186,3 +191,6 @@ If you want to link multiple lights to the same controller you can either use [L
- **2021-12-05**: Added secondary mapping for IKEA E2001/E2002
- **2022-07-22**: Add support for Xiaomi WXKG11LM.
- **2022-07-30**: Add support for SONOFF SNZB-01.

## New Changelog (might be incomplete)
- **2024-09-28**: Add cycling of scenes.