Kickstart-bk7231t to ESPHome add-on

I already have several Arlec Grid Connect PC191HA series 1 Smart Power Plugs with Energy Monitoring which I added to ESPHome’s HA Add-on through several stages back when LibreTiny was the way to go. I believe that a lot of the steps I went through then should no longer be required.

I purchased a batch of Arlec grid Connect PC191HA series 2, and am trying to get them into HA’s ESPHome add-on in the most straight-forward manner.

  • Breakdown by tonyb62 shows the “Series 2” is a CB2S version (BK7231N). He states he chose “the device by firmware version - 1.1.8 - BK7231N / oem_bk7231n_plug”
  • tuya-cloudcutter gives Arlec device options “PC191HA Smart Plug BK7231N v1.1.8” and "PC191HA Smart Plug BK7231T v1.3.5
  • According to the Grid Connect phone app, my v2 units have 1.3.5 firmware.

Curiously tuya-cloudcutter lists only one firmware version 1.3.5 - BK7231T / oem_bk7231s_dltj.

I reinstalled tuya-cloudcutter (to ensure latest version), and used it to upload the ESPhome kickstart firmware

sudo ./tuya-cloudcutter.sh -r -f ESPHome-Kickstart-v23.08.29_bk7231t_app.ota.ug.bin -p arlec-pc191ha-smart-plug-bk7231t-v1.3.5

OK, I have got a device on my WLAN with kickstart-bk7231t firmware, and it is detected in the HA Integrations page.
How to get it from here into the HA ESPHome add-ons panel ? and able to install my full configuration yaml ?

From memory when I went through the workflow I got the Discovered / Adopt prompt. I think…?

https://www.google.com/search?sca_esv=8b94fdf9c54254b4&rlz=1C1CHBF_en-GBAU859AU859&sxsrf=ACQVn09BW5CqrZxEq_ya3tSqyZktbIFo8A:1710036901096&q=esphome+adopt&tbm=isch&source=lnms&sa=X&ved=2ahUKEwicrKvwz-iEAxXS0KACHSfXDR0Q0pQJegQIDxAB&biw=1920&bih=919&dpr=1

Or maybe I created a basic yaml file in the right place and just OTA’d that over the top of it with the right ip name and address etc.

https://upk.libretiny.eu/?profile=arlec-pc191ha-smart-plug-bk7231n-v1.1.8

So… Not sure.

Not an answer, but some notes so far…

  1. ESP devices configured in HA’s Settings > Integrations DO NOT transfer over to the ESPHome add-on. They can transfer the other way, but better to get sorted out in ESPHome add-on first to avoid creating squillions of badly-named entities.

  2. There is no straightforward way to add a Beken device in the ESPHome Addon. Apparently ESPHome project haven’t got the memo yet that LibreTiny has been merged into ESPHome, because any hint of Beken and they tell you to go to LibreTiny github … whose instructions are now out of date.

  3. I found 2 ways to create a new device in ESPHome add-on:

  • manually create a yaml file in HA’s /homeassistant/esphome folder (eg by using the File Editor or SSH add-on)

-or-

  • create a new device, choosing any of the wrong but supported device types, but skip the Encryption key. Then edit the device yaml and replace it totally with one for your new device
1 Like

Did you do anything special to flash those with 1.3.5? I have 8, 4 with 1.1.8, and 4 with 1.3.5. I had no issues with 1.1.8, but didnt get any of the 1.3.5 units to flash.

I tried sudo ./tuya-cloudcutter.sh -r -f ESPHome-Kickstart-v23.08.29_bk7231t_app.ota.ug.bin -p arlec-pc191ha-smart-plug-bk7231t-v1.3.5 but it ends with [!] The profile you selected did not result in a successful exploit.

The two firmware versions are for different chips which have different pinouts !

I found some advice online which said that series 2 PC191HA units use the CB2S chip (BK7231N - note the trailing N); compared to the series 1 which uses the WB2S chip (BK7231T).

However the v2 units I purchased are using the same firmware as my earlier v1 units; which implies they are still using the WB2S chip. Go figure !

PC191HA Smart Plug BK7231N chip uses firmware v1.1.8
PC191HA Smart Plug BK7231T chip uses firmware v1.3.5

Did you have any success flashing the ones with v1.3.5? I tried both options and neither worked for me

When you say “flashing”, do you mean updating the built-in firmware; or just installing an ESPHome configuration ?

The first isn’t necessary, as they are already the latest firmwares for the chips used.

As for installing an ESPHome configuration … yes. The only issue I have had is that after installing the update it usually comes back online still using the previous configuration - ie it looks as though the update didn’t work. Repeating the ESPHome install gives the same result.

In fact the update did get loaded into the PC191HA, but it just didn’t activate. I usually have to power off the PC191HA device (sometimes only for a couple of minutes, but sometimes for much longer) and when powered back on there should be a delay (while it activates the new ESPHome configuration) before the LED starts flashing (indicating it is connecting to wi-fi).

This behaviour seems common with the PC191HA; though I have seen a few reports of it on other devices.

Once you have openbeken on the device you should see it on your lan. You then connect to this and upload your new firmware. Then it will be seen in HA. I just recovered a bricked devise and flashed a new one over the weekend. Not PC191HA’s but same process. This is my procedure for TUYA devices if it helps;

1\ Launch Libretuya ESPHome, http://192.168.1.105:6052/

2\ Go +New Device, Continue, enter a name, select LibreTuya, and select board type.

3\ We now have a basic YAML file. It’s highly recommended to always include the web_server
and captive_portal components - even in your first “empty” upload. “use_address” will
be used later. For initial config I enter the actual ssid & pword.

# Enable web server
web_server:
  port: 80

# Enable Home Assistant API
api:

ota:
  safe_mode: true

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: true
  power_save_mode: none
  manual_ip:
    static_ip: !secret ip_antbms1
    gateway: !secret ip_gateway
    subnet: !secret ip_subnet
    dns1: !secret ip_dns1
  #use_address: 192.168.1.28

  # Enable fallback hotspot in case wifi connection fails
  ap: {} # This spawns an AP with the device name and mac address, no password.
    #ssid: "Power-Switch1 AP"
    #password: "password"

captive_portal:

4\ Save the yaml and close. Using the 3 dots, select Install, Manual download, and select Modern Format.
This will save the binaries on the RPi.

5\ Connect to the RPi using WinSCP. Navigate to the root and then opt folder. Do a search for *ug.bin and
then Focus on the result to enter the folder. Drag the required *ug.bin file to the local desktop and rename
to something meaningful. Navigate back to “/home/janos-pi/tuya-cloudcutter/custom-firmware” and drag the
bin file into this folder.

6\ SSH into the RPi and navigate to “/home/janos-pi/tuya-cloudcutter”.

7\ We first need to cut the device from Tuya cloud using tuya-cloudcutter.
-execute sudo ./tuya-cloudcutter.sh -s ssid pword -w wlan0
follow the prompts until completion. Device will now be local.
-execute sudo ./tuya-cloudcutter.sh -w wlan0 -f esphome.bin (or whatever the bin filename is)
follow the prompts until completion. Device will now have custom firmware loaded.

8\ If it fails for whatever reason and doesn’t connect to local network then it should create its own
Access Point. Use the phone to connect to this AP and load http://192.168.4.1/. From here your
can reenter WiFi credentials and/or load new firmware.

9\ If it works then the device will connect to local network and be discovered by ESPHome.

10\ To do any updates requires the Libretuya ESPHome fork. To upload just rem out the use_address line
and enter the actual IP address allocated to the device. Will compile and upload as per std ESPHome.

11\ I have soft bricked some devices so will need to try,
https://www.youtube.com/watch?v=YQdR7r6lXRY&list=PLzbXEc2ebpH0CZDbczAXT94BuSGrd_GoM

12\ I managed to soft brick a device but recovered using a USB to TTL adaptor.

  • Solder leads to the Tuya pins 3v3, gnd, tx, and rx. Connect to adaptor through a breadboard.
  • Download BK7231Flasher.exe and follow instructions in the video above.
  • It’s tricky but you need to get the Tuya into flash mode. This is done by shorting CEN pin to gnd.
    This did not work and while I was swapping the tx & rx cables it suddenly connected. I found it
    generally connected while disconnecting the +ve power while it was trying to connect.
  • It should then backup the current firmware, erase, and write new firmware.
  • Use the phone to connect to this AP and load http://192.168.4.1/. From here your can re-enter
    WiFi credentials and/or load new firmware. Another option is to use WiFiman to find the device. Scan
    the ports and connect to port 80.
  • You can now disconnect from the usb adaptor.
  • The device will now have OpenBeken so it now needs to be converted to esphome.
  • When the yaml file was compiled in step 4 it also created a file called “bk7231n_app.ota.rbl” or
    whatever our device was. Grab this rbl file from build directory (note: without “UG” in the name!),
    rename it to something like OpenBK7231N_esphome.rbl. Programme checks for BK7231N/T in the name.
    Change T to N depending on the chip type, and drop it on the OTA panel. This is inside the WEB Application.
  • Disconnect from usb adaptor, power up, and check that all is working ok in Home Assistant. If all good
    then reassemble and it’s done.