Detailed guide on how to flash the new Tuya Beken Chips with OpenBK7231T

I don’t think it does. I am not sure if the hardware is capable of monitoring engergy (I could be wrong). I have not tried to do this even with ESP based Deta switches. Tasmota does not show anything about Energy monitoring in its templates for Deta Switches.

I am not as familiar with the Deta switches on Tasmota. I’ve used a lot of the Makegood GPOs which do support it. I was going off the specs from the Bunnings Website so I assumed there was a sensor on one of the GPIOs.

Good day. I believe you added this review ?

Can you share the pinout for serial flashing?

Thank you

It’s the same as wb3s

1 Like

Does anyone have a working configuration for ESPHome for PC191HA smart plug?
I flashed it to ESPhome and can update and all, but cannot get the GPIO pins to do anything =(
So far I found the following:
P6 (PWM0) - RELAY
P7 (PWM1) - CF
P8 (PWM2) - CF1
P24 (PWM4) - SEL
P26 (PWM5) - LED
P11 (TXD1) - BUTTON
P10 (RXD1) - WIFI LED

I’ve just got a window opener with a Tuya switch.



I’d like to use it without the cloud and would normally flash with Tasmota and link into HA. I think (?) this one is not compatible with Tasmota and came across this thread as a possible alternative.
Can anyone provide some confirmation before I set off on a new adventure?

Yes, that’s a beken chip so you can flash with openbeken/libretuya

I had a similar switch design like yours, swapped with an esp12.
Had to heat the chip from other side of the board to avoid melting the touchpad since it’s right next to it.

1 Like

Flashed it now. Was tricky. Had to cut the track coming from the TX1 and RX1 pads as they interfered with programming and I struggled bridging the cut after with solder alone on one of them.
I couldn’t flash it with BKWriterV1.60 but eventually managed it with hid_download_py.
Trying to configure it now but new to OpenBeken!

1 Like

Great outcome! Configuring can be a trial and error. Please post the final pin configs when you get it working.

I’ve had great success flashing Deta 6951HA 2 way switch using Libretiny / Libre tuya and tuya-cloudcutter.
Libretiny has a ESPHOME branch that allows flashing / integration into ESPHOME (branch) and Home assistant.

This can be done OTA, no soldering needed.
After flashing works just like esphome / home assistant

I installed Libretiny and Tuya-cloudcutter into docker containers running Ubuntu onto an old laptop.
(needs to have wifi)

There are lots of tutorials etc for installing these.
The guides to flashing are a bit confusing.

My tips for these:
First we need to discover Firmware/MCU versions.
I installed “Smart Life” app on android phone.
Put device into discovery mode (fast flash) from it’s instruction manual.
Usually hold button for 5 seconds or turn off and on 3 times.
Add device in Smart Life app.
Once discovered go to settings / firmware update (I don’t have exact detail).

  • DONT UPDATE- We are just looking for firmware versions.
    For Deta 6951HA 2 way switch - MAIN is V1.1.5 / MCU is 1.1.5.
    This is a WB3S chip.

I found updating based on “By manufacturer/device name” option in cloud-cutter is inaccurate:
My method is safe as it will error out if device type is wrong:
Confirm device type:
Use tuya-cloudcutter:

  • Select option 1:
  1. Detach from the cloud and run Tuya firmware locally
    Fill in WIFI details:
    Select option 2:

By firmware version and name
Scroll down to devices matching MCU version.
(Bit of trial and error here)
The devices available for me:
1.1.5 - BK7231N / oem_bk7231n_control_switch
1.1.5 - BK7231N / oem_bk7231n_strip_ty
1.1.5 - BK7231T / oem_bk7231s_4_speed_controller
1.1.5 - BK7231T / oem_bk7231s_rnd_zero_dctrl_switch

First option didn’t work.
Finally found:
1.1.5 - BK7231T / oem_bk7231s_4_speed_controller
[?] Select the brand of your device: Lonsonho

Lonsonho
Rabit
Tuya Generic

[?] Select the article number of your device: X801A 1-Gang Switch

X801A 1-Gang Switch
X802A-L 2-Gang Switch
X804A 4 Gang Smart Wifi Switch

Follow the instruction in cloudcutter.
If you device is successfully cut from the cloud, You can burn it in ESPhome

The guides are a bit vauge here as well.
Basically you create a yaml file for your device and manually download.
This creates a OTA UG file in a hidden directory on your ESPHome docker.
For me the path was:
/opt/esphome/.esphome/build/masterbed-bed-sw/.pioenvs/masterbed-bed-sw

We need the bin filename with “ota” and “ug”
For me: bk7231t_app.ota.ug.bin

Rename this file and copy to cloudcutter custom directory.
for me:
/root/tuya-cloudcutter/custom-firmware

Now rerun cloud-cutter selecting option2:
2) Flash 3rd Party Firmware
[?] Select your custom firmware file: masterbed-bed-sw.ota.ug.bin

