diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | kauf-plug-factory.yaml | 9 | ||||
-rw-r--r-- | kauf-plug-update.yaml | 72 | ||||
-rw-r--r-- | kauf-plug.yaml | 61 |
4 files changed, 61 insertions, 82 deletions
@@ -4,5 +4,6 @@ dev-common secrets.yaml kauf-plug-test.yaml kauf-plug-test-2.yaml +kauf-plug-test-3.yaml kauf-plug-old.yaml kauf-plug-dev.yaml diff --git a/kauf-plug-factory.yaml b/kauf-plug-factory.yaml index 3934683..f71129a 100644 --- a/kauf-plug-factory.yaml +++ b/kauf-plug-factory.yaml @@ -9,7 +9,12 @@ packages: esphome: on_boot: then: + - script.execute: script_factory_test + +script: + - id: script_factory_test + then: # little sequence so factory can confirm firwmare is working. - if: condition: @@ -69,7 +74,7 @@ esphome: globals: - - id: first_boot # used to run routine at factory to confirm - type: bool # correct firmware is running. + - id: first_boot # used to run test routine at factory + type: bool restore_value: yes initial_value: 'true' diff --git a/kauf-plug-update.yaml b/kauf-plug-update.yaml index 30ed5a9..1a03ce0 100644 --- a/kauf-plug-update.yaml +++ b/kauf-plug-update.yaml @@ -1,10 +1,5 @@ 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" @@ -18,78 +13,13 @@ dashboard_import: 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 - - -globals: - - id: force_ap - type: bool - restore_value: yes - initial_value: "true" -# re-adding wifi component so that hotspot will be enabled +# re-adding wifi component to get forced hash 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); diff --git a/kauf-plug.yaml b/kauf-plug.yaml index 47ef5ab..277ef55 100644 --- a/kauf-plug.yaml +++ b/kauf-plug.yaml @@ -15,7 +15,7 @@ substitutions: # https://esphome.io/components/esphome.html#esphome-creators-project project_name: Kauf.PLF10 - project_ver_num: "1.973" + project_ver_num: "1.98" project_ver_let: y # https://esphome.io/components/switch/gpio.html?highlight=restore_mode @@ -24,7 +24,7 @@ substitutions: disable_entities: "true" # set to "false" to have all entities show up in Home Assistant automatically # substitutions for button actions. on_press and on_release implement a timer scheme with configurable delay. - # on_hold_5s re-enables the AP and captive portal for the precompiled update binary. + # on_hold_30s re-enables the AP and captive portal for the precompiled update binary. # any length of hold can be implemented with just on_press and on_release using the following directions. This # is basically how this yaml file works. # * have a delay for the desired hold in the on_press script @@ -34,14 +34,14 @@ substitutions: # perform them on release of the button. sub_on_press: script_do_nothing # executes right when button is initially pressed sub_on_release: script_do_nothing # executes right when button is released - sub_on_hold_5s: script_do_nothing # executes right when button has been held for 5s, while button is still being held + sub_on_hold_30s: script_force_ap # executes right when button has been held for 5s, while button is still being held sub_on_turn_on: script_do_nothing sub_on_turn_off: script_do_nothing # an extra script that, if running, will stop the relay from toggling on button release. # used to not toggle when WiFi AP is re-enabled on update bin file. - sub_toggle_check: script_do_nothing + sub_toggle_check: script_force_ap # made this a substitution so that the update bin file and yaml compiled versions can have different defaults default_button_config: "Toggle on Press" @@ -130,6 +130,12 @@ esphome: name: $project_name version: $project_ver_num($project_ver_let) + on_boot: + then: + # implementing on_boot automation as a script makes it run in parallel + # with any other on_boot scripts. + - script.execute: on_wifi_connect + # https://esphome.io/components/external_components.html external_components: @@ -150,10 +156,17 @@ wifi: # using fast_connect as default since it is required for hidden networks. fast_connect: true + # enable wifi ap with ridiculous timeout so it does not normally turn on. + ap: + ap_timeout: 2147483647ms # maximum 32 bit value. About 3.5 weeks in milliseconds. + forced_addr: 8 global_addr: global_forced_addr +captive_portal: # for fallback wifi hotspot + + # https://esphome.io/components/logger.html logger: @@ -198,7 +211,7 @@ binary_sensor: if (id(select_button).state == "Toggle on Press") { id(relay).toggle(); } - script.execute: $sub_on_press - - script.execute: script_5s_timer + - script.execute: script_30s_timer on_release: - lambda: |- // set duration sensor @@ -209,7 +222,7 @@ binary_sensor: id(relay).toggle(); } - script.execute: $sub_on_release - - script.stop: script_5s_timer + - script.stop: script_30s_timer # indicates whether plugged-in device is running based on configurable threshold. # https://esphome.io/components/binary_sensor/template.html @@ -311,10 +324,40 @@ script: - delay: 10s - button.press: restart_button - - id: script_5s_timer + - id: script_30s_timer + then: + - delay: !lambda return (30000-id(number_debounce).state); + - script.execute: $sub_on_hold_30s + + - id: on_wifi_connect + then: + + # wait until wifi connects + - wait_until: wifi.connected + + - lambda: |- + ESP_LOGD("KAUF on_boot","------------------->>>>>>>>>>>>>>>>> wifi connected, cranking ap timeout back up"); + wifi_wificomponent->set_ap_timeout(2147483647); + + - id: script_force_ap + then: + - logger.log: "------------------->>>>>>>>>>>>>>>>> HELD BUTTON 30 SECONDS, FORCING AP" + + # overwrite software defined credentials to force ap to turn on. + - lambda: wifi::global_wifi_component->save_wifi_sta("initial_ap","asdfasdfasdfasdf"); + + # blink LED for 10s then restart to get captive portal to turn on. + - 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: - - delay: !lambda return (5000-id(number_debounce).state); - - script.execute: $sub_on_hold_5s + - light.toggle: blue_led + - delay: 333ms + - script.execute: blink_led - id: script_do_nothing then: |