forked from KaufHA/kauf-rgbww-bulbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kauf-bulb-lite.yaml
284 lines (219 loc) · 7.88 KB
/
kauf-bulb-lite.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
# 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-lite.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
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.93"
project_ver_let: l
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
# https://esphome.io/guides/automations.html#global-variables
globals:
- 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
# default is 20, 17 is recommended.
output_power: 17
# using fast_connect as default since it is required for hidden networks.
fast_connect: true
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
# 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:
- platform: 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_white_color_temperature: $sub_warm_white_temp
cold_white_color_temperature: $sub_cold_white_temp
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/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
# 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();