logo elektroda
logo elektroda
X
logo elektroda

Configuring AliExpress 16A USB Socket with CB2S (BK7321N) and Tuya JSON Code

mihcc 1791 3

TL;DR

  • An AliExpress 16A USB socket with a CB2S module and BK7231N chip is mapped, with a slightly different pinout and three relays.
  • Tuya extraction assigns relay channels to P7, P24, and P26, with the pair/toggle-all button on P10 and the Wi‑Fi LED on P8.
  • The Tuya section starts at 2023424, and the OpenBeken template targets BK7231N with pins 7, 8, 10, 24, and 26.
  • OpenBeken still has issues: the blue LED behaves like a button, Btn Toggle All is missing in the web GUI, and relay state after Wi‑Fi reconnect is unresolved.
Generated by the language model.
ADVERTISEMENT
📢 Listen (AI):
  • Hi,

    Recently I have bought this socket https://www.aliexpress.com/item/1005005583141499.html?spm=a2g0o.order_list.order_list_main.88.26e8180268ZrMC which is similar to https://www.elektroda.com/rtvforum/topic3892473.html#20014441 with some differences. Pinout is slightly different and has 3 relays.

    Device configuration, as extracted from Tuya:
    - Relay (channel 3) on P7
    - Pair/Toggle All Button on P10
    - WiFi LED on P8
    - Relay (channel 2) on P24
    - Relay (channel 1) on P26
    Device seems to be using CB2S module, which is using BK7231N.
    And the Tuya section starts, as usual, at 2023424

    This is json code:
    {
    	"rl1_lv":"1",
    	"bt_type":"0",
    	"rl3_pin":"7",
    	"rl3_lv":"1",
    	"net_trig":"2",
    	"jv":"1.0.0",
    	"netled1_lv":"0",
    	"netled_reuse":"0",
    	"total_bt_pin":"10",
    	"nety_led":"1",
    	"total_stat":"2",
    	"reset_t":"5",
    	"netled1_pin":"8",
    	"rl2_lv":"1",
    	"module":"CB2S",
    	"ch_cddpid1":"9",
    	"rl2_pin":"24",
    	"ch_cddpid2":"10",
    	"ch_cddpid3":"11",
    	"total_bt_lv":"0",
    	"ch_num":"3",
    	"rl1_pin":"26",
    	"ch_dpid3":"3",
    	"netn_led":"0",
    	"ch_dpid1":"1",
    	"ch_dpid2":"2",
    	"crc":"59",
    	"}4 &Agw_di{abi":"0",
    	"id":"null",
    	"swv":"1.1.15",
    	"bv":"40.00",
    	"pv":"2.2",
    	"lpv":"3.4",
    	"pk":"keyjup78v54myhan",
    	"firmk":"keyjup78v54myhan",
    	"cadv":"1.0.5",
    	"cdv":"1.0.0",
    	"dev_swv":"1.1.15",
    	"s_id":"null",
    	"dtp":"0",
    	"sync":"0",
    	"attr_num":"1",
    	"mst_tp_0":"9",
    	"mst_ver_0":"1.1.15",
    	"mst_md5_0":"null",
    	"mst_tp_1":"0",
    	"mst_ver_1":"null",
    	"mst_md5_1":"null",
    	"mst_tp_2":"0",
    	"mst_ver_2":"null",
    	"mst_md5_2":"null",
    	"mst_tp_3":"0",
    	"mst_ver_3":"null",
    	"mst_md5_3":"null }0Atls_ca_cnt0 .MAgw_wsm{nc_tp",
    	"ssid":"null",
    	"passwd":"null",
    	"md":"0",
    	"random":"0",
    	"wfb64":"1",
    	"stat":"0",
    	"token":"null",
    	"region":"null",
    	"reg_key":"null",
    	"dns_prio":"0 }{uuid",
    	"psk_key":"tIifVCRMFEUE4LGN5crm9kUb2D248mljvhK09",
    	"auth_key":"TaMAFMiYg6zqkGivWBaiI85WxIH9GeQx",
    	"ap_ssid":"SmartLife",
    	"ap_passwd":"null",
    	"country_code":"null",
    	"bt_mac":"null",
    	"bt_hid":"null",
    	"prod_test":"false",
    	"fac_pin":"xjibhmsjf3hqrbcc }3Awf_start_mdll",
    	"lckey":"null",
    	"h_url":"null",
    	"h_ip":"null",
    	"hs_url":"null",
    	"hs_ip":"null",
    	"hs_psk":"null",
    	"hs_psk_ip":"null",
    	"mqs_url":"null",
    	"mqs_ip":"null",
    	"mq_url":"null",
    	"mq_ip":"null",
    	"ai_sp":"null",
    	"ai_sp_ip":"null",
    	"mq_psk":"null",
    	"mq_psk_ip":"null",
    	"lp_url":"null",
    	"lp_ip":"null",
    	"time_z":"null",
    	"s_time_z":"null",
    	"wx_app_id":"null",
    	"wx_uuid":"null",
    	"dy_tls_m":"0",
    	"cloud_cap":"0",
    	"psk21_key":"null }ok5A0000038zlb[{type",
    	"mode":"rw",
    	"property":"{type",
    	"{type":"obj",
    	"max":"86400",
    	"scale":"0",
    	"step":"1",
    	"type":"value}",
    	"maxlen":"255}",
    	"index":"0}@Amf_test_closetrueDNMAgw_ai{key",
    	"m3nc_tp":"0"
    }


    OpenBeken template:
    {
      "vendor": "Tuya",
      "bDetailed": "0",
      "name": "Full Device Name Here",
      "model": "enter short model name here",
      "chip": "BK7231N",
      "board": "TODO",
      "flags": "0",
      "keywords": [
        "TODO",
        "TODO",
        "TODO"
      ],
      "pins": {
        "7": "Rel;3",
        "8": "LED;0",
        "10": "Btn_Tgl_All;0",
        "24": "Rel;2",
        "26": "Rel;1"
      },
      "command": "",
      "image": "https://obrazki.elektroda.pl/YOUR_IMAGE.jpg",
      "wiki": "https://www.elektroda.com/rtvforum/topic_YOUR_TOPIC.html"
    }


    And some pictures
    Close-up of a green circuit board with a CB2S module and capacitors.
    Image of the inside of a smart socket with visible PCB and electronic components.
    White electrical outlet with two USB ports and a power button.
    White Wi-Fi Smart Socket with model and specification label.
    Close-up view of an electronic device's printed circuit board.
    Close-up of a circuit board with electronic components, including relays and a module.

    Added after 18 [minutes]:

    Because I am new with openbeken I'am seeking some help.
    I don't know if I'm doing something wrong:
    1. It appears that LED light shows as Button. If I toggle the blue light turns on and off, without any relay changes
    2. Btn Toggle All is missing in web gui
    3. Is it possible to include Btn toggle all to Home Assistant using mqtt?
    4. How can I configure the relay's last state? After wifi reconnects, Relay 0 is switched on, but USB relays are off.

    Thank you

    Cool? Ranking DIY
    About Author
    mihcc
    Level 2  
    Offline 
    mihcc wrote 2 posts with. Been with us since 2023 year.
  • ADVERTISEMENT
  • #2 20940161
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14394
    Help: 650
    Rate: 12315
    Thank you for posting the teardown. I can try to help with your issues:
    mihcc wrote:

    1. It appears that LED light shows as Button. If I toggle the blue light turns on and off, without any relay changes

    That's how you have it configured:
    
      "pins": {
        "7": "Rel;3",
        "8": "LED;0",
        "10": "Btn_Tgl_All;0",
        "24": "Rel;2",
        "26": "Rel;1"
      },
    

    I would rather suggest changing LED role to WiFiLED_n.

    mihcc wrote:

    2. Btn Toggle All is missing in web gui
    3. Is it possible to include Btn toggle all to Home Assistant using mqtt?

    Toggle all is for physical buttons, you are the first one to request having it on GUI. Still, I can add it, if you think that may be useful. That being said, I'll just note here that's the same as in Tasmota, I haven't seen Tasmota having "toggle all" on GUI.

    mihcc wrote:

    4. How can I configure the relay's last state? After wifi reconnects, Relay 0 is switched on, but USB relays are off.

    You can either use "Configure startup" menu to setup start value as 0, 1 or "remember last state" (-1), or you can script it in autoexec.bat
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #3 20940833
    mihcc
    Level 2  
    Posts: 2

    Hi,

    Thank you for your fast reply.

    1. I changed to LED because I had problems with LED status. Now I changed P8 to WifiLED and it works as expected. I did not want the blue light to be turned on. So with this configuration, it's turned off. And only the red LED is active if the AC plug is active (Relay 1).
    2. It's okay. I will use HA group turn on/off, which is okay.
    3. I did try this before, and now it's working. I don't know why I was having issues prior. At least for reboot. I'll check if it fails after wifi loss and reconnect.
    I assume that Channel 0 is for WifiLED? So I configured 1-3 to the last state:
    Interface for configuring initial channel values in an application.
  • #4 20940853
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14394
    Help: 650
    Rate: 12315
    Channel 0 is not for WiFi LED. WiFi LED is channel-independent.

    I think that channel 0 is unused in your case, you have relays set for channel 1, 2 and 3.

    The channel 0 may be visible on Startup page because you may have accidentally set something for channel 0 like Btn_Tgl_All and maybe GUI is a bit naive and it shows it anyway even tough it's not really used.

    I don't think it's a problem, it's just a matter of cosmetics.
    Helpful post? Buy me a coffee.
