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,97 +45,109 @@ 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_hold_delay: helper_section :
name: Helper - Hold delay name: Helpers
description: Delay between the execution of the **Hold** action(s). icon: mdi:cog-outline
default: 250 collapsed: true
selector: input:
number: helper_hold_delay:
unit_of_measurement: milliseconds name: Hold delay
min: 100.0 description: Delay between the execution of the **Hold** action(s).
max: 5000.0 default: 250
step: 10.0 selector:
mode: slider number:
helper_max_loops: unit_of_measurement: milliseconds
name: Helper - Max number of loops min: 100.0
description: Maximum number of loops when holding down a button. max: 5000.0
default: 20 step: 10.0
selector: mode: slider
number: helper_max_loops:
min: 1.0 name: Max number of loops
max: 1000.0 description: Maximum number of loops when holding down a button.
step: 1.0 default: 20
mode: slider selector:
on_double_press_exposed: number:
name: (Rodret only) Double press event (on) min: 1.0
description: > max: 1000.0
**_(Rodret only)_** Choose whether or not to expose the virtual **double press** event for the **on** button. step: 1.0
Turn this on if you are providing action(s) for the **Double press action (on / 1 dot)**. mode: slider
default: false rodret_options_section:
selector: name: Rodret options
boolean: {} icon: mdi:remote
off_double_press_exposed: collapsed: true
name: (Rodret only) Double press event (off) input:
description: > on_double_press_exposed:
**_(Rodret only)_** Choose whether or not to expose the virtual **double press** event for the **off** button. name: Expose virtual double press "on" event
Turn this on if you are providing an action for the **Double press action (off / 2 dots)**. description: >
default: false Choose whether or not to expose the virtual **double press** event for the **on** button.
selector: Turn this on if you are providing action(s) for the **Double press action (on / 1 dot)**.
boolean: {} default: false
helper_double_press_delay: selector:
name: (Rodret only) Helper - Double press delay boolean: {}
description: > off_double_press_exposed:
**(Rodret only)** Max delay between the first and the second button press for the name: Expose virtual double press "off" event
**Double press events**. Provide a value only if you are using a double press action. description: >
Increase this value if you notice that the double press action is not triggered Choose whether or not to expose the virtual **double press** event for the **off** button.
properly. Turn this on if you are providing an action for the **Double press action (off / 2 dots)**.
default: 250 default: false
selector: selector:
number: boolean: {}
unit_of_measurement: milliseconds helper_double_press_delay:
min: 100.0 name: Double press delay
max: 5000.0 description: >
step: 10.0 Max delay between the first and the second button press for the
mode: slider **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
properly.
default: 250
selector:
number:
unit_of_measurement: milliseconds
min: 100.0
max: 5000.0
step: 10.0
mode: slider
mode: single mode: single
max_exceeded: silent max_exceeded: silent
triggers: triggers:

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,25 +54,30 @@ blueprint:
filter: filter:
domain: light domain: light
multiple: false multiple: false
helper_force_brightness: brightness_section:
name: Helper - Force brightness name: Brightness
description: Force the brightness to **Helper - Brightness** value when light turns on. icon: mdi:lightbulb-on-50
default: false collapsed: true
selector: input:
boolean: {} helper_force_brightness:
helper_brightness: name: Force brightness
name: Helper - Brightness description: Force the brightness to **Brightness** value when light turns on.
description: default: false
Target light brightness when turning on. Requires **Helper - Force brightness** selector:
to be enabled. boolean: {}
default: 50 helper_brightness:
selector: name: Brightness
number: description:
unit_of_measurement: "%" Target light brightness when turning on. Requires **Force brightness**
min: 1.0 to be enabled.
max: 100.0 default: 50
step: 1.0 selector:
mode: slider number:
unit_of_measurement: "%"
min: 1.0
max: 100.0
step: 1.0
mode: slider
mode: restart mode: restart
max_exceeded: silent max_exceeded: silent
triggers: triggers:
@@ -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
data:
brightness_step_pct: "{{ helper_hold_dim_step | int * -1 }}"
target: target:
entity_id: !input light entity_id: !input light
data:
brightness_step_pct: "{{ helper_hold_dim_step | int * -1 }}"
transition: "{{ helper_hold_delay }}"
- 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 }}"