logo elektroda
logo elektroda
X
logo elektroda

[CBU/BK7231N] Tuya PIR motion sensor Krasław 120°, deep sleep, battery powered

p.kaczmarek2  25 5730 Cool? (+6)
📢 Listen (AI):

TL;DR

  • Teardown and OpenBeken flash of a Tuya Krasław 120° PIR motion sensor with CBU/BK7231N, aimed at making the battery-powered detector fully local and cloud-free.
  • The CBU runs everything directly, without TuyaMCU, and uses deep sleep so Wi‑Fi wakes only when the PIR reports motion or a status must be sent.
  • The sensor cost PLN 50, uses three AAA batteries, and Tuya’s config maps P20 button, P26 LED, P16 PIR, P17 battery relay, and P23 ADC.
  • OpenBeken configuration with the battery driver and DoorSensorWithDeepSleep worked, and the LED lit up as soon as motion was detected.
  • Depending on the PCB version, DSEdge may need adjustment for the wake edge, and the author notes that sleeping in both states should improve battery life.

I will present here the teardown, the principle of operation and the firmware change (in order to free it from the cloud and gain independence from the manufacturer's servers) of a cheap PIR sensor by Tuya, bought on one of the Polish shipping portals. Finally, I will provide its full configuration for OpenBeken, along with the template. Of course, we will configure the device to work with deep sleep and the PIR sensor will only wake it up when a movement is detected. This is essential for battery-powered gadgets with WiFi communication, otherwise battery would drain too fast.

Sensor purchase
The sensor was purchased by one of the users OpenBeken on a Polish auction site, with the intention of giving it to me so that I could change its firmware. Below are screenshots of the offer:

We paid only PLN 50 (about 12$), the shipment was free (in the package for regular customers of this portal).
Parameters, no specifics here:

Only in the features can we read, for example, that the sensor "holds" presence detection for 30 seconds, or at what distance it can detect:


This sensor is powered by three AAA batteries (they are not included in the set, they must be purchased separately).
The packaging, unfortunately, does not have specific markings:

Here's what we got in the kit:

There is a tape and a reset key.
The product also has a hook to stick to the wall (this is the tape), and after removing it, we have access to the battery, the ON-OFF button and the reset button (i.e. pairing):



The teardown of the sensor
Apparently the sensor has a warranty seal from the seller, but it is glued in such a way we don't have to remove it.

There is a module inside CBU , its documentation is on the Tuya website, a OpenBeken supports BK7231N.

Let's take a look at the board:

Not much happens on this board. The PIR sensor is typical, such as in popular modules for Arduino. My attention was caught by the U3 chip, i.e. 7333, 3.3V LDO regulator. I thought that there would be a slightly more efficient step down converter here, but no. All in all, it makes some sense, here there are three nominally 1.5V batteries, i.e. 4.5V in total, of course less and less with their discharge. Tuya battery powered products with converters instead of regulators are rather two batteries, then there is 3V, and the converter increases them to 3.3V.
The on-off button allows you to turn off the sensor completely without removing the battery:

Transistors R1 and A09T, whose roles I have not analyzed:

CBU:

This device does not use TuyaMCU. There is no additional microcontroller here, nothing is blocking UART1 from the CBU. The CBU controls everything by itself and falls into a deep sleep when nothing happens. This device wakes up and connects to WiFi only when a status needs to be reported.

Programming, configuration
We connect the common ground, RX and TX from the UART converter and possibly the power supply, start the flasher, and do the power cycle (off and on). Everything as described in our repo:
https://github.com/openshwprojects/BK7231GUIFlashTool
The same process can be seen on our YT channel:
https://www.youtube.com/@elektrodacom
Soldered wires:

Flasher in motion:

Flasher can also read Tuya configuration:

Here we have the JSON from Tuya, their device description format:
Code: JSON
Log in, to see the code

Text description of the same from my flasher:

Device configuration, as extracted from Tuya: 
- Button (channel 0) on P20
- Status LED on P26
- PIR sensor on P16
- Battery Relay on P17
- Battery Max Voltage: 3000
- Battery Min Voltage: 2200
- Battery ADC on P23
Device seems to use Battery Driver. See more details here: https://www.elektroda.com/rtvforum/topic3959103.html
Device seems to be using CBU module, which is using BK7231N.
And the Tuya section starts, as usual, at 2023424


Partially finished template in our JSON format:
Code: JSON
Log in, to see the code

Let's analyze what we've got here. First, there's the pairing button, Button, on the P20. There is a WiFi LED here on the P26. There is a PIR sensor on the P16. And we have a battery status control system, i.e. ADC + GPIO which turns on the resistor divider. These GPIOs are there to save energy and to make the resistor divider only let current when we make a measurement. Tuya also determines the maximum and minimum battery voltages, it is used for calculations.
There was already a topic about the battery controller here:
https://www.elektroda.com/rtvforum/topic3959103.html
Now it's all about deep sleep. The WiFi module cannot work all the time, it would drain the batteries too quickly. To do this, we will use the deep sleep solution described here:
https://www.elektroda.com/rtvforum/topic3960149.html
Also, check out this topic on deep sleep:
https://www.elektroda.pl/rtvforum/topic3972898.html
https://www.elektroda.com/rtvforum/topic3972898.html
In summary, here is what needs to be configured:
- set the Button role for the button to P20 to be able to wake the device from a deep sleep in an emergency
- set the role of LED (or WiFi LED - at your discretion, or LED_n) to P26, select channel 1 there
- set the role of DoorSensorWithDeepSleep for P16, because we will use the door sensor driver to report movement, also set channel 1
- additionally, depending on which PCB version you have, you may need to configure DSEdge to select the type of edge that wakes up the sensor (rising, falling, or respectively increasing when the system goes to sleep with a low state on the sensor or falling when the system goes to sleep with a high state on sensor)
- configure the battery driver, as in the previously linked topic
After that, you can perform Home Assistant Discovery to connect the device to the HA:
https://www.youtube.com/watch?v=pkcspey25V4

Just in case, here is the OBK documentation:
https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/README.md
And any questions can be asked on our forum.

Here is the final result:



The LED lights up as soon as motion is detected.


Summary
That was a success - another device freed from the cloud and from the manufacturer's servers. In addition, once again we managed to encounter something using a battery controller based on the ADC input and the digital GPIO output, where the digital GPIO turns on the resistor voltage divider only for the time of measurement. I have seen it several times in this type of products, also in the case of a door sensor.
As for the configuration of the device itself, it is worth noting that it could also be handled "manually", through the OpenBeken script, simply by entering a simple loop with IF and GoTo, which will put it to sleep using the PinDeepSleep command when there are no changes on the sensor for while.
Here the question arises whether we want the device to "sleep" only when there is no movement (and it was "wake up" until the PIR reports the presence of movement), or to "fall asleep" in both states. When using the driver, DoorSensor falls asleep in both states. This is probably better in terms of battery life.
It is worth adding that in OBK such a device can control others even without Home Assistant - just script the SendGET command and, for example, send a new state for the light switch via IP.
That's probably it, at the end I'll just remind you that a static IP and placing the device close to the router will also extend the battery life to some extent.
Does any of the readers use this type of PIR sensors? And if so, is it in the "cloud" version related to the manufacturer's servers, or maybe in a fully local version?

About Author
p.kaczmarek2
p.kaczmarek2 wrote 14218 posts with rating 12108 , helped 647 times. Been with us since 2014 year.

Comments

pippo_franco 15 Aug 2023 13:08

Hello, I have the same sensor and I was able to flash it with OpenBK after using the cloudcutter tool. Everything seems to be working using the provided configuration, I just had to put the PIR sensor... [Read more]

p.kaczmarek2 15 Aug 2023 13:13

LED could be very easily scripted to behave as you wish. For example, you can put LED on channel 4 (or any other one), and then in autoexec.bat do: // turn on LED setChannel 4 1 // schedule an event,... [Read more]

pippo_franco 15 Aug 2023 16:24

Thanks, I will try with the script as suggested and see if it works. If I properly understood, that script is going to turn on the LED as soon as the device is turnt on, and not when the PIR detects a... [Read more]

p.kaczmarek2 15 Aug 2023 17:23

You are correct. If you want to link LED behaviour to PIR channel, you should do smth like that: // set channel to 1 and after 2 seconds set it to 0 // NOTE: addRepeatingEvent [RepeatTime]... [Read more]

pippo_franco 16 Aug 2023 11:02

Thanks a lot for the quick feedback, I’ll try with the provided script and let you know if I have further questions. Regarding the SendGet approach, if I properly understood it means that I will need... [Read more]

p.kaczmarek2 16 Aug 2023 11:11

Well, you could certainly call HA API that way, but I was thinking about using SendGet directed towards a lamp IP and sending a Tasmota-style cm interface POWER ON call. That way PIR communicates directly... [Read more]

pippo_franco 16 Aug 2023 14:11

Got it, thanks. The lamp is actually controlled using a Shelly 1 with the original firmware and connected to HA, that’s why I would prefer to have it controlled with an automation in HA. I’ll try to do... [Read more]

lambuzz 20 Feb 2024 17:49

Hello, I have the same sensor. I was able to flash it with OpenBK with Tuya cloudcutter. Everything seems to be working until I provided my SSID and password info in the configuration. After, it restarted... [Read more]

p.kaczmarek2 20 Feb 2024 17:56

So you already accessed OBK on the OBK config page? Well, then try to enter safe mode: https://obrazki.elektroda.pl/1935619000_1708448192_thumb.jpg https://github.com/openshwprojects/OpenBK... [Read more]

lambuzz 20 Feb 2024 18:13

I was able to access OBK config page. I did the 5 quick power on/off on both device but nothing happened. I tried multiple times [Read more]

p.kaczmarek2 20 Feb 2024 19:04

Have you already entered a deep sleep command for that device? Maybe it's asleep? [Read more]

lambuzz 20 Feb 2024 19:28

The only thing I updated once I flashed OBK is in the wifi settings. I added the SSID and password and I clicked on Submit. This made me confirmed I entered the correct information. and then it turned... [Read more]

p.kaczmarek2 20 Feb 2024 19:42

The safe mode really should work. It's designed in such a way that even if the AP connect crashes, safe mode will still kick in. Anyway, can you connect USB to UART converter to get log from TX2? [Read more]

lambuzz 21 Feb 2024 16:42

Tried again to enter safe mode on both devices, nothing happened. unfortunately, I don't have UART connector [Read more]

p.kaczmarek2 04 Mar 2024 18:02

Is your device the same as the one in the first post? Maybe your device is TuyaMCU based. That could complicate things. TuyaMCU battery powered devices have MCU controlling the power of WiFi module, so... [Read more]

lambuzz 07 Mar 2024 14:48

This is the same device. I bought a new one and tried again. This time it worked and I think I understand what happened with the first two devices. I did not configure the devices and the buttons, LED... [Read more]

p.kaczmarek2 22 Mar 2024 09:24

This should never break BK7231 device, unless you enter a deep sleep command with a large delay and get BK7231 sleeping on power from a capacitor. Still, even there, if should just turn off and be flashable... [Read more]

DeDaMrAz 24 Aug 2024 16:04

This will provide basic functionality and can be further tweaked to preserve battery. //safe mode 20 is the pin number where your switch is addEventHandler OnHold 20 SafeMode 5 // wait for wifi... [Read more]

p.kaczmarek2 13 Oct 2024 22:06

For a non-debug version, delay_s 15 should be removed and PinDeepSleep enabled (remove comment). Or at least.... we need to add a mechanism to run PinDeepSleep only if a pairing button is not pressed (so... [Read more]

FAQ

TL;DR: Deep-sleep trims average current from 70 mA to 0.12 mA (-99 %) [Tuya-CBU DS]—"Five power-cycles always force Safe-Mode" [Elektroda, p.kaczmarek2, post #20970476] Flashing OpenBeken frees the 12 USD Tuya PIR from the cloud in under 5 minutes [Elektroda, p.kaczmarek2, post #20648488]

Why it matters: Local firmware slashes standby drain and removes vendor lock-in while preserving Home-Assistant integration.

Quick Facts

• Chipset: Beken BK7231N on Tuya CBU module [Elektroda, p.kaczmarek2, post #20648488] • Power: 3 × AAA cells, 4.5 V nominal [Elektroda, p.kaczmarek2, post #20648488] • Street price: PLN 50 ≈ 12 USD (Jul 2023) [Elektroda, p.kaczmarek2, post #20648488] • Typical Wi-Fi reconnect (static IP + QuickConnect): ≈ 5 s [Elektroda, pippo_franco, post #20694211] • Deep-sleep command: PinDeepSleep 86400 (wakes once per day) [Elektroda, DeDaMrAz, post #21202250]

1. What hardware is inside the Tuya 120° PIR sensor?

The board carries a Tuya CBU module with a BK7231N Wi-Fi SoC, a 3.3 V 7333 LDO, PIR element, button (P20), status LED (P26) and battery ADC/relay pair (P23/P17) [Elektroda, p.kaczmarek2, post #20648488]

2. How do I flash OpenBeken firmware?

  1. Solder GND, RX, TX and optional 3.3 V from a USB-UART to the pads shown in the teardown photo [Elektroda, p.kaczmarek2, post #20648488]
  2. Run BK7231 GUI FlashTool, select the UG image, click Flash, then power-cycle the sensor.
  3. On first boot, connect to the OBK access-point and finish web setup. Total time ≈ 5 minutes.

3. Which GPIO roles must I set after flashing?

• P20 → Btn;0
• P16 → DoorSnsrWSleep;0
• P26 → LED;0
• P17 → BAT_Relay;0
• P23 → BAT_ADC;0
Template JSON is provided in the original post for copy-paste [Elektroda, p.kaczmarek2, post #20648488]

4. How much battery life can deep-sleep add?

CBU deep-sleep current is 0.12 mA versus ~70 mA when Wi-Fi stays up [Tuya-CBU DS]. At one motion per hour and a 1200 mAh AAA pack, calculated life rises from about 1 day to roughly 1 year.

6. How can I make the LED blink only once on motion?

Create an autoexec.bat:

alias blinky backlog setChannel 4 1; addRepeatingEvent 2 1 setChannel 4 0
addChangeHandler Channel1 == 1 blinky
This turns LED (channel 4) on, then off after 2 s whenever PIR (channel 1) goes high [Elektroda, p.kaczmarek2, post #20694518]

7. How do I integrate it with Home Assistant?

Enable MQTT discovery in OBK, set broker IP, then run Home-Assistant Discovery. The sensor appears as a binary_sensor with “presence” label; no Tuya cloud needed [Elektroda, p.kaczmarek2, post #20648488]

8. What is Safe-Mode and how do I enter it?

Safe-Mode boots OBK with Wi-Fi AP active even if the main config crashes. Toggle power five times within 10 s; the LED lights and AP appears [Elektroda, p.kaczmarek2, post #20970476]

9. The device stayed dark after saving Wi-Fi—am I bricked?

Most cases are a mis-configuration. Enter Safe-Mode, or wire TX2 to a USB-UART for logs. If you accidentally issued PinDeepSleep on capacitor power, discharge the board, reconnect, and re-flash [Elektroda, p.kaczmarek2, post #21014482]

10. Edge case: what if my unit uses TuyaMCU?

A rare TuyaMCU variant keeps an external MCU that may shut the Wi-Fi power rail, blocking Safe-Mode. You must access UART early and possibly bypass the MCU’s VCC control [Elektroda, p.kaczmarek2, post #20990161]

11. How do I set up accurate battery reporting?

Use Battery_Setup 3400 4500 2.01 2400 4096 for three-cell packs, then Battery_cycle 2 to sample every two boots [Elektroda, DeDaMrAz, post #21202250] Adjust the first two voltages for two-cell units.

13. Can I control a lamp directly without MQTT?

Yes. Script:

waitFor WiFiState 4
SendGet http://192.168.0.112/cm?cmnd=Power0%20ON
delay_s 3
PinDeepSleep 86400
This HTTP call triggers a Tasmota lamp in ~5 s, even if HA is offline [Elektroda, p.kaczmarek2, post #20695354]

14. What causes Safe-Mode to fail?

If you wire batteries but miss the LED/channel mapping, OBK may deep-sleep before LEDs or buttons work, making the five-toggle sequence seem dead. Configure pins first, then enable PinDeepSleep [Elektroda, lambuzz, post #20994250]
%}