aboutsummaryrefslogtreecommitdiffhomepage
path: root/kauf-plug-lite.yaml
diff options
context:
space:
mode:
authorKaufHA <[email protected]>2022-06-25 10:57:05 -0700
committerKaufHA <[email protected]>2022-06-25 10:57:05 -0700
commit814d1b5cab52ee6e9bbb598be7595f4e52965bbc (patch)
treec8945babcef7bcb186a49cafcd8eea72f9824864 /kauf-plug-lite.yaml
parentd3adc553c0ae8b748ef79455152ea0d4144ea9ba (diff)
downloadPLF10-814d1b5cab52ee6e9bbb598be7595f4e52965bbc.tar.gz
PLF10-814d1b5cab52ee6e9bbb598be7595f4e52965bbc.zip
update lite to 1.97
Diffstat (limited to 'kauf-plug-lite.yaml')
-rw-r--r--kauf-plug-lite.yaml233
1 files changed, 101 insertions, 132 deletions
diff --git a/kauf-plug-lite.yaml b/kauf-plug-lite.yaml
index 1c3fe3d..3807828 100644
--- a/kauf-plug-lite.yaml
+++ b/kauf-plug-lite.yaml
@@ -15,7 +15,7 @@ substitutions:
# https://esphome.io/components/esphome.html#esphome-creators-project
project_name: Kauf.PLF10
- project_ver_num: "1.96"
+ project_ver_num: "1.97"
project_ver_let: l
# https://esphome.io/components/switch/gpio.html?highlight=restore_mode
@@ -30,12 +30,15 @@ substitutions:
# * have a delay for the desired hold in the on_press script
# * stop the on_press script in the on_release script
# * place actions in the on_press script after the delay to perform them while still holding the button
- # * place actions in the on_release script, with the condition that the on_press script is not running, to
+ # * place actions in the on_release script, with the condition that the on_press script is not running, to
# 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_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
@@ -81,6 +84,14 @@ globals:
type: int
restore_value: no
initial_value: '0'
+ - id: global_has_debounce
+ type: boolean
+ restore_value: no
+ initial_value: "false"
+ - id: global_has_powermode
+ type: boolean
+ restore_value: no
+ initial_value: "false"
# https://esphome.io/components/esphome.html#adjusting-flash-writes
@@ -96,13 +107,6 @@ esphome:
name: $project_name
version: $project_ver_num($project_ver_let)
- on_boot:
- priority: 700
- then:
- # implementing on_boot function as a script so that any other on_boot automations in other files
- # will execute in parallel and not be blocked by this one.
- - script.execute: on_boot_main
-
# https://esphome.io/components/wifi.html
wifi:
@@ -130,8 +134,7 @@ api:
# https://esphome.io/components/ota.html
ota:
on_error:
- then:
- - button.press: restart_button
+ - button.press: restart_button
# https://esphome.io/components/web_server.html
@@ -140,7 +143,7 @@ web_server:
# https://esphome.io/components/binary_sensor/index.html
-binary_sensor:
+binary_sensor:
# button input toggles relay and thereby power led
# https://esphome.io/components/binary_sensor/gpio.html
@@ -154,29 +157,27 @@ binary_sensor:
pullup: true
inverted: true
on_press:
- then:
- - lambda: |-
- // store time of press and clear duration sensor
- id(global_press_time) = millis();
- id(sensor_press_duration).publish_state(0);
-
- // toggle if configured for toggle on press
- if (id(select_button).state == "Toggle on Press") {
- id(relay).toggle(); }
- - script.execute: $sub_on_press
- - script.execute: script_5s_timer
+ - lambda: |-
+ // store time of press and clear duration sensor
+ id(global_press_time) = millis();
+ id(sensor_press_duration).publish_state(0);
+
+ // toggle if configured for toggle on press
+ if (id(select_button).state == "Toggle on Press") {
+ id(relay).toggle(); }
+ - script.execute: $sub_on_press
+ - script.execute: script_5s_timer
on_release:
- then:
- - lambda: |-
- // set duration sensor
- id(sensor_press_duration).publish_state(millis() - id(global_press_time) + id(number_debounce).state);
-
- // toggle if configured on release and toggle check script is not running.
- if ( (id(select_button).state == "Toggle on Release") && !id($sub_toggle_check).is_running() ) {
- id(relay).toggle();
- }
- - script.execute: $sub_on_release
- - script.stop: script_5s_timer
+ - lambda: |-
+ // set duration sensor
+ id(sensor_press_duration).publish_state(millis() - id(global_press_time) + id(number_debounce).state);
+
+ // toggle if configured on release and toggle check script is not running.
+ if ( (id(select_button).state == "Toggle on Release") && !id($sub_toggle_check).is_running() ) {
+ id(relay).toggle();
+ }
+ - script.execute: $sub_on_release
+ - script.stop: script_5s_timer
# indicates whether plugged-in device is running based on configurable threshold.
# https://esphome.io/components/binary_sensor/template.html
@@ -272,16 +273,12 @@ script:
else:
- script.execute: script_set_power_leds # done with status LED, restore light power status
- - id: script_new_debounce
- mode: restart # only reboot plug once number is static for 10s. changing value again restarts timer.
- then: # only do it if wifi is connected, keeps initial loading of value on boot from causing restart.
- - if:
- condition:
- - wifi.connected
- then:
- - lambda: ESP_LOGD("kauf-plug.yaml","New debounce value detected, rebooting in 10 seconds to effect change.");
- - delay: 10s
- - button.press: restart_button
+ - id: script_setting_reboot
+ mode: restart # only reboot plug settings are static for 10s. Another change restarts timer.
+ then:
+ - lambda: ESP_LOGD("kauf-plug.yaml","Setting change requiring reboot detected, rebooting in 10 seconds to effect change.");
+ - delay: 10s
+ - button.press: restart_button
- id: script_5s_timer
then:
@@ -292,60 +289,6 @@ script:
then:
- lambda: return;
- - id: on_boot_main
- then:
-
- # this on_boot script has to execute after select and number entities are set up, so
- # priority < 800. Adding a check here to make sure all needed entities are set up just
- # in case another yaml file makes on_boot priority higher than 800 the following code
- # will still work right. If on_boot priority becomes <= 600, the code for setting up
- # power monitoring mode won't work because HLW will already be set up before values are
- # changed in this script.
- - wait_until:
- lambda: return (id(select_monitor_mode).has_state() );
-
- - lambda: |-
-
- //////////////////////////////////////////////////////////////////////
- // implement power monitoring mode per select entity
-
- if ( id(select_monitor_mode).state == "10s P / 40s V,I") {
- id(hlw_main).set_update_interval(10000);
- id(hlw_main).set_change_mode_every(1); }
-
- else if ( id(select_monitor_mode).state == "10s P,I Only" ) {
- id(hlw_main).set_update_interval(10000);
- id(hlw_main).set_change_mode_every(4294967295);
- id(hlw_main).set_initial_mode(hlw8012::HLW8012_INITIAL_MODE_CURRENT); }
-
- else if ( id(select_monitor_mode).state == "10s P,V Only" ) {
- id(hlw_main).set_update_interval(10000);
- id(hlw_main).set_change_mode_every(4294967295);
- id(hlw_main).set_initial_mode(hlw8012::HLW8012_INITIAL_MODE_VOLTAGE); }
-
- else if ( id(select_monitor_mode).state == " 2s P,I Only" ) {
- id(hlw_main).set_update_interval(2000);
- id(hlw_main).set_change_mode_every(4294967295);
- id(hlw_main).set_initial_mode(hlw8012::HLW8012_INITIAL_MODE_CURRENT); }
-
- else if ( id(select_monitor_mode).state == " 2s P,V Only" ) {
- id(hlw_main).set_update_interval(2000);
- id(hlw_main).set_change_mode_every(4294967295);
- id(hlw_main).set_initial_mode(hlw8012::HLW8012_INITIAL_MODE_VOLTAGE); }
-
- //////////////////////////////////////////////////////////////////////
- // add a delayed_on filter to the button binary_sensor with time argument from number_debounce.
- // this is placed after settings recovery so that it will take into account recovered setting
- // on first boot. In any case, needs to be after priority 800 so that number_debounce is set up.
-
- binary_sensor::DelayedOnFilter *button_delayedonfilter;
- button_delayedonfilter = new binary_sensor::DelayedOnFilter(id(number_debounce).state);
- button_delayedonfilter->set_component_source("binary_sensor");
- App.register_component(button_delayedonfilter);
- id(button_in).add_filters({button_delayedonfilter});
-
-
-
# pwm outputs for LEDs so they can be dimmed
# https://esphome.io/components/output/esp8266_pwm.html
@@ -392,7 +335,7 @@ light:
# https://esphome.io/components/switch/index.html
-switch:
+switch:
# relay output
# https://esphome.io/components/switch/gpio.html
@@ -404,8 +347,10 @@ switch:
restore_mode: $sub_restore_mode
on_turn_on:
- script.execute: script_set_power_leds
+ - script.execute: $sub_on_turn_on
on_turn_off:
- script.execute: script_set_power_leds
+ - script.execute: $sub_on_turn_off
# https://esphome.io/components/switch/template.html
- platform: template
@@ -455,8 +400,8 @@ sensor: # Power monitoring sensors output to Home Assistant
current_resistor: $current_resistor_val
voltage_divider: $voltage_divider_val
- change_mode_every: $sub_change_mode_every
- update_interval: $sub_update_interval
+ change_mode_every: $sub_change_mode_every
+ update_interval: $sub_update_interval
initial_mode: $sub_initial_mode
power:
@@ -598,8 +543,19 @@ number: # used as a threshold for whether the plugged-in devices is running
unit_of_measurement: "ms"
mode: box
disabled_by_default: $disable_entities
- on_value: # currently, have to reboot plug to apply new delayed_on time
- - script.execute: script_new_debounce
+ set_action: # currently rebooting plug to apply new delayed_on time
+ - script.execute: script_setting_reboot
+ on_value:
+ - lambda: |-
+ // add a delayed_on filter to the button binary_sensor with time argument from number_debounce.
+ if ( !id(global_has_debounce) ) {
+ binary_sensor::DelayedOnFilter *button_delayedonfilter;
+ button_delayedonfilter = new binary_sensor::DelayedOnFilter(id(number_debounce).state);
+ button_delayedonfilter->set_component_source("binary_sensor");
+ App.register_component(button_delayedonfilter);
+ id(button_in).add_filters({button_delayedonfilter});
+ id(global_has_debounce) = true;
+ }
# https://esphome.io/components/select/index.html
# https://esphome.io/components/select/template.html
@@ -634,13 +590,12 @@ select:
restore_value: true
icon: mdi:led-on
on_value:
- then:
- - if:
- condition:
- - lambda: return ( x == "Error Status" );
- then:
- - light.turn_off: blue_led
- - script.execute: script_set_power_leds
+ - if:
+ condition:
+ - lambda: return ( x == "Error Status" );
+ then:
+ - light.turn_off: blue_led
+ - script.execute: script_set_power_leds
- platform: template
name: $friendly_name Red LED Config
@@ -658,13 +613,12 @@ select:
restore_value: true
icon: mdi:led-on
on_value:
- then:
- - if:
- condition:
- - lambda: return ( x == "Error Status" );
- then:
- - light.turn_off: red_led
- - script.execute: script_set_power_leds
+ - if:
+ condition:
+ - lambda: return ( x == "Error Status" );
+ then:
+ - light.turn_off: red_led
+ - script.execute: script_set_power_leds
# change mode of power monitoring
- platform: template
@@ -684,10 +638,31 @@ select:
entity_category: config
disabled_by_default: $disable_entities
set_action:
- - delay: 1s
- - lambda: global_preferences->sync();
- - delay: 2s
- - button.press: restart_button
+ - script.execute: script_setting_reboot
+ on_value:
+ - lambda: |-
+ if ( !id(global_has_powermode) ) {
+ if ( x == "10s P / 40s V,I") {
+ id(hlw_main).set_update_interval(10000);
+ id(hlw_main).set_change_mode_every(1); }
+ else if ( x == "10s P,I Only" ) {
+ id(hlw_main).set_update_interval(10000);
+ id(hlw_main).set_change_mode_every(4294967295);
+ id(hlw_main).set_initial_mode(hlw8012::HLW8012_INITIAL_MODE_CURRENT); }
+ else if ( x == "10s P,V Only" ) {
+ id(hlw_main).set_update_interval(10000);
+ id(hlw_main).set_change_mode_every(4294967295);
+ id(hlw_main).set_initial_mode(hlw8012::HLW8012_INITIAL_MODE_VOLTAGE); }
+ else if ( x == " 2s P,I Only" ) {
+ id(hlw_main).set_update_interval(2000);
+ id(hlw_main).set_change_mode_every(4294967295);
+ id(hlw_main).set_initial_mode(hlw8012::HLW8012_INITIAL_MODE_CURRENT); }
+ else if ( x == " 2s P,V Only" ) {
+ id(hlw_main).set_update_interval(2000);
+ id(hlw_main).set_change_mode_every(4294967295);
+ id(hlw_main).set_initial_mode(hlw8012::HLW8012_INITIAL_MODE_VOLTAGE); }
+ id(global_has_powermode) = true;
+ }
# Send IP Address to HA
@@ -704,14 +679,8 @@ text_sensor:
interval:
- interval: 5s
then:
- - if:
- condition:
- - lambda: return ( ( (App.get_app_state() & STATUS_LED_ERROR) != 0u) || ((App.get_app_state() & STATUS_LED_WARNING) != 0u) );
- then:
- - if:
- condition:
- not:
- - script.is_running: blink_status_led
- then:
- - script.execute: blink_status_led
-
+ - lambda: |-
+ if ( ( ((App.get_app_state() & STATUS_LED_ERROR ) != 0u) ||
+ ((App.get_app_state() & STATUS_LED_WARNING) != 0u) )
+ && !id(blink_status_led).is_running() )
+ id(blink_status_led).execute();