Skip to content

Instantly share code, notes, and snippets.

@14roiron
Created December 9, 2023 21:10
Show Gist options
  • Save 14roiron/49c03919034f0eb53969bdfad3a28465 to your computer and use it in GitHub Desktop.
Save 14roiron/49c03919034f0eb53969bdfad3a28465 to your computer and use it in GitHub Desktop.
Esphome for Smartplug Tuya bk7231t with bk7231t
esphome:
name: plug1
friendly_name: plug1
substitutions:
voltage_divider: "894.5060273291349"
current_resistor: "0.001054149274397953"
current_multiply: "0.4499878363475396"
bk72xx:
board: generic-bk7231t-qfn32-tuya
framework:
version: dev
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: !secret key
ota:
password: !secret ota
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Plug1 Fallback Hotspot"
password: "tyo4CneBqcDg"
captive_portal:
web_server:
port: 80
sensor:
- platform: wifi_signal
name: "WiFi Signal Sensor"
update_interval: 60s
- platform: uptime
name: Uptime Sensor
id: uptime_sensor
update_interval: 60s
on_raw_value:
then:
- text_sensor.template.publish:
id: uptime_human
state: !lambda |-
int seconds = round(id(uptime_sensor).raw_state);
int days = seconds / (24 * 3600);
seconds = seconds % (24 * 3600);
int hours = seconds / 3600;
seconds = seconds % 3600;
int minutes = seconds / 60;
seconds = seconds % 60;
return (
(days ? to_string(days) + "d " : "") +
(hours ? to_string(hours) + "h " : "") +
(minutes ? to_string(minutes) + "m " : "") +
(to_string(seconds) + "s")
).c_str();
- platform: hlw8012
model: bk7231t
sel_pin:
number: P24
inverted: true
cf_pin:
number: P7
inverted: true ## <---
cf1_pin:
number: P8
inverted: true ## <---
current_resistor: ${current_resistor}
voltage_divider: ${voltage_divider}
current:
name: "BL0937 Current"
filters:
- multiply: ${current_multiply}
voltage:
name: "BL0937 Voltage"
power:
name: "BL0937 Power"
update_interval: 10s
text_sensor:
- platform: template
name: Uptime Human Readable
id: uptime_human
icon: mdi:clock-start
- platform: wifi_info
ip_address:
name: IP Address
entity_category: diagnostic
binary_sensor:
- platform: status
name: Status
entity_category: diagnostic
- platform: gpio
pin:
number: P11
mode:
input: true
pullup: true
#inverted: true
name: "Power Button"
on_press:
- switch.toggle: relay
switch:
- platform: gpio
# RED
id: led_1
pin:
number: P6
inverted: true
- platform: gpio
name: Switch
pin: P26
id: relay
# Turn off red LED to show blue when turned on
on_turn_on:
- switch.turn_on: led_1
# Turns on the red LED once the plug is turned off
on_turn_off:
- switch.turn_off: led_1
button:
- platform: restart
id: restart_button
name: Restart
entity_category: diagnostic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment