diff options
author | Kaufman Home Automation <[email protected]> | 2022-05-10 13:50:57 -0700 |
---|---|---|
committer | GitHub <[email protected]> | 2022-05-10 13:50:57 -0700 |
commit | 5a0decc79b32f198f80faf7e54f2fa78cd0c13c1 (patch) | |
tree | ad0b0aa9600f7f55479dc005d8cbd0421523bdd7 | |
parent | 7cb14609196b7cc082163ec55f39be9132e506e5 (diff) | |
download | PLF10-5a0decc79b32f198f80faf7e54f2fa78cd0c13c1.tar.gz PLF10-5a0decc79b32f198f80faf7e54f2fa78cd0c13c1.zip |
v1.95
-rw-r--r-- | kauf-plug-lite.yaml | 140 |
1 files changed, 113 insertions, 27 deletions
diff --git a/kauf-plug-lite.yaml b/kauf-plug-lite.yaml index 8c25806..037faa9 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.911" + project_ver_num: "1.95" project_ver_let: l # https://esphome.io/components/switch/gpio.html?highlight=restore_mode @@ -24,17 +24,25 @@ substitutions: disable_entities: "true" # set to "false" to have all entities show up in Home Assistant automatically - # substitutions for button actions. yaml dashboard import uses press, but update bin file uses hold_short to allow hold_long - # to turn on wifi ap. These substitutions can be overwritten in the user's yaml file to do anything. - sub_on_press: script_toggle # executes right when button is initially pressed - sub_on_release: script_do_nothing # executes right when button is released - sub_on_release_quick: script_do_nothing # executes when button is released after being held under 750ms - sub_on_release_short: script_do_nothing # executes when button is released after being held between 750ms and 5s - # For a longer hold, see kauf-plug-update.yaml in the config-update directory. - # You have to start a timer in the on_press script and cancel the timer in the on_release script. - # or if you wanted to require release, then start a counter on press and check the value on release. - # If you want to have a hold action, you probably want to toggle on release_quick instead of on_press so that - # you can perform the hold action without toggling the plug's relay. + # 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. + # 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 + # * 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 + # perform them on release of the button. + sub_on_press: script_start_timer # executes right when button is initially pressed + sub_on_release: script_stop_timer # 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_release_quick: script_do_nothing # executes when button is released after being held under 750ms + sub_on_release_short: script_do_nothing # executes when button is released after being held between 750ms and 5s + sub_on_release_long: script_do_nothing # executes when button is released after being held between 5s and 60s + + # 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_start_timer # substitutions for power monitoring calibration. Allows end users to change calibration in their yaml and still @@ -181,6 +189,10 @@ binary_sensor: max_length: 5s then: - script.execute: $sub_on_release_short + - min_length: 5s + max_length: 60s + then: + - script.execute: $sub_on_release_long # indicates whether plugged-in device is running based on configurable threshold. # https://esphome.io/components/binary_sensor/template.html @@ -203,7 +215,7 @@ script: if ( (id(select_bled).state == "Power Status") || (id(select_bled).state == "Error and Power") ) { call.set_state(id(relay).state); } - + // blue invert power status else if ( (id(select_bled).state == "Invert Power Status") || (id(select_bled).state == "Error and Invert Power") ) { call.set_state(!id(relay).state); @@ -212,14 +224,13 @@ script: call.perform(); - call = id(red_led).make_call(); // red power status if ( (id(select_rled).state == "Power Status") || (id(select_rled).state == "Error and Power") ) { call.set_state(id(relay).state); } - + // red invert power status else if ( (id(select_rled).state == "Invert Power Status") || (id(select_rled).state == "Error and Invert Power") ) { call.set_state(!id(relay).state); @@ -272,7 +283,7 @@ script: call.set_save(false); call.perform(); } - + - delay: 1150ms - if: @@ -286,16 +297,76 @@ script: ############################################################################ # scripts for different things the button can do: # - # * toggle # + # * start timer (on press) # + # * stop timer (on release) # # * nothing # ############################################################################ - - id: script_toggle + - id: script_start_timer then: + + # store press time in ms + - lambda: id(global_press_time) = millis(); + + - script.execute: script_5s_timer + + # variable delay before toggling plug + - delay: !lambda |- + if ( id(select_button).state == "Toggle if Pressed For 20ms" ) + return 20; + else if ( id(select_button).state == "Toggle if Released After 20ms" ) + return 20; + else if ( id(select_button).state == "Toggle if Pressed For 100ms" ) + return 100; + else if ( id(select_button).state == "Toggle if Released After 100ms" ) + return 100; + else if ( id(select_button).state == "Toggle if Pressed For 250ms" ) + return 250; + else if ( id(select_button).state == "Toggle if Released After 250ms" ) + return 250; + else + return 1000; + + # toggle immediately after delay if a "pressed" option is selected - if: - condition: # only toggle relay if button is enabled - lambda: return (id(select_button).state == "Enabled"); + condition: + lambda: |- + std::size_t found = id(select_button).state.find("Press"); + return (found != std::string::npos); then: - switch.toggle: relay + - switch.toggle: relay + + - id: script_stop_timer + then: + + # set duration sensor + - lambda: id(sensor_press_duration).publish_state(millis() - id(global_press_time)); + + - if: + condition: # potentially toggle if a "released" option is selected + lambda: |- + std::size_t found = id(select_button).state.find("Release"); + return (found != std::string::npos); + then: + + - if: + condition: + or: # do nothing if timer is still running or toggle check script is running. + - script.is_running: script_start_timer + - script.is_running: $sub_toggle_check + then: + - script.execute: script_do_nothing + else: # otherwise toggle relay + - switch.toggle: relay + + # in all cases, stop timers on button release. + - script.stop: script_5s_timer + - script.stop: script_start_timer + + + - id: script_5s_timer + then: + - delay: 5s + - script.execute: $sub_on_hold_5s - id: script_do_nothing then: @@ -475,6 +546,14 @@ sensor: # Power monitoring sensors output to Home Assistant entity_category: diagnostic disabled_by_default: $disable_entities + - platform: template + name: $friendly_name Button Press Duration + id: sensor_press_duration + entity_category: diagnostic + disabled_by_default: $disable_entities + unit_of_measurement: ms + icon: mdi:timer-outline + # https://esphome.io/components/number/index.html # https://esphome.io/components/number/template.html @@ -560,19 +639,26 @@ select: # option to disable button - platform: template - name: $friendly_name Button + name: $friendly_name Button Config id: select_button optimistic: true options: - - Enabled - - Disabled - initial_option: Enabled + - Toggle if Pressed For 20ms + - Disable Button + - Toggle if Pressed For 100ms + - Toggle if Pressed For 250ms + - Toggle if Pressed For 1s + - Toggle if Released After 20ms + - Toggle if Released After 100ms + - Toggle if Released After 250ms + - Toggle if Released After 1s + initial_option: Toggle if Pressed For 100ms restore_value: true icon: mdi:circle-double entity_category: config - platform: template - name: $friendly_name Blue LED + name: $friendly_name Blue LED Config id: select_bled optimistic: true entity_category: config @@ -596,7 +682,7 @@ select: - script.execute: script_set_power_leds - platform: template - name: $friendly_name Red LED + name: $friendly_name Red LED Config id: select_rled optimistic: true entity_category: config |