Skip to content

Commit

Permalink
v1.2.0 use template number instead of template sensor.
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesSwift committed May 13, 2022
1 parent 8165880 commit db8c3f3
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 34 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
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).
85 changes: 53 additions & 32 deletions localbytes-plug-pm-v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit db8c3f3

Please sign in to comment.