diff options
-rw-r--r-- | kauf-plug-factory.yaml | 69 | ||||
-rw-r--r-- | kauf-plug.yaml | 13 |
2 files changed, 43 insertions, 39 deletions
diff --git a/kauf-plug-factory.yaml b/kauf-plug-factory.yaml index f71129a..3cdf9f3 100644 --- a/kauf-plug-factory.yaml +++ b/kauf-plug-factory.yaml @@ -1,5 +1,6 @@ substitutions: project_ver_let: "f" + select_monitor_mode_initial_option: " 2s P / 8s V,I" packages: @@ -24,45 +25,38 @@ script: # get AP going ASAP - lambda: 'wifi_wificomponent->set_ap_timeout(1);' - # disable button toggling relay - - select.set: - id: select_button - option: "Don't Toggle" - - # turn on relay to draw current + # turn on relay - switch.turn_on: relay - delay: 1s - light.turn_off: blue_led - # wait until button is pressed, then turn on led - - while: - condition: - binary_sensor.is_off: button_in - then: - - light.turn_off: blue_led - - delay: 50ms - - while: - condition: - binary_sensor.is_on: button_in - then: - - light.turn_on: blue_led - - delay: 50ms - - # give it some time to see if a crash occurs with both AP and relay on - - delay: 8s - - # test passed, clear first_boot variable so we don't run this again - - globals.set: - id: first_boot - value: 'false' - - # re-enable button toggling relay - - select.set: - id: select_button - option: "Toggle on Release" - - # delay time to save above changes - - delay: 3s + - delay: 16s + + # ensure all 3 values are reported + - wait_until: + lambda: return(!std::isnan(id(wattage).state) && !std::isnan(id(current).state) && !std::isnan(id(voltage).state)); + + # set scaling factors to expected test load. + # required ranges helps prevent calibration without proper test load. + - lambda: |- + if ( (id(wattage).state > 20) && (id(wattage).state < 33) ) { + auto call = id(scale_power).make_call(); + call.set_value(ceil((10.0f*100.0f*26.800f) / id(wattage).state) / 10.0f); + call.perform(); + } + if ( (id(current).state > 0.05) && (id(current).state < 1.0) ) { + auto call = id(scale_current).make_call(); + call.set_value(ceil((10.0f*100.0f*0.226f) / id(current).state) / 10.0f); + call.perform(); + } + if ( (id(voltage).state > 90) && (id(voltage).state < 150) ) { + auto call = id(scale_voltage).make_call(); + call.set_value(ceil((10.0f*100.0f*120.0f) / id(voltage).state) / 10.0f); + call.perform(); + } + + //test passed, clear first_boot variable so we don't run this again + id(first_boot) = false; # blink blue led to indicate pass test until button is pressed then stay on - while: @@ -72,6 +66,11 @@ script: - light.toggle: blue_led - delay: 100ms + # set power monitoring mode to lower frequency default + - select.set: + id: select_monitor_mode + option: "10s P / 40s V,I" + - lambda: global_preferences->sync(); globals: - id: first_boot # used to run test routine at factory diff --git a/kauf-plug.yaml b/kauf-plug.yaml index 071d140..c32c4c0 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.99" + project_ver_num: "1.991" project_ver_let: y # https://esphome.io/components/switch/gpio.html?highlight=restore_mode @@ -70,6 +70,7 @@ substitutions: sub_change_mode_every: "1" sub_update_interval: 10s sub_initial_mode: CURRENT + select_monitor_mode_initial_option: "10s P / 40s V,I" # GPIO definitions sub_pm_sel_pin: GPIO12 @@ -143,7 +144,7 @@ external_components: - source: type: git url: https://github.com/KaufHA/common - ref: v2022.11.01 + #ref: v2022.11.01 refresh: 0s @@ -322,7 +323,7 @@ script: - 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."); + - lambda: ESP_LOGCONFIG("kauf-plug.yaml","Setting change requiring reboot detected, rebooting in 10 seconds to effect change."); - delay: 10s - button.press: restart_button @@ -832,7 +833,8 @@ select: - " 2s P,I Only" - " 2s P,V Only" - "YAML Configured" - initial_option: "10s P / 40s V,I" + - " 2s P / 8s V,I" + initial_option: $select_monitor_mode_initial_option restore_value: true icon: mdi:wrench-clock entity_category: config @@ -857,6 +859,9 @@ select: 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 / 8s V,I" ) { + id(hlw_main).set_update_interval(2000); + id(hlw_main).set_change_mode_every(1); } else if ( x == " 2s P,I Only" ) { id(hlw_main).set_update_interval(2000); id(hlw_main).set_change_mode_every(4294967295); |