152 lines
3.4 KiB
YAML
152 lines
3.4 KiB
YAML
substitutions:
|
|
name: "old-phone-doorbell"
|
|
friendly_name: "Old Phone (Doorbell)"
|
|
|
|
esphome:
|
|
name: "${name}"
|
|
|
|
esp8266:
|
|
board: nodemcuv2
|
|
framework:
|
|
version: dev
|
|
|
|
# Enable Home Assistant API
|
|
api:
|
|
encryption:
|
|
key: !secret oldphonedoorbell_api
|
|
|
|
ota:
|
|
- platform: esphome
|
|
password: !secret oldphonedoorbell_ota
|
|
|
|
wifi:
|
|
ssid: !secret wifi_ssid
|
|
password: !secret wifi_password
|
|
|
|
# Enable fallback hotspot (captive portal) in case wifi connection fails
|
|
ap:
|
|
ssid: "Old-Phone-Doorbell"
|
|
password: !secret oldphonedoorbell_fallback
|
|
|
|
captive_portal:
|
|
|
|
|
|
output:
|
|
- platform: gpio
|
|
pin: GPIO4 # H-Bridge A (D2)
|
|
id: h_bridge_a
|
|
inverted: false
|
|
- platform: gpio
|
|
pin: GPIO5 # H-Bridge B (D1)
|
|
id: h_bridge_b
|
|
inverted: false
|
|
- platform: gpio
|
|
pin: GPIO14 # Enable (D5)
|
|
id: h_bridge_enable
|
|
inverted: false
|
|
|
|
globals:
|
|
- id: is_ringing_active
|
|
type: bool
|
|
restore_value: no
|
|
initial_value: 'false'
|
|
- id: current_ac_phase
|
|
type: bool
|
|
restore_value: no
|
|
initial_value: 'false'
|
|
|
|
# Timer for 20Hz AC (50ms period - alternates every 25ms)
|
|
|
|
interval:
|
|
- interval: 19ms
|
|
then:
|
|
- if:
|
|
condition:
|
|
and:
|
|
- lambda: 'return id(is_ringing_active);'
|
|
then:
|
|
- if:
|
|
condition:
|
|
lambda: 'return id(current_ac_phase);'
|
|
then:
|
|
- output.turn_on: h_bridge_a
|
|
- output.turn_off: h_bridge_b
|
|
else:
|
|
- output.turn_off: h_bridge_a
|
|
- output.turn_on: h_bridge_b
|
|
- globals.set:
|
|
id: current_ac_phase
|
|
value: !lambda 'return !id(current_ac_phase);'
|
|
else:
|
|
- output.turn_off: h_bridge_a
|
|
- output.turn_off: h_bridge_b
|
|
|
|
button:
|
|
- platform: template
|
|
name: "${friendly_name}"
|
|
icon: "mdi:phone-classic"
|
|
on_press:
|
|
- script.execute: british_ring_script
|
|
|
|
number:
|
|
- platform: template
|
|
name: "Nuber of times ringing"
|
|
optimistic: true
|
|
id: RingCount
|
|
unit_of_measurement: "times"
|
|
initial_value: 3
|
|
restore_value: true
|
|
min_value: 1
|
|
max_value: 10
|
|
step: 1
|
|
mode: box
|
|
|
|
script:
|
|
- id: british_ring_script
|
|
then:
|
|
# Initialize
|
|
- output.turn_off: h_bridge_a
|
|
- output.turn_off: h_bridge_b
|
|
- globals.set:
|
|
id: current_ac_phase
|
|
value: 'false'
|
|
# Enable H-bridge
|
|
- output.turn_on: h_bridge_enable
|
|
- delay: 10ms # Ensure enable stabilization
|
|
|
|
# Ring pattern (3 cycles)
|
|
- repeat:
|
|
count: !lambda 'return int(id(RingCount).state);'
|
|
then:
|
|
# First ring segment (400ms)
|
|
- globals.set:
|
|
id: is_ringing_active
|
|
value: 'true'
|
|
- delay: 400ms
|
|
|
|
# First pause (200ms)
|
|
- globals.set:
|
|
id: is_ringing_active
|
|
value: 'false'
|
|
- delay: 200ms
|
|
|
|
# Second ring segment (400ms)
|
|
- globals.set:
|
|
id: is_ringing_active
|
|
value: 'true'
|
|
- delay: 400ms
|
|
|
|
# Long pause (2000ms)
|
|
- globals.set:
|
|
id: is_ringing_active
|
|
value: 'false'
|
|
- delay: 2000ms
|
|
|
|
# Final cleanup
|
|
- delay: 10ms
|
|
- output.turn_off: h_bridge_enable
|
|
|
|
logger:
|
|
level: DEBUG
|
|
|