forked from KaufHA/kauf-rgbww-bulbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kauf-bulb.yaml
399 lines (319 loc) · 11 KB
/
kauf-bulb.yaml
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
# https://esphome.io/guides/configuration-types.html#substitutions
substitutions:
# substitutions can be changed here if you are using this file directly in the ESPHome dashboard. The better approach is
# to incorporate this file as a package using the following lines, and then overwrite these substitutions in your local
# yaml file by redefining them.
#
# packages:
# kauf.rgbww: github://KaufHA/kauf-rgbww-bulbs/kauf-bulb.yaml
#
name: kauf-bulb # **** CHANGE DEVICE NAME TO SOMETHING UNIQUE PER DEVICE. RENAME YAML FILE TO SAME NAME. ****
# **** USE DASHES (-) INSTEAD OF SPACES OR UNDERSCORE (_). USE ONLY LOWER CASE LETTERS. ****
friendly_name: Kauf Bulb # **** CHANGE FRIENDLY NAME TO SOMETHING UNIQUE PER DEVICE ****
disable_entities: "true" # set to "false" to have all entities show up in Home Assistant automatically
disable_webserver: "false" # set to "true" to disable webserver listening on port 80.
wifi_ap_timeout: 2min # default to 2 minute timeout for yaml file as package.
# https://esphome.io/components/esphome.html#esphome-creators-project
project_name: Kauf.RGBWW
project_ver_num: "1.931b1"
project_ver_let: y
sub_on_turn_on: script_do_nothing
sub_on_turn_off: script_do_nothing
sub_red_pin: GPIO4
sub_green_pin: GPIO12
sub_blue_pin: GPIO14
sub_cw_pin: GPIO5
sub_ww_pin: GPIO13
sub_warm_white_temp: 2800 Kelvin
sub_cold_white_temp: 6600 Kelvin
sub_red_freq: 200 hz
sub_green_freq: 200 hz
sub_blue_freq: 200 hz
sub_cw_freq: 400 hz
sub_ww_freq: 400 hz
sub_reboot_req: '9'
sub_ota_num_attempts: '15'
# removed config entities
sub_max_power: '0.8'
sub_default_transition_length: 250ms
sub_api_reboot_timeout: 0s
light_restore_mode: RESTORE_DEFAULT_ON # change power-on action for main light entity (https://esphome.io/components/light/index.html#base-light-configuration)
# https://esphome.io/components/esp8266.html
esp8266:
board: esp01_1m
restore_from_flash: true
start_free: 76
global_addr: global_forced_addr
# https://esphome.io/components/external_components.html
external_components:
- source:
type: git
url: https://github.com/KaufHA/common
ref: v2024.05.08
refresh: never
- source:
type: git
url: https://github.com/bkaufx/kauf-rgbww-bulbs
refresh: always
# https://esphome.io/guides/automations.html#global-variables
globals:
- id: global_forced_addr
type: int
restore_value: no
initial_value: '12345'
- id: global_quick_boot_count
type: int
restore_value: yes
initial_value: '0'
# https://esphome.io/components/esphome.html
esphome:
name: $name
project:
name: $project_name
version: $project_ver_num($project_ver_let)
on_boot:
then:
- script.execute: script_quick_boot
# https://esphome.io/components/button/index.html
# https://esphome.io/components/button/restart.html
button:
- platform: restart
id: restart_button
name: $friendly_name Restart Firmware
entity_category: diagnostic
disabled_by_default: $disable_entities
# https://esphome.io/components/wifi.html
wifi:
ssid: initial_ap
password: asdfasdfasdfasdf
# using fast_connect as default since it is required for hidden networks.
fast_connect: true
forced_addr: 0
global_addr: global_forced_addr
ap:
ap_timeout: $wifi_ap_timeout
# https://esphome.io/components/captive_portal.html
captive_portal:
# https://esphome.io/components/logger.html
logger:
# https://esphome.io/components/api.html
api:
id: kauf_api
reboot_timeout: $sub_api_reboot_timeout
# https://esphome.io/components/ota.html
ota:
num_attempts: $sub_ota_num_attempts
on_error:
then:
- button.press: restart_button
# https://esphome.io/components/web_server.html
web_server:
local: true
disable: $disable_webserver
# PWM outputs for each LED channel
# https://esphome.io/components/output/esp8266_pwm.html
output:
- platform: esp8266_pwm
pin: $sub_red_pin
frequency: $sub_red_freq
id: pwm_red
max_power: $sub_max_power
- platform: esp8266_pwm
pin: $sub_green_pin
frequency: $sub_green_freq
id: pwm_green
max_power: $sub_max_power
- platform: esp8266_pwm
pin: $sub_blue_pin
frequency: $sub_blue_freq
id: pwm_blue
max_power: $sub_max_power
- platform: esp8266_pwm
pin: $sub_cw_pin
frequency: $sub_cw_freq
id: pwm_cw
max_power: $sub_max_power
- platform: esp8266_pwm
pin: $sub_ww_pin
frequency: $sub_ww_freq
id: pwm_ww
max_power: $sub_max_power
# https://esphome.io/components/light/index.html
light:
# Additive RGB light for Warm White
- platform: kauf_rgbww
id: warm_rgb
entity_category: config
default_transition_length: 0ms
icon: mdi:store-cog
aux: true
name: $friendly_name Warm RGB
forced_hash: 4077116474
forced_addr: 28
global_addr: global_forced_addr
disabled_by_default: $disable_entities
restore_mode: RESTORE_DEFAULT_OFF
# Additive RGB light for Cold White
- platform: kauf_rgbww
id: cold_rgb
entity_category: config
default_transition_length: 0ms
icon: mdi:store-cog-outline
aux: true
name: $friendly_name Cold RGB
forced_hash: 301094535
forced_addr: 40
global_addr: global_forced_addr
disabled_by_default: $disable_entities
restore_mode: RESTORE_DEFAULT_OFF
# Main RGBWW light
- platform: kauf_rgbww
id: kauf_light
default_transition_length: $sub_default_transition_length
name: $friendly_name
red: pwm_red
green: pwm_green
blue: pwm_blue
warm_white: pwm_ww
cold_white: pwm_cw
warm_rgb: warm_rgb
cold_rgb: cold_rgb
warm_white_color_temperature: $sub_warm_white_temp
cold_white_color_temperature: $sub_cold_white_temp
forced_hash: 2723974766
forced_addr: 52
global_addr: global_forced_addr
restore_mode: $light_restore_mode
on_turn_on:
- script.execute: $sub_on_turn_on
on_turn_off:
- script.execute: $sub_on_turn_off
# https://esphome.io/components/select/index.html
# https://esphome.io/components/select/template.html
select:
- platform: template
name: $friendly_name Effect
id: effect
optimistic: true
options:
- "None"
- "WLED / DDP"
initial_option: "None"
restore_value: true
icon: mdi:string-lights
on_value:
- lambda: |-
if ( x == "WLED / DDP" ) { id(kauf_light).set_use_wled(true); }
else { id(kauf_light).set_use_wled(false); }
- script.execute: script_save_changes
entity_category: config
forced_hash: 5841966
forced_addr: 66
global_addr: global_forced_addr
- platform: template
name: $friendly_name DDP Debug
id: select_ddp_debug
optimistic: true
options:
- "Print no packets"
- "Print imperfect packets"
- "Print all packets"
initial_option: "Print no packets"
restore_value: false
icon: mdi:play-network
entity_category: diagnostic
disabled_by_default: $disable_entities
set_action:
- lambda: |-
if ( x == "Print no packets" ) { id(kauf_light).set_ddp_debug(0); }
else if ( x == "Print imperfect packets" ) { id(kauf_light).set_ddp_debug(1); }
else if ( x == "Print all packets" ) { id(kauf_light).set_ddp_debug(2); }
# https://esphome.io/components/sensor/uptime.html
sensor:
- platform: uptime
name: $friendly_name Uptime
update_interval: 60s
entity_category: diagnostic
disabled_by_default: $disable_entities
# Send IP Address to HA.
# https://esphome.io/components/text_sensor/wifi_info.html
text_sensor:
- platform: wifi_info
ip_address:
name: $friendly_name IP Address
entity_category: diagnostic
disabled_by_default: $disable_entities
# https://esphome.io/guides/automations.html#script-component
script:
- id: script_save_changes
mode: restart
then:
- delay: 3s
- lambda: global_preferences->sync();
- id: script_do_nothing
then:
lambda: return;
# increment global_quick_boot_count if bulb stays on less than 10 seconds or never connects to wifi
# reset wifi credentials if the counter gets to $sub_reboot_req
- id: script_quick_boot
then:
# if quick boot count is $sub_reboot_req, overwrite wifi credentials to force AP
- if:
condition:
lambda: return ( id(global_quick_boot_count) >= $sub_reboot_req );
then:
- lambda: |-
ESP_LOGD("kauf-bulb.yaml", "quick boot count variable is now $sub_reboot_req, overwriting credentials and rebooting");
// turn on red light
auto call = id(kauf_light).turn_on();
call.set_brightness(0.6);
call.set_rgb(1.0, 0.0, 0.0);
call.set_save(false);
call.perform();
// reset counter and immediately save
id(global_quick_boot_count) = 0;
global_quick_boot_count->loop();
global_preferences->sync();
# short delay
- delay: 2s
# wait until attempt to load credentials has been made, that way we know the new ones can be saved properly.
- wait_until:
lambda: return ( wifi_wificomponent->tried_loading_creds );
# the save_wifi_sta function reboots.
- lambda: |-
// overwrite wifi credentials
wifi::global_wifi_component->save_wifi_sta("initial_ap","asdfasdfasdfasdf");
# increment quick boot counter so it will stay incremented if device reboots
- lambda: |-
ESP_LOGD("kauf-bulb.yaml", "quick boot count variable is now %d. Need $sub_reboot_req to overwrite credentials", id(global_quick_boot_count));
id(global_quick_boot_count) += 1;
global_quick_boot_count->loop();
global_preferences->sync();
# if quick boot count gets over 1 (don't flash on first occurance in case it's an accident), flash light to indicate we are in process
- if:
condition:
lambda: return ( id(global_quick_boot_count) > 2 );
then:
- lambda: |-
auto call = id(kauf_light).turn_on();
call.set_brightness(0.5);
call.set_rgb(1.0, 1.0, 0.0);
call.set_save(false);
call.perform();
# wait 10 seconds
- delay: 10s
- lambda: ESP_LOGD("kauf-bulb.yaml", "quick boot script, 10 seconds up");
# wait until wifi is connected
- wait_until: wifi.connected
- lambda: ESP_LOGD("kauf-bulb.yaml", "quick boot script, wifi connected");
# any time boot is greater than 10 seconds and also connects to wifi, reset quick boot count to 0
- lambda: |-
id(global_quick_boot_count) = 0;
global_quick_boot_count->loop();
global_preferences->sync();
# Current reserved flash memory:
# 00-25: Wi-Fi Credentials
# 28-39: Warm RGB
# 40-51: Cold RGB
# 52-63: Main Light
# 66-67: Effect select