Select device type from working type - you discovered above.
Follow prompts and flash device.

Device will be available / discoverable in esphome branch and home assistant.

My yaml for this 2 way switch (3 way for Americans :slight_smile: ):

substitutions:
  device_name: masterbedbedsw
  friendly_name: "masterbedbedsw"
  device_ip: 192.168.1.128

esphome:
  name: ${device_name}
  friendly_name: ${friendly_name}

libretuya:
  board: wb3s
  framework:
    version: dev

# Enable logging
logger:


# Enable Home Assistant API
api:
  encryption:
    key: "key="

ota:
  password: "password"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip: 
    static_ip: ${device_ip}
    gateway: 192.168.1.1
    subnet: 255.255.255.0


  # Enable fallback hotspot in case wifi connection fails
  ap:
    ssid: "Masterbed-bed-Sw"
    password: "password"

# The web_server & sensor components can be removed without affecting core functionality.
web_server:
  port: 80

sensor:
  - platform: wifi_signal
    name: ${device_name} Wifi Signal Strength
    update_interval: 60s
  - platform: uptime
    name: ${device_name} Uptime

#status_led:
#  pin:
#    number: GPIO4
#    inverted: true
script:
  - id: toggle_short_script
    mode: restart     # Light will be kept on during 10 minute since
                      # the latest time the script is executed
    then:
     - script.execute: pwdr_light_script

  - id: pwdr_light_script
    mode: restart     # Light will be kept on during 10 minute since
                      # the latest time the script is executed
    then:
      - light.turn_on: pwdr_light
      - delay: 30 min
      - light.turn_off: pwdr_light

  - id: button_press_script
    mode: restart     # Light will be kept on during 10 minute since
                      # the latest time the script is executed
    then:
      - light.toggle: pwdr_light
# P24 - status led
# P14 - relay
# P26 - Local button
# P9 - Remote button
# P8 - power status (inverted)
output:
  # status led
  - platform: gpio
    pin: P24
    id: relay0
    inverted: true
    
  # Top (or only) button
  - platform: gpio
    pin: P14
    id: relay1


light:

  # status Led
  - platform: binary
    name: "${friendly_name} status_led"
    output: relay0
    id: status
    
  # Top (or only) button
  - platform: binary
    name: "${friendly_name} light"
    output: relay1
    id: pwdr_light
    on_turn_on:
     - script.execute: toggle_short_script
   

# Buttons
binary_sensor:
  # Top (or only) button
  - platform: gpio
    pin:
      number: P26
      mode: INPUT_PULLUP
      inverted: True
    filters:
    - delayed_on: 10ms  
    name: "${friendly_name} Button"
    #toggle relay on push
    on_press:
     - script.execute: button_press_script

  # Top (or only) button
  - platform: gpio
    pin:
      number: P9
      mode: INPUT_PULLUP
      inverted: True
    name: "${friendly_name} Button"
    #toggle relay on push
    on_press:
     - script.execute: button_press_script

  - platform: gpio
    pin:
      number: P8
      mode: INPUT_PULLUP
      inverted: true  
    name: "Power status 8"

  

switch:
  - platform: restart
    name: "${friendly_name} REBOOT"      
2 Likes

