-
Notifications
You must be signed in to change notification settings - Fork 16
BN Link Power Monitoring Plug
15A, 1875W rating - but don't use it for anywhere near this much, as the plug is NOT UL listed (though it does say it "conforms to" a UL standard)
Note this configuration uses substitution, for some variables and for the ESPHome !secrets (requires a secrets.yaml
file in the ESPHome directory). Or you can just replace the secret callouts with your values.
The current_res
and voltage_div
values were calibrated using a Kill-a-Watt. The KaW was placed between the plug and the wall, with the load attached to the plug. A 90W bulb was used as a steady resistive load. Individual plugs will have variation on these values, and they can be adjusted as needed. Alternatively the calibrate_linear
ESPHome filter can be used to further improve the calibration using multiple data points.
Configuration file, reproduced below. Note below may be out of date to the repo configuration file, but is provided for reference:
# Configuration for BN-Link BNC-60/U133TJ
substitutions:
plug_name: bnlink_01
# Plug state to set upon powerup (or after power loss)
# See options here: https://esphome.io/components/switch/gpio.html
restore_mode: ALWAYS_ON
# Base calibration to 90W lightbulb, Kill-a-Watt between plug and wall
# Detail calibration can be done with calibrate_linear sensor filters below
current_res: "0.00243"
voltage_div: "755"
# Increasing current_res reduces reported wattage
# Increasing voltage_div increases reported voltage
esphome:
name: ${plug_name}
platform: ESP8266
board: esp01_1m
includes:
- espsense.h
# Uses the ESPAsyncUDP library
libraries:
- "ESPAsyncUDP"
- "[email protected]"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_pass
fast_connect: on
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "${plug_name} Fallback Hotspot"
password: !secret ap_pass
ota:
safe_mode: True
password: !secret ota_pass
captive_portal:
# Enable logging
logger:
# level: DEBUG
baud_rate: 0 # Disable UART logging, we have no physical connections!
# Home Assistant API
# Comment out if not using API, but you'll also need to remove the total_daily_energy and
# time sensors below
api:
time:
- platform: homeassistant
id: homeassistant_time
binary_sensor:
- platform: gpio
pin:
number: GPIO3
inverted: True
name: "${plug_name} Button"
on_press:
then:
- switch.toggle: "relay"
switch:
# Main plug control relay
- platform: gpio
name: "${plug_name} Relay"
id: "relay"
pin: GPIO14
restore_mode: ${restore_mode}
# Use blue LED to indicate relay state
on_turn_on:
- switch.turn_on: "led_blue"
on_turn_off:
- switch.turn_off: "led_blue"
- platform: gpio
name: "${plug_name} LED Blue"
id: "led_blue"
pin: GPIO13
inverted: True
restore_mode: ${restore_mode} # Matches relay
# Red LED used for ESPHome status below, but this could be
# reconfigured for other purposes!
# - platform: gpio
# name: "${plug_name} LED Red"
# id: "led_red"
# pin: GPIO1
# inverted: True
# restore_mode: ALWAYS_OFF
status_led:
# Use Red LED as ESPHome's built-in status indicator
pin:
number: GPIO1
inverted: True
sensor:
- platform: hlw8012
sel_pin:
number: GPIO12
inverted: True
cf_pin: GPIO4
cf1_pin: GPIO5
current_resistor: ${current_res}
voltage_divider: ${voltage_div}
current:
name: "${plug_name} Amperage"
unit_of_measurement: A
filters:
# - calibrate_linear:
# # Map X (from sensor) to Y (true value)
# # At least 2 data points required
# - 0.0 -> 0.0
# - 1.0 -> 1.0 #load was on
voltage:
name: "${plug_name} Voltage"
unit_of_measurement: V
filters:
# - calibrate_linear:
# # Map X (from sensor) to Y (true value)
# # At least 2 data points required
# - 0.0 -> 0.0
# - 1.0 -> 1.0 #load was on
power:
id: "wattage"
name: "${plug_name} Wattage"
unit_of_measurement: W
filters:
# - calibrate_linear:
# # Map X (from sensor) to Y (true value)
# # At least 2 data points required
# - 0.0 -> 0.0
# - 1.0 -> 1.0 #load was on
change_mode_every: 8
update_interval: 3s # Longer interval gives better accuracy
- platform: total_daily_energy
name: "${plug_name} Total Daily Energy"
power_id: "wattage"
filters:
# Multiplication factor from W to kW is 0.001
- multiply: 0.001
unit_of_measurement: kWh
# Extra sensor to keep track of plug uptime
- platform: uptime
name: ${plug_name} Uptime Sensor
custom_component:
- lambda: |-
auto sensor_power = new ESPSense(id(wattage), 120);
return {sensor_power};