I decided to create a default firmware for my Brilliant energy monitoring smart plugs (353 KB.)
Here’s the YAML configuration I came up with. I’ve included instructions for how to use it (mainly for my own reference, but I thought I may as well share it in case it’s useful.)
You can see it’s a bit complicated, so I hope there’s a nicer way to do this. I’d still be interested to know how ESPHome Web does it.
# This is a default firmware that can be flashed onto Brilliant Smart Plugs to get
# them ready for OTA updates in the future. OTA and API passwords can be set later.
# (We don't set up the AP and captive portal initially because it makes
# the firmware over 512KB, which can't be flashed by tuya-convert.)
#
# Use tuya-convert (or something else) to flash this firmware on the plug.
# Once you know what you want to use the plug for, you can create a new device in ESPHome and flash the new firmware via an OTA update.
#
# Step-by-step instructions for "adopting" a plug that runs this default firmware:
# ------------------------------------------------------------------------------------------------------
#
# 1) Plug the plug into power.
# 2) Ensure it connects to WiFi and can be reached at `default-brilliant-wifi-plug.local`
# 3) Create a new ESP8266 device in ESPHome and open the configuration editor.
# 4) Paste this YAML configuration below the existing configuration.
# 5) Replace `<OTA_PASSWORD>`, `<API_ENCRYPTION_KEY>`, and `<WIFI_AP_PASSWORD>` with the generated values in the original configuration.
# 6) Delete the original configuration
# 7) Uncomment the `on_boot:` lines under `esphome:`
# 8) Uncomment `password: ""` under `ota:` (must be an empty string)
# 9) Uncomment all of the lines below `# Uncomment all of the below`
# 10) Save, and install the new firmware wirelessly. (The `use_address` line under `wifi:` ensures that you use the default hostname.)
# 11) Delete or comment out the `on_boot:` lines under `esphome:`
# 12) Delete or comment out the `password: ""` line under `ota:`, and uncomment `password: "<OTA_PASSWORD>"`
# 13) Uncomment the `encryption:` lines under `api:`
# 14) Uncomment `captive_portal:` and `wifi:` => `ap:`. (You should be able to flash the larger firmware now.)
# 15) Delete or comment out `use_address: "default-brilliant-wifi-plug.local"` under `wifi:`.
# 16) Save and install the firmware wirelessly
# 17) Add the new ESPHome device in Home Assistant. (You'll need to copy/paste the API encryption key.)
substitutions:
devicename: default-brilliant-wifi-plug
friendly_name: Default Brilliant WiFi Plug
esphome:
name: $devicename
# NOTE: You must also uncomment `password: ""` in the OTA section to include the required libraries
# on_boot:
# - lambda: |-
# id(my_ota).set_auth_password("<OTA_PASSWORD>");
esp8266:
board: esp8285
logger:
api:
# encryption:
# key: "<API_ENCRYPTION_KEY>"
ota:
id: my_ota
# password: ""
# password: "<OTA_PASSWORD>"
wifi:
use_address: "default-brilliant-wifi-plug.local"
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
# ap:
# ssid: "Default-Brilliant-Wifi-Plug"
# password: "<WIFI_AP_PASSWORD>"
# captive_portal:
# Uncomment all of the below
# ---------------------------------------------------
# # Enable time component for use by daily power sensor
# time:
# - platform: homeassistant
# id: homeassistant_time
# sensor:
# - platform: uptime
# name: ${friendly_name} Uptime
# filters:
# - lambda: return x / 60.0;
# unit_of_measurement: minutes
# - platform: wifi_signal
# name: "${friendly_name} WiFi Signal"
# update_interval: 300s
# # Reports the Current, Voltage, and Power used by the plugged-in device
# - platform: hlw8012
# sel_pin:
# number: GPIO12
# inverted: true
# cf_pin: GPIO04
# cf1_pin: GPIO05
# change_mode_every: 3
# update_interval: 3s
# power:
# id: power
# name: ${friendly_name} Power
# unit_of_measurement: W
# accuracy_decimals: 0
# current:
# name: ${friendly_name} Current
# unit_of_measurement: A
# accuracy_decimals: 3
# voltage:
# name: ${friendly_name} Voltage
# unit_of_measurement: V
# accuracy_decimals: 1
# # Reports the total Power so-far each day, resets at midnight, see https://esphome.io/components/sensor/total_daily_energy.html
# - platform: total_daily_energy
# name: ${friendly_name} Total Daily Energy
# power_id: power
# filters:
# - multiply: 0.001
# unit_of_measurement: kWh
# binary_sensor:
# - platform: status
# name: ${friendly_name} Status
# # Button on the front is pressed and then toggle relay
# - platform: gpio
# internal: true
# device_class: power
# pin:
# number: GPIO03
# inverted: True
# name: ${friendly_name} Button
# on_press:
# - switch.toggle: relay
# text_sensor:
# # Reports the ESPHome Version with compile date
# - platform: version
# name: ${friendly_name} ESPHome Version
# # Reports detailed wifi info, can be commented out
# # - platform: wifi_info
# # ip_address:
# # name: ${friendly_name} IP Address
# # ssid: # Some additional wifi info that is not normally needed
# # name: ${friendly_name} Connected SSID
# # bssid:
# # name: ${friendly_name} Connected BSSID
# switch:
# # Relay itself
# - platform: gpio
# name: ${friendly_name} Power
# pin: GPIO14
# id: relay
# restore_mode: RESTORE_DEFAULT_OFF #Try to restore relay state after reboot/power-loss event.
# #RESTORE_DEFAULT_OFF (Default) - Attempt to restore state and default to OFF if not possible to restore. Uses flash write cycles.
# #RESTORE_DEFAULT_ON - Attempt to restore state and default to ON. Uses flash write cycles.
# #ALWAYS_OFF - Always initialize the pin as OFF on bootup. Does not use flash write cycles.
# #ALWAYS_ON - Always initialize the pin as ON on bootup. Does not use flash write cycles.
# on_turn_on: # Action when relay is turned on
# - script.execute: led_power_on
# on_turn_off: # Action when relay is turned off
# - script.execute: led_relay_off
# output:
# # Output GPIOs for blue led
# - platform: esp8266_pwm # Blue
# id: "blue_led_output"
# pin:
# number: GPIO013
# inverted: True
# light:
# # RGB light
# - platform: monochromatic
# internal: true
# name: ${friendly_name} Light
# output: "blue_led_output"
# id: "blue_led"
# script:
# - id: led_relay_off # Normal operation when relay is off
# then:
# - light.turn_off:
# id: blue_led
# - id: led_power_on # Normal operation when relay is on
# then:
# - light.turn_on:
# id: blue_led
# brightness: 80%
You can download the firmware here if you need it (353 KB): Dropbox - default-brilliant-wifi-plug.bin - Simplify your life
(We need the “Legacy firmware format” for tuya-convert.)
I just went through the ESP Web process again, and I’d love to know how to get a copy of the firmware they are using here:
Woohoo, I flashed the default firmware on the 6 smart plugs that I bought a while ago. It was very convenient to flash one firmware on all of them, so I don’t have to keep getting out the Raspberry Pi to run tuya-convert. (Which is quite tricky to get working sometimes.) I’m just glad I was able to hack them over WiFi, and didn’t have to open them up and solder some wires. That’s one reason why I love Zigbee devices, since you don’t have to mess around with custom firmware and they just work out of the box. (ESPHome is pretty awesome though!)
Going to finally get my dishwasher, washing machine, and dryer set up in Home Assistant, so I know when they’re running and finished.