Skip to content

Commit 731074e

Browse files
committed
add release without hold
1 parent b58033d commit 731074e

File tree

1 file changed

+50
-12
lines changed

1 file changed

+50
-12
lines changed

kauf-rgbs.yaml

+50-12
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ substitutions:
1515

1616
# https://esphome.io/components/esphome.html#esphome-creators-project
1717
project_name: Kauf.RGBSw
18-
project_ver_num: "1.321"
18+
project_ver_num: "1.322"
1919
project_ver_let: y
2020

2121
disable_entities: "true" # set to "false" to have all entities show up in Home Assistant automatically
@@ -27,11 +27,12 @@ substitutions:
2727
# when these substitutions are redefined. Redefining these will not stop the ui switch from toggling.
2828
# The button configuration select entity must be set to disabled to stop the button from toggling the ui switch.
2929
# The button press duration sensor will also still update even with these redefined.
30-
sub_on_press: script_do_nothing # executes right when button is pressed
31-
sub_on_release: script_do_nothing # executes right when button is released
32-
sub_on_double_press: script_do_nothing # executes when the button is double pressed
33-
sub_on_single_press: script_do_nothing # executes when the button is single pressed only, not held or double pressed
34-
sub_on_hold: script_do_nothing # executes when the button is held for a threshold amount of time
30+
sub_on_press: script_do_nothing # executes right when button is pressed
31+
sub_on_release: script_do_nothing # executes right when button is released
32+
sub_on_double_press: script_do_nothing # executes when the button is double pressed
33+
sub_on_single_press: script_do_nothing # executes when the button is single pressed only, not held or double pressed
34+
sub_on_hold: script_do_nothing # executes when the button is held for a threshold amount of time
35+
sub_on_release_without_hold: script_do_nothing # executes when the button is released after a press that is under the hold threshold.
3536

3637
# an extra script that, if running, will stop the switch from toggling on button release.
3738
sub_toggle_check: script_do_nothing
@@ -54,12 +55,15 @@ substitutions:
5455
sub_hold_time: 750ms
5556
sub_button_sensor_duration: 500ms
5657

57-
# substitutions to sync hass entities to and from the switch
58-
hass_entity_single_press_toggle: no.ne
59-
hass_entity_double_press_toggle: no.ne
60-
hass_entity_hold_toggle: no.ne
61-
hass_entity_control_small_light: no.ne
62-
hass_entity_control_big_light: no.ne
58+
# substitutions to control hass entities with press combos
59+
hass_entity_single_press_toggle: no.ne
60+
hass_entity_double_press_toggle: no.ne
61+
hass_entity_hold_toggle: no.ne
62+
hass_entity_release_without_hold_toggle: no.ne
63+
64+
# substitutions to sync lights with hass entities instead of UI switch
65+
hass_entity_control_small_light: no.ne
66+
hass_entity_control_big_light: no.ne
6367

6468

6569
# https://esphome.io/components/esp8266.html
@@ -100,6 +104,9 @@ esphome:
100104
- binary_sensor.template.publish:
101105
id: button_hold
102106
state: OFF
107+
- binary_sensor.template.publish:
108+
id: button_release_without_hold
109+
state: OFF
103110

104111

105112
# https://esphome.io/components/external_components.html
@@ -237,6 +244,18 @@ binary_sensor:
237244
id(script_hass_toggle_hold).execute();
238245
id($sub_on_hold).execute();
239246
247+
# definition for release without hold
248+
- timing:
249+
- ON for at most $sub_hold_time
250+
then:
251+
- lambda: |-
252+
id(button_release_without_hold).publish_state(true);
253+
// toggle if button is configured to toggle on release without hold
254+
if (id(select_button).state == "Toggle on Release Without Hold") {
255+
id(ui_switch).toggle(); }
256+
id(script_hass_toggle_release_without_hold).execute();
257+
id($sub_on_release_without_hold).execute();
258+
240259
- platform: template
241260
name: $friendly_name Single Press
242261
id: button_single_press
@@ -265,6 +284,14 @@ binary_sensor:
265284
id: button_hold
266285
state: OFF
267286

287+
- platform: template
288+
name: $friendly_name Release Without Hold
289+
id: button_release_without_hold
290+
on_press:
291+
- delay: $sub_button_sensor_duration
292+
- binary_sensor.template.publish:
293+
id: button_release_without_hold
294+
state: OFF
268295

269296
# https://esphome.io/components/switch/index.html
270297
switch:
@@ -520,6 +547,7 @@ select:
520547
- Toggle on Single Press
521548
- Toggle on Double Press
522549
- Toggle on Hold
550+
- Toggle on Release Without Hold
523551
restore_value: true
524552
entity_category: config
525553
icon: mdi:toggle-switch-off-outline
@@ -656,6 +684,16 @@ script:
656684
data:
657685
entity_id: $hass_entity_hold_toggle
658686

687+
- id: script_hass_toggle_release_without_hold
688+
then:
689+
if:
690+
condition: # toggle if release without hold hass entity is set
691+
lambda: return (strcmp("$hass_entity_release_without_hold_toggle","no.ne") != 0 );
692+
then:
693+
homeassistant.service:
694+
service: homeassistant.toggle
695+
data:
696+
entity_id: $hass_entity_release_without_hold_toggle
659697

660698
# https://esphome.io/components/button/index.html
661699
button:

0 commit comments

Comments
 (0)