blob: 8e757567018a401b342ef2e1b0747ac385d2c727 (
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
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
|
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: !include kauf-plug.yaml
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 any other on_boot scripts.
- script.execute: on_boot_wifi
external_components:
# - source:
# type: git
# url: https://github.com/KaufHA/common
# # ref: v2022.06.21
# refresh: 0s
- source:
type: local
path: dev-common
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.
# 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
- 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
- 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);
# select:
# # default light state on boot
# - platform: template
# name: $friendly_name Power On State
# id: select_boot_state
# optimistic: true
# options:
# - "Restore Power Off State"
# - "Always On"
# - "Always Off"
# initial_option: Restore Power Off State
# restore_value: true
# icon: mdi:restart-alert
# on_value:
# - lambda: |-
# if ( x == "Always On" ) {
# // disable saving any more values in the relay flash address
# relay->set_restore_mode(esphome::gpio::GPIO_SWITCH_ALWAYS_ON);
# // save a "1" in the relay flash address so that gets restored next time
# relay->force_save(true);
# }
# else if ( x == "Always Off" ) {
# // disable saving any more values in the relay flash address
# relay->set_restore_mode(esphome::gpio::GPIO_SWITCH_ALWAYS_ON);
# // save a "0" in the relay flash address so that gets restored next time
# relay->force_save(false);
# }
# else
# relay->set_restore_mode(esphome::gpio::GPIO_SWITCH_$sub_restore_mode);
# //relay->write_state(id(relay));
# - script.execute: script_save_changes
# - delay: 5s
# # always go to a restoring mode after boot, we already got what we wanted out of the boot state,
# # this way the current state will continue to be saved no matter the setting.
# - lambda: relay->set_restore_mode(esphome::gpio::GPIO_SWITCH_RESTORE_DEFAULT_ON);
# entity_category: config
# forced_hash: 3222171394
# forced_addr: 74
# global_addr: global_forced_addr
|