blob: 1c90706437fafee91a30d7ba5a4088d9c102e041 (
plain)
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
|
substitutions:
project_ver_let: u
# don't toggle if force_ap script is started by holding 5+ seconds
sub_toggle_check: script_force_ap
sub_on_hold_5s: script_force_ap
default_button_config: "Toggle on Release"
packages:
kauf_plug_base:
url: https://github.com/KaufHA/PLF10
files: kauf-plug.yaml
refresh: 0s
dashboard_import:
package_import_url: github://KaufHA/PLF10/kauf-plug.yaml
esphome:
name_add_mac_suffix: true
on_boot:
then:
# implementing on_boot automation as a script makes it run in parallel with
# main on_boot script and any other on_boot scripts.
- script.execute: on_boot_wifi
globals:
- id: force_ap
type: bool
restore_value: yes
initial_value: "true"
# re-adding wifi component so that hotspot will be enabled
wifi:
# enable wifi ap, which was not needed in dashboard import version
ap:
ap_timeout: 2147483647ms # maximum 32 bit value. About 3.5 weeks in milliseconds.
# by default, fast_connect is disabled. Will automatically be enabled by wifi component
# needs to be set false here as dashboard import version sets true
fast_connect: false
# add forced hash in update bin file which isn't needed for dashboard import.
# Allows saving wifi credentials across update.
forced_hash: 1432266978
captive_portal: # for fallback wifi hotspot
script:
- id: script_force_ap
then:
- logger.log: "------------------->>>>>>>>>>>>>>>>> HELD BUTTON 5 SECONDS, FORCING AP"
# blink LED for 10s then restart to get captive portal to turn on.
- globals.set:
id: force_ap
value: 'true'
- script.execute: blink_led
- delay: 10s
# we have to restart because ESPHome's AP won't show the captive portal once wifi has been connected.
- button.press: restart_button
# blink LED forever. Used when button is held to re-enable AP. Stops blinking because plug restarts.
- id: blink_led
mode: queued
then:
- light.toggle: blue_led
- delay: 333ms
- script.execute: blink_led
# clear wifi credentials and reboot. causes AP to be enabled.
- id: on_boot_wifi
then:
# wait until ESPHome tries loading wifi credentials
- wait_until:
lambda: return ( wifi_wificomponent->tried_loading_creds );
# enable AP if credentials couldn't be loaded or force_ap is set
- lambda: |-
if ( !wifi_wificomponent->loaded_creds || id(force_ap) ) {
ESP_LOGD("KAUF on_boot","------------------->>>>>>>>>>>>>>>>> wifi not configured, enabling ap and waiting");
wifi_wificomponent->set_ap_timeout(15000);
}
- wait_until: # wait until wifi connects
wifi.connected
- globals.set: # clear global so ap doesn't come back up next time
id: force_ap
value: 'false'
# set ap timeout to max 32 bit value in milliseconds. About 3.5 weeks.
- lambda: |-
ESP_LOGD("KAUF on_boot","------------------->>>>>>>>>>>>>>>>> wifi connected, cranking ap timeout back up");
wifi_wificomponent->set_ap_timeout(2147483647);
|