I tried this with the same unit, but the CEN pin on mine seems to be hardwired to 3.3V. Shorting the pin to ground just shorts out the power supply. And I even made a pogo-pin jig to put it in :frowning:

I verified with multimeter that there is zero ohms between CE (pin 1) on the module and VCC.

I might try the SPI route and see if I have more luck.

Have you tried cloudcutter?
Unless your tuya firmware version for that device has already patched it

I did try cloudcutter, and it was able to “cut” the device, but not flash the firmware. The specific device wasn’t in the cloudcutter list, and the closest one I could fine (same firmware version, same brand, different model number) didn’t work.

I tried the UART bootloader again, using the CLI flasher but using a power cycle instead of shorting CEN to reset. This worked fine!

The image I flashed was a Libretiny/ESPHome image I built with this config. It was immediately found by HA and everything seems to work perfectly.

2 Likes

My code for Deta 6920ha - Dual Outlet with usb and power monitoring:
Could flash image using cloud-cutter:
1.1.4 - BK7231T / oem_bk7231s_dltj_2switch_alerc

substitutions:
  device_name: detaexternalpowerpoint1
  friendly_name: "detaexternalpowerpoint1"
  device_ip: 192.168.1.136

esphome:
  name: ${device_name}
  friendly_name: ${friendly_name}

libretiny:
  board: wb2s
  framework:
    version: dev

# Enable logging
logger:
#  level: DEBUG
#  baud_rate: 0

# Enable Home Assistant API
api:
  encryption:
    key: "kBlv1/mhIBwr/u2G9oOKuD9J84UwuYg4jlYd6Ah5+JM="

ota:
  password: "68551e62859ce4b609efbca9fe64c3e7"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  #use_address: 192.168.1.21 
  manual_ip:
    static_ip: !secret ip_detaexternalpowerpoint1
    gateway: !secret ip_gateway
    subnet: !secret ip_subnet
    dns1: !secret ip_dns1

  # Enable fallback hotspot in case wifi connection fails
  ap:
    ssid: "Detapowerpoint1 Fallback Hotspot"
    password: "2cPTGnFgXXD2"


# Enable time component for use by daily power sensor
time:
  - platform: homeassistant
    id: homeassistant_time

uart:
  rx_pin: P10
  baud_rate: 4800

sensor:
  - platform: uptime
    name: ${friendly_name} Uptime
    filters:
      - lambda: return x / 60.0;
    unit_of_measurement: minutes

  - platform: wifi_signal
    name: ${friendly_name} Signal
    update_interval: 300s

#HLW8032
  - platform: cse7766
    update_interval: 15s
    current:
      name: "${friendly_name} Current"
      icon: mdi:current-ac
      filters:
        - multiply: 1.021884
        - sliding_window_moving_average:
            window_size: 10
            send_every: 10
            send_first_at: 1
    voltage:
      name: "${friendly_name} Voltage"
      icon: mdi:flash
      filters:
        - multiply: 1.925
        - sliding_window_moving_average:
           window_size: 10
           send_every: 10
           send_first_at: 1      

    power:
      name: "${friendly_name} Power"
      icon: mdi:gauge
      id: ${friendly_name}_wattage
      filters:
        - multiply: 1.9375          
        - sliding_window_moving_average:
            window_size: 10
            send_every: 10
            send_first_at: 1

    energy:
      name: "${friendly_name} energy"
      icon: mdi:gauge
      id: ${friendly_name}_energy
      filters:
#        - multiply: 1.9375  
        - sliding_window_moving_average:
            window_size: 10
            send_every: 10
            send_first_at: 1

  - platform: total_daily_energy
    name: "${friendly_name} Daily Energy"
    power_id: ${friendly_name}_wattage
    filters:
      - multiply: 0.001
    unit_of_measurement: kWh
    icon: mdi:chart-bar

