From db8c3f3aa0626cf8f753c8ae713594950a03b314 Mon Sep 17 00:00:00 2001 From: James Swift Date: Fri, 13 May 2022 23:04:58 +0000 Subject: [PATCH] v1.2.0 use template number instead of template sensor. --- README.md | 8 +++- localbytes-plug-pm-v2.yaml | 85 ++++++++++++++++++++++++-------------- 2 files changed, 59 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 8921f4d..c70d314 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,14 @@ This is an ESPHome firmware for the Localbytes Smart plug (V2), which is sold pr # Installation -To flash the ESPHome firmware over tasmota, first flash the `minimal` firmware using the tasmota web interface (as the full firmware is too big to fit in the free space left by tasmota). Then, connect to the hotspot the device creates and flash the latest full `localbytes-plug-pm-v2` firmware. +To flash the ESPHome firmware over tasmota, first flash the `minimal` firmware using the tasmota web interface (as the full firmware is too big to fit in the free space left by tasmota). Then, connect to the hotspot and enter your wifi details. + +At this point you can use the "dashboard import" feature of esphome to take ownership of the device. The next time you hit install/update via the dashboard, the full firmware will be uploaded to the plug. + +Alternatively, if you don't want to import the plug to your ESPHome dashboard, connect to the hotpsot the device creates and use the web UI to flash the full `localbytes-plug-pm-v2` firmware from the latest release. # Calibration Once you have flashed the new firmware onto your smart plug and connected it to home assistant, you may wish to calibrate your plug to improve it's accuracy. To calibrate your plug, you need another "known-good" smart plug or a calibration device. -Plug your new smart plug into the know good smart plug, then plug a kettle, toaster, or other high-power device into it. From home assistant, go to `Developer Tools` > `Services`. Use the services `calibrate_current`, `calibrate_power`, and `calibrate_voltage` to report the real readings as given from the "known-good" device. (Don't forget to turn on the kettle/toaster before starting to take readings). \ No newline at end of file +Plug your new smart plug into the known-good smart plug, then plug a kettle, toaster, or other high-power appliance into it. From home assistant, go to `Developer Tools` > `Services`. Use the services `calibrate_current`, `calibrate_power`, and `calibrate_voltage` to report the real readings as given from the "known-good" device. (Don't forget to turn on the kettle/toaster and leave it to stabalise it's power usage for a minute before starting to copy the readings). \ No newline at end of file diff --git a/localbytes-plug-pm-v2.yaml b/localbytes-plug-pm-v2.yaml index 482fda4..df4b81e 100644 --- a/localbytes-plug-pm-v2.yaml +++ b/localbytes-plug-pm-v2.yaml @@ -12,9 +12,6 @@ substitutions: # Options: `RESTORE_DEFAULT_OFF`, `RESTORE_DEFAULT_ON`, `ALWAYS_ON` & `ALWAYS_OFF` default_state: "RESTORE_DEFAULT_OFF" - # Activity State Threshold - # Threshold (number) that the device will change from `Idle` to `Active` if power is greater than or equal to - activity_threshold: "5" esphome: name: "${name}" @@ -26,7 +23,7 @@ esphome: # configuration and updates. project: name: localbytes.plug-pm-v2 - version: "1.1.3" + version: "1.2.0" esp8266: board: esp01_1m @@ -59,22 +56,31 @@ api: variables: actual_value: float then: - lambda: |- - id(voltage_multiply) = actual_value / id(voltage).raw_state; + - lambda: |- + id(voltage_multiply) = actual_value / id(voltage).raw_state; + - number.set: + id: voltage_factor + value: !lambda "return id(voltage_multiply);" - service: calibrate_power variables: actual_value: float then: - lambda: |- - id(power_multiply) = actual_value / id(power).raw_state; + - lambda: |- + id(power_multiply) = actual_value / id(power).raw_state; + - number.set: + id: power_factor + value: !lambda "return id(power_multiply);" - service: calibrate_current variables: actual_value: float then: - lambda: |- - id(current_multiply) = actual_value / id(current).raw_state; + - lambda: |- + id(current_multiply) = actual_value / id(current).raw_state; + - number.set: + id: current_factor + value: !lambda "return id(current_multiply);" globals: - id: voltage_multiply @@ -173,41 +179,56 @@ sensor: - multiply: 0.001 unit_of_measurement: kWh - # Make calibration data readable + + +# Make calibration factor data readable/setable from home assistant +number: - platform: template - name: "${friendly_name} Voltage Calibration" + name: "${friendly_name} Voltage Calibration Factor" + id: voltage_factor + icon: "mdi:sine-wave" + min_value: 0 + max_value: 10 + step: 0.001 entity_category: diagnostic - accuracy_decimals: 3 + mode: box lambda: |- return id(voltage_multiply); - + set_action: + lambda: |- + id(voltage_multiply) = x; + - platform: template - name: "${friendly_name} Power Calibration" + name: "${friendly_name} Power Calibration Factor" + id: power_factor + icon: "mdi:flash" + min_value: 0 + max_value: 10 + step: 0.001 entity_category: diagnostic - accuracy_decimals: 3 + mode: box lambda: |- return id(power_multiply); - + set_action: + lambda: |- + id(power_multiply) = x; + - platform: template - name: "${friendly_name} Current Calibration" + name: "${friendly_name} Current Calibration Factor" + id: current_factor + icon: "mdi:current-ac" + min_value: 0 + max_value: 10 + step: 0.001 entity_category: diagnostic - accuracy_decimals: 3 + mode: box lambda: |- return id(current_multiply); + set_action: + lambda: |- + id(current_multiply) = x; + -text_sensor: - # Device Activity State - # e.g. shows as active if power reading above a certain threshold - - platform: template - name: "${friendly_name} Activity State" - icon: "mdi:${main_icon}" - lambda: |- - if (id(power).state >= $activity_threshold) { - return {"Active"}; - } else { - return {"Idle"}; - } - update_interval: 5s # Relay State LED output: