77 lines
2.7 KiB
Plaintext
77 lines
2.7 KiB
Plaintext
#substitutions:
|
|
# local_gpioinvert: "True"
|
|
# local_singleclick_duration: "300000" # 5 minutes in ms
|
|
# local_doubleclick_duration: "1800000" # 30 minutes in ms
|
|
# local_tripleclick_duration: "7200000" # 2 hours in ms
|
|
|
|
#globals:
|
|
# - id: single_click_delay
|
|
# type: long
|
|
# restore_value: no
|
|
# initial_value: ${local_singleclick_duration}
|
|
# - id: double_click_delay
|
|
# type: long
|
|
# restore_value: no
|
|
# initial_value: ${local_doubleclick_duration}
|
|
# - id: triple_click_delay
|
|
# type: long
|
|
# restore_value: no
|
|
# initial_value: ${local_tripleclick_duration}
|
|
|
|
binary_sensor:
|
|
- platform: gpio
|
|
pin:
|
|
number: ${local_gpio}
|
|
mode: INPUT
|
|
inverted: True
|
|
name: ${local_name}
|
|
on_multi_click:
|
|
# Single Click: one press (short press/release)
|
|
- timing:
|
|
- ON for at most 1s
|
|
- OFF for at least 0.5s
|
|
then:
|
|
- lambda: |-
|
|
if (id(local_relay_id).state) {
|
|
ESP_LOGD(id(local_gpio},"Single click: ",id(local_relay_id)," is on, turning it off.");
|
|
id(local_relay_id).turn_off();
|
|
} else {
|
|
ESP_LOGD(id(local_gpio), "Single click: ",id(local_relay_id)," is off, turning it on for %d ms.", id(local_singleclick_duraton));
|
|
id(local_relay_id).turn_on();
|
|
delay(id(local_singleclick_duration));
|
|
id(local_relay_id).turn_off();
|
|
}
|
|
# Double Click: two quick press/release cycles
|
|
- timing:
|
|
- ON for at most 1s
|
|
- OFF for at most 1s
|
|
- ON for at most 1s
|
|
- OFF for at least 0.5s
|
|
then:
|
|
- lambda: |-
|
|
ESP_LOGD(id(local_gpio), "Double click detected: turning ",id(local_relay_id)," on for %d ms.", id(local_doubleclick_duration));
|
|
id(local_relay_id).turn_on();
|
|
delay(id(local_doubleclick_duration));
|
|
id(local_relay_id).turn_off();
|
|
# Triple Click: three quick press/release cycles
|
|
- timing:
|
|
- ON for at most 1s
|
|
- OFF for at most 1s
|
|
- ON for at most 1s
|
|
- OFF for at most 1s
|
|
- ON for at most 1s
|
|
- OFF for at least 0.5s
|
|
then:
|
|
- lambda: |-
|
|
ESP_LOGD(id(local_gpio), "Triple click detected: turning ",id(local_relay_id)," on for %d ms.", id(local_tripleclick_duration));
|
|
id(local_relay_id).turn_on();
|
|
delay(id(local_tripleclick_duration));
|
|
id(local_relay_id).turn_off();
|
|
# Hold: button held for at least 4 seconds
|
|
- timing:
|
|
- ON for at least 4s
|
|
then:
|
|
- lambda: |-
|
|
ESP_LOGD(id(local_gpio), "Hold detected: turning ",id(local_relay_id)," on indefinitely.");
|
|
id(local_relay_id).turn_on();
|