feat: smoothen transition when dimming light (#9)

* feat: add transition when dimming light

* chore: add sections to simplify the blueprint

* chore: hardcode source_url

* feat: rework dimming down mechanism

* chore: add CODEOWNERS
This commit is contained in:
Damien
2024-12-20 14:34:04 +01:00
committed by GitHub
parent d7f693d393
commit f5c2b9d6e1
3 changed files with 113 additions and 91 deletions

1
.github/CODEOWNERS vendored Normal file
View File

@@ -0,0 +1 @@
@damru

View File

@@ -20,7 +20,8 @@ blueprint:
- Double press **on/off** (Rodret, _Optional_) **1 dot/2 dots** (Somrig) - Double press **on/off** (Rodret, _Optional_) **1 dot/2 dots** (Somrig)
- Hold **on/off** (Rodret) **1 dot/2 dots** (Somrig). - Hold **on/off** (Rodret) **1 dot/2 dots** (Somrig).
Actions will be executed every **Helper - Hold delay**, but maximum **Helper - Max number of loops** times. Actions will be executed every **Hold delay**, but maximum **Max number of loops** times.
source_url: https://github.com/damru/ha-blueprints/blob/main/ikea_E2201-E2213_ZHA-Z2M_control-anything.yaml
input: input:
remote_device: remote_device:
name: Remote name: Remote
@@ -44,47 +45,54 @@ blueprint:
model: SOMRIG shortcut button (E2213) model: SOMRIG shortcut button (E2213)
multiple: false multiple: false
on_press_action: on_press_action:
name: Single press action (on / 1 dot) name: Press "on / 1 dot" action
description: Choose action(s) to run when **on** (Rodret) or **1 dot** (Somrig) button is **pressed**. description: Choose action(s) to run when **on** (Rodret) or **1 dot** (Somrig) button is **pressed**.
default: [] default: []
selector: selector:
action: {} action: {}
off_press_action: off_press_action:
name: Single press action (off / 2 dots) name: Press "off / 2 dots" action
description: Choose action(s) to run when **off** (Rodret) or **2 dots** (Somrig) button is **pressed**. description: Choose action(s) to run when **off** (Rodret) or **2 dots** (Somrig) button is **pressed**.
default: [] default: []
selector: selector:
action: {} action: {}
on_hold_action: on_hold_action:
name: Hold action (on / 1 dot) name: Hold "on / 1 dot" action
description: Choose action(s) to run when **on** (Rodret) or **1 dot** (Somrig) button is **held**. description: Choose action(s) to run when **on** (Rodret) or **1 dot** (Somrig) button is **held**.
default: [] default: []
selector: selector:
action: {} action: {}
off_hold_action: off_hold_action:
name: Hold action (off / 2 dots) name: Hold "off / 2 dots" action
description: Choose action(s) to run when **off** (Rodret) or **2 dots** (Somrig) button is **held**. description: Choose action(s) to run when **off** (Rodret) or **2 dots** (Somrig) button is **held**.
default: [] default: []
selector: selector:
action: {} action: {}
on_double_press_action: on_double_press_action:
name: Double press action (on / 1 dot) name: Double press "on / 1 dot" action
description: > description: >
Choose action(s) to run when the **on** (Rodret) or **1 dot** (Somrig) button is **pressed twice**. Choose action(s) to run when the **on** (Rodret) or **1 dot** (Somrig) button is **pressed twice**.
(**_NB for Rodret only_**: **Double press event (on)** must be exposed and **Helper - Double press delay** interval is used as a timeout.)
**_NB for Rodret only_**: **Double press event (on)** must be exposed and **Double press delay** interval is used as a timeout.
default: [] default: []
selector: selector:
action: {} action: {}
off_double_press_action: off_double_press_action:
name: Double press action (off / 2 dots) name: Double press "off / 2 dots" action
description: > description: >
Choose action(s) to run when the **off** (Rodret) or **2 dots** (Rodret) button is **pressed twice**. Choose action(s) to run when the **off** (Rodret) or **2 dots** (Rodret) button is **pressed twice**.
(**_NB for Rodret only_**: **Double press event (off)** must be exposed and **Helper - Double press delay** interval is used as a timeout.)
**_NB for Rodret only_**: **Double press event (off)** must be exposed and **Double press delay** interval is used as a timeout.
default: [] default: []
selector: selector:
action: {} action: {}
helper_section :
name: Helpers
icon: mdi:cog-outline
collapsed: true
input:
helper_hold_delay: helper_hold_delay:
name: Helper - Hold delay name: Hold delay
description: Delay between the execution of the **Hold** action(s). description: Delay between the execution of the **Hold** action(s).
default: 250 default: 250
selector: selector:
@@ -95,7 +103,7 @@ blueprint:
step: 10.0 step: 10.0
mode: slider mode: slider
helper_max_loops: helper_max_loops:
name: Helper - Max number of loops name: Max number of loops
description: Maximum number of loops when holding down a button. description: Maximum number of loops when holding down a button.
default: 20 default: 20
selector: selector:
@@ -104,26 +112,31 @@ blueprint:
max: 1000.0 max: 1000.0
step: 1.0 step: 1.0
mode: slider mode: slider
rodret_options_section:
name: Rodret options
icon: mdi:remote
collapsed: true
input:
on_double_press_exposed: on_double_press_exposed:
name: (Rodret only) Double press event (on) name: Expose virtual double press "on" event
description: > description: >
**_(Rodret only)_** Choose whether or not to expose the virtual **double press** event for the **on** button. Choose whether or not to expose the virtual **double press** event for the **on** button.
Turn this on if you are providing action(s) for the **Double press action (on / 1 dot)**. Turn this on if you are providing action(s) for the **Double press action (on / 1 dot)**.
default: false default: false
selector: selector:
boolean: {} boolean: {}
off_double_press_exposed: off_double_press_exposed:
name: (Rodret only) Double press event (off) name: Expose virtual double press "off" event
description: > description: >
**_(Rodret only)_** Choose whether or not to expose the virtual **double press** event for the **off** button. Choose whether or not to expose the virtual **double press** event for the **off** button.
Turn this on if you are providing an action for the **Double press action (off / 2 dots)**. Turn this on if you are providing an action for the **Double press action (off / 2 dots)**.
default: false default: false
selector: selector:
boolean: {} boolean: {}
helper_double_press_delay: helper_double_press_delay:
name: (Rodret only) Helper - Double press delay name: Double press delay
description: > description: >
**(Rodret only)** Max delay between the first and the second button press for the Max delay between the first and the second button press for the
**Double press events**. Provide a value only if you are using a double press action. **Double press events**. Provide a value only if you are using a double press action.
Increase this value if you notice that the double press action is not triggered Increase this value if you notice that the double press action is not triggered
properly. properly.

View File

@@ -16,13 +16,14 @@ blueprint:
Available controls: Available controls:
- Press **on** (Rodret) or **1 dot** (Somrig) to turn on the light - Press **on** (Rodret) or **1 dot** (Somrig) to turn on the light
(Optional: set the target brightness by enabling **Helper - Force Brightness** and setting a **Helper - Brightness** value) (Optional: set the target brightness by enabling **Force Brightness** and setting a **Brightness** value)
- Press **off** (Rodret) or **2 dots** (Somrig) to turn off the light - Press **off** (Rodret) or **2 dots** (Somrig) to turn off the light
- Hold **on** (Rodret) or **1 dot** button to increase the brightness - Hold **on** (Rodret) or **1 dot** button to increase the brightness
- Hold **off** (Rodret) or **2 dots** button to decrease the brightness down to 1% - Hold **off** (Rodret) or **2 dots** button to decrease the brightness down to 1%
source_url: https://github.com/damru/ha-blueprints/blob/main/ikea_E2201-E2213_ZHA-Z2M_control-light.yaml
input: input:
remote_device: remote_device:
name: Remote name: Remote
@@ -53,16 +54,21 @@ blueprint:
filter: filter:
domain: light domain: light
multiple: false multiple: false
brightness_section:
name: Brightness
icon: mdi:lightbulb-on-50
collapsed: true
input:
helper_force_brightness: helper_force_brightness:
name: Helper - Force brightness name: Force brightness
description: Force the brightness to **Helper - Brightness** value when light turns on. description: Force the brightness to **Brightness** value when light turns on.
default: false default: false
selector: selector:
boolean: {} boolean: {}
helper_brightness: helper_brightness:
name: Helper - Brightness name: Brightness
description: description:
Target light brightness when turning on. Requires **Helper - Force brightness** Target light brightness when turning on. Requires **Force brightness**
to be enabled. to be enabled.
default: 50 default: 50
selector: selector:
@@ -258,7 +264,7 @@ actions:
- variables: - variables:
helper_force_brightness: !input helper_force_brightness helper_force_brightness: !input helper_force_brightness
helper_hold_delay: 0.1 helper_hold_delay: 0.1
helper_hold_dim_step: 5 helper_hold_dim_step: 4
light: !input light light: !input light
- choose: - choose:
- conditions: - conditions:
@@ -317,6 +323,7 @@ actions:
entity_id: !input light entity_id: !input light
data: data:
brightness_step_pct: "{{ helper_hold_dim_step }}" brightness_step_pct: "{{ helper_hold_dim_step }}"
transition: "{{ helper_hold_delay }}"
- delay: "{{ helper_hold_delay }}" - delay: "{{ helper_hold_delay }}"
- conditions: - conditions:
- condition: trigger - condition: trigger
@@ -326,22 +333,23 @@ actions:
- hold-dots2-zha-e2213 - hold-dots2-zha-e2213
- hold-dots2-z2m-e2213 - hold-dots2-z2m-e2213
sequence: sequence:
- variables:
brightness_pct: "{{ iif(is_state(light, 'on'), state_attr(light, 'brightness'), 0) * 100 / 255 }}"
total_iterations_to_zero: "{{ (brightness_pct / helper_hold_dim_step) | round(0, 'ceil') }}"
- repeat: - repeat:
while: count: "{{ total_iterations_to_zero - 1 }}"
- condition: template
value_template:
"{{ state_attr(light, 'brightness') | int / 255 > helper_hold_dim_step/100
}}"
sequence: sequence:
- parallel: - parallel:
- action: light.turn_on - action: light.turn_on
target:
entity_id: !input light
data: data:
brightness_step_pct: "{{ helper_hold_dim_step | int * -1 }}" brightness_step_pct: "{{ helper_hold_dim_step | int * -1 }}"
target: transition: "{{ helper_hold_delay }}"
entity_id: !input light
- delay: "{{ helper_hold_delay }}" - delay: "{{ helper_hold_delay }}"
- action: light.turn_on - action: light.turn_on
data:
brightness_pct: 1
target: target:
entity_id: !input light entity_id: !input light
data:
brightness_pct: 1
transition: "{{ helper_hold_delay }}"