diff options
author | Kaufman Home Automation <[email protected]> | 2022-04-01 22:51:12 -0700 |
---|---|---|
committer | GitHub <[email protected]> | 2022-04-01 22:51:12 -0700 |
commit | 158d7b2dd906b4380f994115708b3555671f547a (patch) | |
tree | 06ec113c9abf74a87a66f02cfae6a77e9b768624 | |
parent | 4d18b1ae3cd7f12e3358edfeed7777e1bc0eb3cb (diff) | |
download | PLF10-158d7b2dd906b4380f994115708b3555671f547a.tar.gz PLF10-158d7b2dd906b4380f994115708b3555671f547a.zip |
update lite yaml for 1.90
-rw-r--r-- | kauf-plug-lite.yaml | 174 |
1 files changed, 159 insertions, 15 deletions
diff --git a/kauf-plug-lite.yaml b/kauf-plug-lite.yaml index 9be9245..18623a7 100644 --- a/kauf-plug-lite.yaml +++ b/kauf-plug-lite.yaml @@ -5,7 +5,7 @@ substitutions: friendly_name: Kauf Plug # **** CHANGE FRIENDLY NAME TO SOMETHING UNIQUE PER DEVICE **** - sub_restore_mode: "RESTORE_DEFAULT_OFF" # overwrite to change boot up behavior of relay + sub_restore_mode: RESTORE_DEFAULT_OFF # overwrite to change boot up behavior of relay disable_entities: "true" # set to "false" to have all entities show up in Home Assistant automatically @@ -39,6 +39,11 @@ substitutions: voltage_cal_val2_in: "302.1" voltage_cal_val2_out: "117.1" + # set power monitoring mode in yaml https://esphome.io/components/sensor/hlw8012.html#configuration-variables + sub_change_mode_every: "1" + sub_update_interval: 10s + sub_initial_mode: CURRENT + esp8266: # https://esphome.io/components/esp8266.html board: esp01_1m @@ -53,7 +58,15 @@ esphome: name: $name project: name: "Kauf.PLF10" - version: "1.87(l)" + version: "1.90(l)" + + on_boot: + priority: 700 + then: + # priority 700 ensures power monitoring mode variables are changed + # in this script before HLW component is setup + - script.execute: script_set_monitor_mode + wifi: @@ -105,14 +118,13 @@ web_server: # web server allows access to device with # password: !secret web_server_password - # red led, blink when not connected to WiFi or Home Assistant status_led: pin: number: GPIO0 inverted: true - + binary_sensor: # button input toggles relay and thereby blue led @@ -140,18 +152,18 @@ binary_sensor: then: - script.execute: $sub_on_release_short - # indicates whether plugged-in device is running based on configurable threshold. - platform: template id: in_use name: ${friendly_name} Device In Use + script: - id: script_toggle then: - if: condition: # only toggle relay if button is enabled - lambda: 'return (id(select_button).state == "Enabled");' + lambda: return (id(select_button).state == "Enabled"); then: switch.toggle: relay - id: script_do_nothing @@ -169,6 +181,35 @@ script: id(kauf_api)->set_reboot_timeout(900000); } + - id: script_set_monitor_mode + then: + - lambda: |- + + 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); + } + output: - platform: esp8266_pwm @@ -206,16 +247,26 @@ switch: on_turn_on: - if: condition: # only if blue LED enabled - lambda: 'return (id(select_led).state == "Enabled");' + lambda: return (id(select_led).state == "Enabled"); then: light.turn_on: blue_led + - if: + condition: # only if blue LED enabled + lambda: return (id(select_led).state == "Inverted"); + then: + light.turn_off: blue_led on_turn_off: - if: condition: # only if blue LED enabled - lambda: 'return (id(select_led).state == "Enabled");' + lambda: return (id(select_led).state == "Enabled"); then: light.turn_off: blue_led + - if: + condition: # only if blue LED enabled + lambda: return (id(select_led).state == "Inverted"); + then: + light.turn_on: blue_led - platform: template id: switch_no_hass @@ -230,6 +281,7 @@ switch: on_turn_off: - script.execute: script_no_hass + button: - platform: restart id: restart_button @@ -246,6 +298,7 @@ time: sensor: # Power monitoring sensors output to Home Assistant - platform: hlw8012 + id: hlw_main sel_pin: number: GPIO12 inverted: True @@ -253,6 +306,11 @@ sensor: # Power monitoring sensors output to Home Assistant cf1_pin: GPIO14 current_resistor: $current_resistor_val # The value of the shunt resistor for current measurement. voltage_divider: $voltage_divider_val # The value of the voltage divider on the board as (R_upstream + R_downstream) / R_downstream. + + change_mode_every: $sub_change_mode_every + update_interval: $sub_update_interval + initial_mode: $sub_initial_mode + power: name: ${friendly_name} Power unit_of_measurement: W @@ -261,10 +319,11 @@ sensor: # Power monitoring sensors output to Home Assistant - calibrate_linear: - $power_cal_val1_in -> $power_cal_val1_out - $power_cal_val2_in -> $power_cal_val2_out + - lambda: return x * id(scale_power).state/100.0f; on_value: # set or clear in_use template binary sensor depending on whether power usage is over threshold - if: condition: - lambda: 'return (x >= id(threshold).state);' + lambda: return (x >= id(threshold).state); then: - binary_sensor.template.publish: id: in_use @@ -273,22 +332,27 @@ sensor: # Power monitoring sensors output to Home Assistant - binary_sensor.template.publish: id: in_use state: OFF + current: name: ${friendly_name} Current unit_of_measurement: A + id: current filters: - calibrate_linear: - $current_cal_val1_in -> $current_cal_val1_out - $current_cal_val2_in -> $current_cal_val2_out + - lambda: return x * id(scale_current).state/100.0f; + voltage: name: ${friendly_name} Voltage unit_of_measurement: V + id: voltage filters: - calibrate_linear: - $voltage_cal_val1_in -> $voltage_cal_val1_out - $voltage_cal_val2_in -> $voltage_cal_val2_out - change_mode_every: 1 - update_interval: 10s # 20 second effective update rate for Power, 40 second for Current and Voltage. + - lambda: return x * id(scale_voltage).state/100.0f; + # Reports the total Power so-far each day, resets at midnight # See https://esphome.io/components/sensor/total_daily_energy.html @@ -298,6 +362,7 @@ sensor: # Power monitoring sensors output to Home Assistant filters: - multiply: 0.001 ## convert Wh to kWh unit_of_measurement: kWh + min_save_interval: 5min - platform: uptime @@ -316,14 +381,15 @@ number: # used as a threshold for whether the plugged-in devices is running initial_value: 3 id: threshold entity_category: config - optimistic: true # required for changing value from home assistant + optimistic: true restore_value: true unit_of_measurement: Watt(s) mode: box + disabled_by_default: $disable_entities on_value: - if: # set or clear in_use template binary sensor depending on whether power usage is above threshold condition: - lambda: 'return (id(wattage).state >= x);' + lambda: return (id(wattage).state >= x); then: - binary_sensor.template.publish: id: in_use @@ -333,6 +399,54 @@ number: # used as a threshold for whether the plugged-in devices is running id: in_use state: OFF + - platform: template + name: ${friendly_name} Scale Power + min_value: 50 + max_value: 200 + step: .1 + initial_value: 100 + id: scale_power + entity_category: config + optimistic: true + restore_value: true + unit_of_measurement: "%" + mode: box + disabled_by_default: $disable_entities + on_value: + - lambda: id(wattage)->publish_state(id(wattage)->get_raw_state()); + + - platform: template + name: ${friendly_name} Scale Current + min_value: 50 + max_value: 200 + step: .1 + initial_value: 100 + id: scale_current + entity_category: config + optimistic: true + restore_value: true + unit_of_measurement: "%" + mode: box + disabled_by_default: $disable_entities + on_value: + - lambda: id(current)->publish_state(id(current)->get_raw_state()); + + - platform: template + name: ${friendly_name} Scale Voltage + min_value: 50 + max_value: 200 + step: .1 + initial_value: 100 + id: scale_voltage + entity_category: config + optimistic: true + restore_value: true + unit_of_measurement: "%" + mode: box + disabled_by_default: $disable_entities + on_value: + - lambda: id(voltage)->publish_state(id(voltage)->get_raw_state()); + select: @@ -358,20 +472,50 @@ select: options: - Enabled - Disabled + - Inverted initial_option: Enabled restore_value: true icon: mdi:led-on on_value: then: # changing to "disabled" will turn off LED, but then relay will not turn on or off LED. - - if: # when "disabled", LED is 100% controlled by light entity. + - if: # when "Disabled", LED is initially turned off but then 100% controlled by light entity. condition: - lambda: 'return ( (id(select_led).state == "Enabled") && id(relay).state );' + lambda: |- + if ( id(select_led).state == "Enabled" ) { return id(relay).state; } + else if ( id(select_led).state == "Inverted" ) { return !id(relay).state; } + else /* id(select_led).state == "Disabled" */ { return false; } + then: light.turn_on: blue_led else: light.turn_off: blue_led + # change mode of power monitoring + - platform: template + name: $friendly_name Monitoring Mode + id: select_monitor_mode + optimistic: true + options: + - "10s P / 40s V,I" + - "10s P,I Only" + - "10s P,V Only" + - " 2s P,I Only" + - " 2s P,V Only" + - "YAML Configured" + initial_option: "10s P / 40s V,I" + restore_value: true + icon: mdi:wrench-clock + entity_category: config + disabled_by_default: $disable_entities + + set_action: + - delay: 1s + - lambda: global_preferences->sync(); + - delay: 1s + - button.press: restart_button + + # Send IP Address to HA text_sensor: - platform: wifi_info |