logo elektroda
logo elektroda
X
logo elektroda

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

mihcc  3 1794 Cool? (0)
📢 Listen (AI):

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.
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

About Author
mihcc wrote 2 posts with . Been with us since 2023 year.

Comments

p.kaczmarek2 01 Feb 2024 21:27

Thank you for posting the teardown. I can try to help with your issues: That's how you have it configured: "pins": { "7": "Rel;3", "8":... [Read more]

mihcc 02 Feb 2024 11:45

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... [Read more]

p.kaczmarek2 02 Feb 2024 12:01

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... [Read more]

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.
%}