# Buttons
binary_sensor:
  # Left button
  - platform: gpio
    device_class: power
    pin:
      number: P7
      mode:
        input: true
        pullup: true
      inverted: true
    name: "${friendly_name} Left Button"
    filters:
      - delayed_on: 10ms
    on_press:
      - switch.toggle: relay_a
      - if:
          condition:
            and:
              - switch.is_off: relay_a
              - switch.is_off: relay_b
          then:
            - switch.turn_on: led_switch
          #else:
          # - switch.turn_on: led_switch    

  # Right button
  - platform: gpio
    device_class: power
    pin:
      number: P24 #D6
      mode:
        input: true
        pullup: true
      inverted: true
    name: "${friendly_name} Right Button"
    filters:
      - delayed_on: 10ms
    on_press:
      - switch.toggle: relay_b
      - if:
          condition:
            or:
              - switch.is_on: relay_a
              - switch.is_on: relay_b
          then:
            - switch.turn_off: led_switch
          #else:
          # - switch.turn_on: led_switch      
          

switch:
  - platform: gpio
    pin: P8
    name: "${friendly_name} - LED"
    restore_mode: restore_default_on
    id: led_switch
    inverted: true
    icon: mdi:led-variant-on
    on_turn_on:
      - if:
          condition:
            or:
              - switch.is_on: relay_a
              - switch.is_on: relay_b
          then:
            - switch.turn_off: led_switch
    on_turn_off:
      - if:
          condition:
            or:
              - switch.is_on: relay_a
              - switch.is_on: relay_b
          then:
            - switch.turn_off: led_switch


  - platform: gpio
    pin: P6
    name: "${friendly_name} - A"
    restore_mode: restore_default_off
    id: relay_a
    inverted: false
    icon: mdi:power-socket-au
    on_turn_on:
      - if:
          condition:
            switch.is_on: led_switch
          then:
            - switch.turn_off: led_switch
          #else:
          # - switch.turn_off: led_switch  
    on_turn_off:
      - if:
          condition:
            and:
              - switch.is_off: relay_a
              - switch.is_off: relay_b
          then:
            - switch.turn_off: led_switch
          else:
           - switch.turn_off: led_switch             


  - platform: gpio
    pin: P26 #D7
    name: "${friendly_name} - B"
    restore_mode: restore_default_off
    id: relay_b
    inverted: false
    icon: mdi:power-socket-au
    on_turn_on:
      - if:
          condition:
            switch.is_on: led_switch
          then:
            - switch.turn_off: led_switch
          #else:
          # - switch.turn_off: led_switch 
    on_turn_off:
      - if:
          condition:
            and:
              - switch.is_off: relay_a
              - switch.is_off: relay_b
          then:
            - switch.turn_on: led_switch
          #else:
          # - switch.turn_off: led_switch 


  - platform: restart
    name: "${friendly_name} REBOOT"

What entities does the switch expose natively to Home Assistant?

With Tasmota capable switches, I’ve had to create MQTT entities in configuration.yaml for multi-way operation to work

After initial discovery, pretty much everything that’s programmed in.
I get Button status, Relay status, Led status, wifi signal strength, all power stuff that’s configured.
I started with tasmota, but found esphome more capable. Tasmota seems really good for standalone devices, where you go directly to the device to do stuff.
Esphome is a bit harder to set devices up. Needs bit more knowledge of hardware / yaml. But once it’s done, its very powerful. I try to program most things onto the switch.
NB: The switch above is a true 2-way switch from Bunnings.

The Device is auto-discovered in HA as well as entities.

Thanks.

I’m familiar with both Tasmota and ESPHome but had only used Tasmota for multiway switches and found the configuration fiddly, especially for use in automation.

Tasmota shows one entity for the state of the switch and another for the state of the circuit to Tasmota and it looks like the ESPHome YAML takes care of merging those underlying states into a single entity.

Hi @umesh59,
just to clarify (in case you didn’t realise), the new 6920ha is a true 2 way switch. The switching/ wiring is done in hardware the same as an analogue 2-way switch would. It has terminals etc for connecting traveler wires between switches.

Thanks for the guide @pencilhead - the clearest I have come across.

I am trying to use Cloudcutter to flash a Deta 6294HA Outdoor Powerpoint. I might be being daft here but I couldnt see where in the Smart Life app to see the MCU version - I go to update in the menu and it says update available 1.1.4 but not the current version. Any suggestions would be very helpful