aboutsummaryrefslogtreecommitdiffhomepage
path: root/kauf-plug-factory.yaml
diff options
context:
space:
mode:
authorKaufHA <[email protected]>2021-10-02 15:30:28 -0700
committerGitHub <[email protected]>2021-10-02 15:30:28 -0700
commit3a0aa6107980bf956f78e923a16fd288b2262567 (patch)
treee341c470bfecbe9932e7f704782bc32ed2aece61 /kauf-plug-factory.yaml
parentc1fccaf93f8a315454987c0a8a6cd48dd93a2cf6 (diff)
downloadPLF10-3a0aa6107980bf956f78e923a16fd288b2262567.tar.gz
PLF10-3a0aa6107980bf956f78e923a16fd288b2262567.zip
1.6 upload 1
Diffstat (limited to 'kauf-plug-factory.yaml')
-rw-r--r--kauf-plug-factory.yaml185
1 files changed, 107 insertions, 78 deletions
diff --git a/kauf-plug-factory.yaml b/kauf-plug-factory.yaml
index 09a03b7..ef35c6e 100644
--- a/kauf-plug-factory.yaml
+++ b/kauf-plug-factory.yaml
@@ -4,7 +4,6 @@ substitutions:
friendly_name: Kauf Plug
-
esphome:
# **** CHANGE DEVICE NAME TO SOMETHING UNIQUE PER DEVICE ****
@@ -21,47 +20,49 @@ esphome:
project:
name: "kauf.plf10"
- version: "1.5a"
-
+ version: "1.6"
-
- # checking if wifi has ever been configured. Cranking up ap timeout to a week if so.
on_boot:
then:
+ # wait until ESPHome tries loading wifi credentials
+ - wait_until:
+ lambda: 'return ( wifi_wificomponent->tried_loading_creds );'
+
+
- if:
- condition:
- lambda: |-
- return id(wifi_configured_before);
+ condition: # don't do anything if credentials were loaded unless force_ap is on as override
+ lambda: 'return ( wifi_wificomponent->loaded_creds && !id(force_ap) );'
then:
- - logger.log: "------------------->>>>>>>>>>>>>>>>> wifi configured before, ap timeout to 2500h"
- - lambda: |-
- wifi_wificomponent->set_ap_timeout(9000000000ULL);
-
- else:
- - logger.log: "------------------->>>>>>>>>>>>>>>>> wifi not configured before, leaving ap timeout as 25s"
+ - logger.log: "------------------->>>>>>>>>>>>>>>>> already has wifi configured, leaving ap timeout cranked"
+ else: # if credentials not loaded or force_ap is set, lower ap timeout to allow saving new credentials
+ - globals.set: # clear global whether or not wifi ever connects.
+ id: force_ap
+ value: 'false'
+ - logger.log: "------------------->>>>>>>>>>>>>>>>> wifi not configured, enabling ap and waiting"
+
+ # set ap timeout to 15 seconds in milliseconds.
+ - lambda: |-
+ wifi_wificomponent->set_ap_timeout(15000);
- wait_until:
wifi.connected
- - logger.log: "------------------->>>>>>>>>>>>>>>>> wifi connected, setting wifi_configured_before variable and cranking up ap timeout"
- - globals.set:
- id: wifi_configured_before
- value: 'true'
+ - logger.log: "------------------->>>>>>>>>>>>>>>>> wifi connected, cranking ap timeout back up"
+
+ # set ap timeout to max 32 bit value in milliseconds. About 3.5 weeks.
- lambda: |-
- wifi_wificomponent->set_ap_timeout(9000000000ULL);
+ wifi_wificomponent->set_ap_timeout(2147483647);
globals:
- - id: wifi_configured_before
- type: bool
+ - id: force_ap
+ type: bool
restore_value: yes
- initial_value: 'false'
-
-
-
-
+ initial_value: "true"
wifi:
+
+ # default credentials as backup. Also needed to show found networks in captive portal.
ssid: initial_ap2
password: asdfasdfasdfasdf
@@ -81,7 +82,7 @@ wifi:
ap:
ssid: ${friendly_name} Hotspot
- ap_timeout: 25s
+ ap_timeout: 2147483647ms # default to max 32-bit value in milliseconds. About 3.5 weeks.
captive_portal: # for fallback wifi hotspot
@@ -95,17 +96,19 @@ api: # Enable Home Assistant API
ota:
# password: !secret ota_password # optional password for OTA updates.
-
debug: # outputs additional debug info when logs start
-
web_server: # web server allows access to device with a web browser
# auth: # optional login details for web interface
# username: admin
# password: !secret web_server_password
-
+ # host css and js file directly on device
+ css_include: "z_includes/webserver-v1.min.css"
+ css_url: ""
+ js_include: "z_includes/webserver-v1.min.js"
+ js_url: ""
# red led, blink when not connected to wifi or Home Assistant
@@ -114,15 +117,13 @@ status_led:
number: GPIO0
inverted: true
-
-
-
binary_sensor:
# button input toggles relay and thereby blue led
- platform: gpio
id: button
+ name: Kauf Plug Button
pin:
number: GPIO13
mode: INPUT_PULLUP
@@ -130,67 +131,52 @@ binary_sensor:
on_click:
- - min_length: 35ms
+ - min_length: 30ms
max_length: 2s
then:
- - switch.toggle: relay
+ - if:
+ condition: # only toggle relay if button is enabled
+ lambda: 'return (id(select_button).state == "Enabled");'
+ then:
+ switch.toggle: relay
- # if button is held >5s, restart AP.
+
+
+ # restart with AP enabled if button is held for 5 seconds (up to 30 seconds because ESPHome requires a max).
+ # Not disabled by button disable option because you may not be able to re-enable button if wifi is not connecting.
+ # If your kid accidentally triggers this, the plug will just reboot and reconnect to wifi. Shouldn't harm anything.
+
+ # we have to restart because ESPHome's AP won't show the captive portal once wifi connects.
- min_length: 5s
max_length: 30s
then:
- - logger.log: "------------------->>>>>>>>>>>>>>>>> HELD BUTTON 5 SECONDS, CLEARING VARIABLE AND STARTING AP"
- - globals.set:
- id: wifi_configured_before
- value: 'false'
- - lambda: |-
- wifi_wificomponent->set_ap_timeout(10000);
- - script.execute: blink_led
- - wait_until:
- wifi.connected
- - logger.log: "------------------->>>>>>>>>>>>>>>>> wifi connected, setting wifi_configured_before variable and cranking up ap timeout"
+ - logger.log: "------------------->>>>>>>>>>>>>>>>> HELD BUTTON 5 SECONDS, FORCING AP"
+
+ # blink LED for 10s then restart to get captive portal to turn on.
- globals.set:
- id: wifi_configured_before
+ id: force_ap
value: 'true'
- - lambda: |-
- wifi_wificomponent->set_ap_timeout(9000000000ULL);
- - while:
- condition:
- script.is_running: blink_led
- then:
- script.stop: blink_led
- # still need to set blue led to relay state
- - if:
- condition:
- lambda: 'return id(relay).state;'
- then:
- - switch.turn_on: blue_led
- else:
- - switch.turn_off: blue_led
-
-
+ - script.execute: blink_led
+ - delay: 10s
+ - switch.turn_on: restart_switch
+ # indicates whether plugged-in devices is running based on configurable threshold.
- platform: template
id: in_use
name: ${friendly_name} Device In Use
-
-
+# blink LED forever. Used when button is held to re-enable AP. Stops blinking because plug restarts.
script:
- id: blink_led
mode: queued
then:
- switch.toggle: blue_led
- - delay: 250ms
+ - delay: 333ms
- script.execute: blink_led
-
-
-
-
switch:
# blue LED follows relay power state
@@ -208,19 +194,25 @@ switch:
# automatically make blue led equal relay state
on_turn_on:
- - switch.turn_on: blue_led
+ - if:
+ condition: # only if blue LED enabled
+ lambda: 'return (id(select_led).state == "Enabled");'
+ then:
+ switch.turn_on: blue_led
+
on_turn_off:
- switch.turn_off: blue_led
+ - platform: restart
+ id: restart_switch
-# clock input from Home Assistant used for total daily energy
+# clock input from Home Assistant used to calculate total daily energy
time:
- platform: homeassistant
id: homeassistant_time
-
sensor: # Power monitoring sensors output to Home Assistant
- platform: hlw8012
sel_pin:
@@ -267,7 +259,8 @@ sensor: # Power monitoring sensors output to Home Assistant
change_mode_every: 1
update_interval: 10s # 20 second effective update rate for Power, 40 second for Current and Voltage.
-# Reports the total Power so-far each day, resets at midnight, see https://esphome.io/components/sensor/total_daily_energy.html
+# Reports the total Power so-far each day, resets at midnight
+# See https://esphome.io/components/sensor/total_daily_energy.html
- platform: total_daily_energy
name: ${friendly_name} Total Daily Energy
power_id: wattage
@@ -276,13 +269,13 @@ sensor: # Power monitoring sensors output to Home Assistant
unit_of_measurement: kWh
-number:
+number: # used as a threshold for whether the plugged-in devices is running.
- platform: template
name: ${friendly_name} Use Threshold
min_value: 1
max_value: 100
step: 1
- initial_value: 2
+ initial_value: 3
id: threshold
optimistic: true # required for changing value from home assistant
restore_value: true
@@ -299,7 +292,43 @@ number:
id: in_use
state: OFF
-
+
+select:
+
+ # option to disable button
+ - platform: template
+ name: "Kauf Plug Button"
+ id: select_button
+ optimistic: true
+ options:
+ - Enabled
+ - Disabled
+ initial_option: Enabled
+ restore_value: true
+ icon: mdi:circle-double
+
+
+ # option to disable blue LED
+ - platform: template
+ name: "Kauf Plug LED"
+ id: select_led
+ optimistic: true
+ options:
+ - Enabled
+ - Disabled
+ initial_option: Enabled
+ restore_value: true
+ icon: mdi:led-on
+ on_value:
+ then:
+ - if:
+ condition:
+ lambda: 'return ( (id(select_led).state == "Enabled") && id(relay).state );'
+ then:
+ switch.turn_on: blue_led
+ else:
+ switch.turn_off: blue_led
+
# Send IP Address to HA
text_sensor: