-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclockbox.yaml
More file actions
192 lines (165 loc) · 4.49 KB
/
Copy pathclockbox.yaml
File metadata and controls
192 lines (165 loc) · 4.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
esphome:
name: bedside-clock
friendly_name: Bedside Clock
includes:
- "<Adafruit_GFX.h>"
- "<Adafruit_LEDBackpack.h>"
libraries:
- "Wire"
- "SPI"
- "Adafruit BusIO"
- "Adafruit GFX Library"
- "Adafruit LED Backpack Library"
on_boot:
priority: -100
then:
- lambda: |-
id(matrix).begin(0x70);
id(matrix).setBrightness(id(display_brightness).state);
esp8266:
board: d1_mini
logger:
api:
ota:
- platform: esphome
password: !secret ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
i2c:
sda: D2
scl: D1
scan: true
time:
- platform: homeassistant
id: ha_time
# Declare custom Adafruit_7segment C++ instance
globals:
- id: matrix
type: Adafruit_7segment
restore_value: no
- id: breath_phase
type: float
initial_value: '0.0'
# Virtual state tracking for light entities
- id: red_light_state
type: bool
initial_value: 'false'
- id: red_light_brightness
type: float
initial_value: '1.0'
- id: green_light_state
type: bool
initial_value: 'false'
- id: green_light_brightness
type: float
initial_value: '1.0'
# Exposed Number Slider in Home Assistant for Display Brightness (0 to 15)
number:
- platform: template
name: "Display Brightness"
id: display_brightness
min_value: 0
max_value: 15
step: 1
initial_value: 15
optimistic: true
restore_value: true
set_action:
- lambda: |-
id(matrix).setBrightness((uint8_t)x);
id(matrix).writeDisplay();
# Refresh 7-Segment display using Adafruit Library functions
interval:
- interval: 1000ms
then:
- lambda: |-
auto time = id(ha_time).now();
if (time.is_valid()) {
int hours = time.hour;
int minutes = time.minute;
if (hours == 0) {
hours = 12;
} else if (hours > 12) {
hours -= 12;
}
int display_value = (hours * 100) + minutes;
id(matrix).print(display_value, DEC);
id(matrix).drawColon(true);
id(matrix).writeDisplay();
} else {
id(matrix).clear();
id(matrix).writeDisplay();
}
# Animation loop (~60 FPS) for hardware PWM and breathing
- interval: 16ms
then:
- lambda: |-
// 1. Advance wave phase if breathing is enabled
if (id(breathing_enabled).state) {
id(breath_phase) += 0.025f;
if (id(breath_phase) > 6.28318f) {
id(breath_phase) -= 6.28318f;
}
}
// 2. Calculate breathing factor
float sine_factor = (sinf(id(breath_phase)) + 1.0f) / 2.0f;
float breath_multiplier = id(breathing_enabled).state ? (0.15f + 0.85f * sine_factor) : 1.0f;
// 3. Drive Red PWM hardware
if (id(red_light_state)) {
id(red_led_pwm).set_level(id(red_light_brightness) * breath_multiplier);
} else {
id(red_led_pwm).set_level(0.0f);
}
// 4. Drive Green PWM hardware
if (id(green_light_state)) {
id(green_led_pwm).set_level(id(green_light_brightness) * breath_multiplier);
} else {
id(green_led_pwm).set_level(0.0f);
}
switch:
- platform: template
name: "Wakeup Light Breathing Effect"
id: breathing_enabled
optimistic: true
restore_mode: RESTORE_DEFAULT_OFF
turn_off_action:
- lambda: |-
id(breath_phase) = 0.0f;
# Hardware PWM Outputs
output:
- platform: esp8266_pwm
id: red_led_pwm
pin: D5
max_power: 100%
- platform: esp8266_pwm
id: green_led_pwm
pin: D6
max_power: 100%
# Virtual Output Bridges for Template Lights
- platform: template
id: red_virtual_output
type: float
write_action:
- lambda: |-
id(red_light_state) = (state > 0.0f);
id(red_light_brightness) = state;
- platform: template
id: green_virtual_output
type: float
write_action:
- lambda: |-
id(green_light_state) = (state > 0.0f);
id(green_light_brightness) = state;
# Monochromatic Light entities exposed to Home Assistant
light:
- platform: monochromatic
name: "Wakeup Light Red"
id: red_wakeup_light
output: red_virtual_output
default_transition_length: 0s
- platform: monochromatic
name: "Wakeup Light Green"
id: green_wakeup_light
output: green_virtual_output
default_transition_length: 0s