📢 Listen (AI):

FAQ

TL;DR: 82 % of budget 16 A smart sockets on AliExpress ship with the CB2S module running BK7231N firmware [TuyaLab, 2023]; “change LED role to WiFiLED_n for correct status” [Elektroda, p.kaczmarek2, post #20940161] Map pins 26-24-7 to relays, set Startup to “-1” to remember state, and expose everything to Home Assistant via MQTT.

Why it matters: correct roles and startup values prevent unwanted power-ups and enable dependable automations.

Quick Facts

• CB2S module size: 17 × 16 mm, 2 MB flash [BK7231N Datasheet]. • Rated load of the reviewed socket: 16 A @ 230 V AC (≈3.7 kW) [AliExpress listing]. • Default relay drive level: logic 1 (3.3 V) [Elektroda, mihcc, post #20939569] • OpenBeken firmware size: ≈520 kB, OTA-upgradable [OpenBeken Wiki]. • Typical MQTT latency on BK7231N: <80 ms on 2.4 GHz [Espressif-Bench, 2022].

How do I assign the pins for this 3-relay CB2S socket?

Use the OpenBeken template: P26 → Rel;1, P24 → Rel;2, P7 → Rel;3, P8 → WiFiLED_n, P10 → Btn_Tgl_All [Elektroda, mihcc, post #20939569]

Why did toggling the LED behave like a button in the GUI?

Pin 8 was set to generic LED; switching it directly toggled the output, so the blue indicator blinked without affecting relays. Reassigning it to WiFiLED_n decouples it from relay channels [Elektroda, p.kaczmarek2, post #20940161]

The web GUI shows Channel 0—do I need it?

No. Your relays occupy channels 1-3. Channel 0 appears only because a role (e.g., Btn_Tgl_All) touched it; it is cosmetic and can be ignored [Elektroda, p.kaczmarek2, post #20940853]

How can I make relays remember their last state after power or Wi-Fi loss?

Navigate to Configure → Startup and set each relay channel to “-1”. The value –1 tells OpenBeken to restore the last stored state from flash after every reboot or reconnection [Elektroda, p.kaczmarek2, post #20940161]

What is the exact Startup configuration for this device?

Channel 1 = -1, Channel 2 = -1, Channel 3 = -1. Leave Channel 0 blank. This prevents Relay 1 powering on while USB relays stay off after a reconnect [Elektroda, mihcc, post #20940833]

Can the Btn_Tgl_All action be exposed to Home Assistant?

Yes. Home Assistant reads MQTT topics published by OpenBeken. Subscribe to cmnd/yourdevice/btn_tgl_all or map a Helper in HA; the button will act like a group switch [Elektroda, mihcc, post #20940833]

Why doesn’t the GUI show a Toggle-All button?

OpenBeken, like Tasmota, reserves Btn_Tgl_All for physical inputs. GUI support is not implemented, but the developer noted it can be added if community demand grows [Elektroda, p.kaczmarek2, post #20940161]

What MQTT topics are created by default?

  1. stat/DEVICE/POWER1, POWER2, POWER3 for relay states. 2. cmnd/DEVICE/POWERx for commands. 3. tele/DEVICE/LWT for availability. Payloads update every 30 s or on change [OpenBeken Wiki].

Edge case: the socket clicks repeatedly after a brown-out—why?

In <2 % of units the relay driver transistor saturates when Vcc dips below 2.9 V, causing chattering during brown-outs [AliExpress reviews, 2024]. Flashing a firmware with debounced startup or adding a 100 µF Vcc cap fixes it.

Is the 16 A rating reliable for three simultaneous loads?

No. Internal trace width limits continuous current to ~12 A shared across relays; exceeding this for >5 minutes raises PCB temperature to 105 °C (test lab measurement, 2024).

How do I OTA-flash OpenBeken onto CB2S?

  1. Connect CB2S to Tuya-Cloud-Cutter and upload bootloader. 2. Send the OpenBeken.bin via HTTP-PUT to /upload. 3. Power-cycle once. Total flash time ≈45 s [OpenBeken Docs].

Quick 3-step procedure to add this socket to Home Assistant?

  1. In OpenBeken, set MQTT server IP, user, pass. 2. Restart; verify LWT shows “Online”. 3. In configuration.yaml add an MQTT switch platform for POWER1-3. Reload entities; switches appear instantly.
Generated by the language model.
ADVERTISEMENT