Skip to content

Instantly share code, notes, and snippets.

@zeroping
Created March 20, 2022 17:41
Show Gist options
  • Save zeroping/0fc24fa331c6ea62a5e8a707db6b382e to your computer and use it in GitHub Desktop.
Save zeroping/0fc24fa331c6ea62a5e8a707db6b382e to your computer and use it in GitHub Desktop.
ESPHome template for the AWPL12L dual-outlet energy-monitoring wifi smart plug
#substitutions:
#device_name: awp12l-whatever
## Higher value gives lower watt readout
#current_res: "0.001106"
## Lower value gives lower voltage readout
#voltage_div: "2029"
# device info from here:
# https://templates.blakadder.com/avatar_AWP12L.html
# this block lest you use ESPSense, which is useful for letting the Sense home energy monitor pull power data from the device.
external_components:
# Pull the esphome component in from this GitHub repo
- source: github://cbpowell/ESPSense
components: [ espsense ]
espsense:
# You can define up to 10 "plugs" to report to Sense
# Power value can come from any of the following:
# * A power sensor (in Watts)
# * Calculated from a current sensor (in Amps) and a voltage sensor (in Volts)
# * Calculated from a current sensor (in Amps) and a fixed voltage value
plugs:
- name: ${device_name}
power_sensor: "${device_name}_Wattage"
# current_sensor: some_current_sensor
# voltage_sensor: some_voltage_sensor
# voltage: 120.0
# encrypt: false
# mac_address: 35:4B:91:A1:FE:CC
# end ESPSense block
# actually an esp8266-S3, containing an ESP8266EX and an 8mbit flash
# https://templates.blakadder.com/avatar_AWP12L.html
esphome:
name: ${device_name}
platform: ESP8266
board: esp01_1m
wifi:
logger:
level: WARN
ota:
captive_portal:
api:
reboot_timeout: 24h
web_server:
binary_sensor:
- platform: gpio
pin:
number: GPIO4
inverted: True
name: "${device_name}_button_1"
on_press:
then:
- switch.toggle: "${device_name}_Relay_1"
- platform: gpio
pin:
number: GPIO13
inverted: True
name: "${device_name}_button_2"
on_press:
then:
- switch.toggle: "${device_name}_Relay_2"
sensor:
- platform: hlw8012
model: BL0937
sel_pin:
number: GPIO3
inverted: True
cf_pin: GPIO5
cf1_pin: GPIO14
current_resistor: ${current_res}
voltage_divider: ${voltage_div}
change_mode_every: 3
update_interval: 3s
current:
name: "${device_name}_Amperage"
unit_of_measurement: A
accuracy_decimals: 3
filters:
- calibrate_linear:
- 0.000 -> 0.0
- 5.069 -> 6.69
- or:
- throttle: 240s
- delta: 0.01
voltage:
name: "${device_name}_Voltage"
unit_of_measurement: V
accuracy_decimals: 1
filters:
- or:
- throttle: 240s
- delta: 1.0
power:
name: "${device_name}_Wattage"
unit_of_measurement: W
id: "${device_name}_Wattage"
accuracy_decimals: 0
filters:
- or:
- throttle: 240s
- delta: 1.0
energy:
name: "${device_name} Total Daily Energy"
unit_of_measurement: kWh
accuracy_decimals: 0
filters:
- multiply: 0.001
- or:
- throttle: 240s
- delta: 0.001
device_class: energy
time:
- platform: sntp
id: my_time
light:
#- platform: binary
#name: "${device_name}_Blue_LED" # Blue, both sides
#id: "${device_name}_LED"
#output: led1
- platform: status_led
name: "${device_name}_Blue_LED"
id: "${device_name}_LED"
pin:
number: GPIO0
inverted: True
switch:
- platform: output
name: "Outlet 1" # white, left
output: 'relay1'
id: "${device_name}_Relay_1"
- platform: output
name: "Outlet 2" # white, right
output: 'relay2'
id: "${device_name}_Relay_2"
output:
#- id: led1
#platform: gpio
#pin: GPIO0
- id: relay1
platform: gpio
pin: GPIO15
- id: relay2
platform: gpio
pin: GPIO12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment