-
Notifications
You must be signed in to change notification settings - Fork 16
TOPGREENER TGWF115PQM
10A, UL listed, low profile (does not obscure other socket)
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 TGWF115PQM (Small 10A plug)
substitutions:
plug_name: topgreener_pqm
# 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.0019"
voltage_div: "2150"
# 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"
- "ArduinoJson-esphomelib@5.13.3"
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"
# Note that blue LED appears to be tied to relay state internally (i.e. electrically)
switch:
# Main plug control relay
- platform: gpio
name: "${plug_name} Relay"
id: "relay"
pin: GPIO14
restore_mode: ${restore_mode}
# Used for Status LED below, but could be repurposed!
# - platform: gpio
# name: "${plug_name} Green LED"
# id: "led_green"
# pin: GPIO13
# restore_mode: ALWAYS_ON
status_led:
# Use Green LED as ESPHome's built-in status indicator
pin:
number: GPIO13
inverted: False
sensor:
- platform: hlw8012
sel_pin:
number: GPIO12
inverted: True
cf_pin: GPIO04
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:
# Moving average filter to try and reduce a periodic drop of ~1-2W
# Unsure of cause, may be a better solution!
- sliding_window_moving_average:
window_size: 2
send_every: 1
# - 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};