feat: update doorbell to support multi-click

This commit is contained in:
Mario Lang 2025-08-09 15:15:40 +00:00
parent f20540792f
commit 213469defa
2 changed files with 68 additions and 48 deletions

View file

@ -4,7 +4,7 @@ time:
binary_sensor:
- platform: status
name: Online
name: Status
id: ink_ha_connected
entity_category: diagnostic

View file

@ -5,10 +5,14 @@ esphome:
esp32:
board: esp32dev
framework:
type: esp-idf
packages: !include common/base.yaml
# Enable Home Assistant API
api:
web_server:
logger:
ota:
- platform: esphome
@ -18,15 +22,35 @@ wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
sensor:
- platform: uptime
name: Uptime
- platform: wifi_signal
name: WiFi Signal
update_interval: 10s
event:
- platform: template
name: Doorbell
id: doorbell
device_class: doorbell
event_types:
- short
- double
- long
on_event:
then:
- if:
condition:
- switch.is_on: chime_active
then:
- switch.turn_on: relay
- light.turn_on:
id: ring
red: 0
green: 1
blue: 0.7
effect: pulse
- delay: 0.2s
- switch.turn_off: relay
- delay: 5s
- light.turn_off: ring
globals:
- id: chime
- id: should_ring
type: bool
restore_value: True
initial_value: 'true'
@ -42,60 +66,56 @@ switch:
name: Chime Active
restore_mode: RESTORE_DEFAULT_ON
lambda: |-
return id(chime);
return id(should_ring);
turn_on_action:
- globals.set:
id: chime
id: should_ring
value: 'true'
turn_off_action:
- globals.set:
id: chime
id: should_ring
value: 'false'
binary_sensor:
- platform: gpio
id: push_button
id: button_doorbell
internal: True
pin:
number: GPIO15
mode:
input: True
pulldown: True
filters:
- delayed_on: 50ms
- delayed_off: 8s
on_press:
then:
- light.turn_on:
id: ring
red: 0
green: 1
blue: 0.7
effect: pulse
- button.press: chime_button
on_release:
then:
- light.turn_off:
id: ring
transition_length: 1s
- platform: status
name: Status
- delayed_on: 20ms
- delayed_off: 20ms
on_multi_click:
# Single Short Click
- timing:
- ON for at most 750ms
- OFF for at least 300ms
then:
- event.trigger:
id: doorbell
event_type: short
button:
- platform: template
id: chime_button
name: Ring
icon: mdi:bell
on_press:
then:
- if:
condition:
- switch.is_on: chime_active
then:
- switch.turn_on: relay
- delay: 0.3s
- switch.turn_off: relay
- platform: restart
name: Restart
# Double Click: two quick presses
- timing:
- ON for at most 750ms
- OFF for at most 300ms
- ON for at most 750ms
- OFF for at least 300ms
then:
- event.trigger:
id: doorbell
event_type: double
# Long Press only
- timing:
- ON for at least 750ms
then:
- event.trigger:
id: doorbell
event_type: long
output:
- platform: ledc
@ -125,4 +145,4 @@ light:
transition_length: 1s
update_interval: 1s
default_transition_length:
milliseconds: 200
milliseconds: 100