logo elektroda
logo elektroda
X
logo elektroda

[BK7231N/CB3S] Tuya Smart Air Box Air Quality Monitor, 5 sensors

lars4 5847 50
Best answers

How can I make OpenBeken show the sensor values from my Tuya Smart Air Box after flashing it?

Add `tuyaMcu_sendQueryState` to the autoexec after your `TuyaMCU` setup; that forces the MCU to send the current DP values, and the readings will appear in OpenBeken [#21169855][#21169864][#21169869] The working config kept `startDriver TuyaMCU`, `tuyaMcu_defWiFiState 4`, and `tuyaMcu_setBaudRate 9600`, then mapped DPs 18, 19, 2, 21, and 22 to channels 1–5 [#21169869] `tmSensor` is not needed here; it is intended for battery-powered devices [#21171036] If you still see nothing, the thread suggests checking the Tuya MCU baud rate and query behavior, but in this case the query command was the actual fix [#21169772][#21169855]
Generated by the language model.
ADVERTISEMENT
  • #31 21595031
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14416
    Help: 650
    Rate: 12371
    Just like our docs says:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/README.md
    setChannel sets given channel to given value, so it will not affect P8 directly if you don't set P8 role and channel, you need to assign a channel to P8 and also set it to Relay (or Rel_n, or LED, or LED_n, etc), in this case, channel 8, but in reality it can be any channel ...
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #32 21595589
    io2345
    Level 9  
    Posts: 244
    Help: 1
    Rate: 6
    >>21595031 Surprisingly enough: Not working. This is the autoexec.bat:

    tuyaMcu_defWiFiState 4
    tuyaMcu_setBaudRate 9600
    setChannelType 1 Temperature_div10
    linkTuyaMCUOutputToChannel 18 val 1
    setChannelType 2 Humidity_div10
    linkTuyaMCUOutputToChannel 19 val 2
    setChannelType 3 Custom
    SetChannelLabel 3 CH2O mg/m^3
    linkTuyaMCUOutputToChannel 2 val 3
    setChannelType 4 Custom
    SetChannelLabel 4 VOC ppm
    linkTuyaMCUOutputToChannel 21 val 4
    setChannelType 5 Custom
    SetChannelLabel 5 CO2 ppm
    linkTuyaMCUOutputToChannel 22 val 5
    tuyaMcu_sendQueryState
    
    alias ALARM_ON setChannel 8 1
    alias ALARM_OFF setChannel 8 0
    again:
    
    delay_s 5
    if $CH1>265
    then ALARM_ON 
    else ALARM_OFF
    goto again
    

    Channel 8 (for IO 8) is set as LED, but doesn't change when the value of 265 is exceeded (more than 26,5°C) . When toggled manually from the Webpage, there is power on IO 8.

    Startup commands are:

    backlog startdriver tuyamcu
    PowerSave 1



    I tried using IO 20 instead of 8 and type relay instead of LED,without success.
  • #33 21595612
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14416
    Help: 650
    Rate: 12371
    We do not have multiline if else syntax.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #34 21595628
    io2345
    Level 9  
    Posts: 244
    Help: 1
    Rate: 6
    >>21595612 Thank you for your fast response. Now it's working fine!

    For all others out there who are noobs like me: The autoexec.bat is now

    startDriver TuyaMCU
    tuyaMcu_defWiFiState 4
    tuyaMcu_setBaudRate 9600
    setChannelType 1 Temperature_div10
    linkTuyaMCUOutputToChannel 18 val 1
    setChannelType 2 Humidity_div10
    linkTuyaMCUOutputToChannel 19 val 2
    setChannelType 3 Custom
    SetChannelLabel 3 CH2O mg/m^3
    linkTuyaMCUOutputToChannel 2 val 3
    setChannelType 4 Custom
    SetChannelLabel 4 VOC ppm
    linkTuyaMCUOutputToChannel 21 val 4
    setChannelType 5 Custom
    SetChannelLabel 5 CO2 ppm
    linkTuyaMCUOutputToChannel 22 val 5
    tuyaMcu_sendQueryState
    alias ALARM_ON setChannel 8 1
    alias ALARM_OFF setChannel 8 0
    again:
    delay_s 10
    if $CH1>580||$CH2>890||$CH3>50||$CH4>200||$CH5>1200 then ALARM_ON else ALARM_OFF
    goto again
  • #35 21600458
    io2345
    Level 9  
    Posts: 244
    Help: 1
    Rate: 6
    >>21595612 One problem still: When powering on the device, all values are zero - and stay on zero until I press the restart button on the webpage. The restart takes quite long (53 seconds), but then all values are ok.
    How can I get the device to report the correct readings instantly?
    About the config: Autoexec.bat in Post #34, Startup commands in Post # 32, Flags 10 + 19 are set.
  • ADVERTISEMENT
  • #36 21629226
    io2345
    Level 9  
    Posts: 244
    Help: 1
    Rate: 6
    >>21600458 Can this be fixed? It's not a big deal - but if there is a power outage, I probably will not remember it in a year or so. So it would be better, if device starts without issue.
  • #37 21629426
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14416
    Help: 650
    Rate: 12371
    Maybe just use setStartValue [channel] -1 to remember those values between reboots?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #38 21629713
    io2345
    Level 9  
    Posts: 244
    Help: 1
    Rate: 6
    >>21629426 I have this in autoexec.bat:

    tuyaMcu_defWiFiState 4
    tuyaMcu_setBaudRate 9600
    setChannelType 1 Temperature_div10
    linkTuyaMCUOutputToChannel 18 val 1
    setChannelType 2 Humidity_div10
    linkTuyaMCUOutputToChannel 19 val 2
    setChannelType 3 Custom
    SetChannelLabel 3 CH2O mg/m^3
    linkTuyaMCUOutputToChannel 2 val 3
    setChannelType 4 Custom
    SetChannelLabel 4 VOC ppm
    linkTuyaMCUOutputToChannel 21 val 4
    setChannelType 5 Custom
    SetChannelLabel 5 CO2 ppm
    linkTuyaMCUOutputToChannel 22 val 5
    tuyaMcu_sendQueryState
    alias ALARM_ON setChannel 8 1
    alias ALARM_OFF setChannel 8 0
    again:
    delay_s 10
    if $CH1>580||$CH2>890||$CH3>50||$CH4>200||$CH5>1200 then ALARM_ON else ALARM_OFF
    goto again


    Will I have to set "setStartValue [channel] -1" only for self-defined channels 1 to 5, or also for 2, 18-19 and 21-22 (these five are MCUoutput)? Saying this I notice now, that the value 2 is existing two times: as MCUoutput channel and as self defined channel. I guess that this isn't clever, right?
    What about channel 8? Needs "setStartValue" as well?
  • #39 21636330
    kevinkorowin
    Level 1  
    Posts: 1
    Hello

    is it possible to add a battery on the board
    ?with tp4056 and 18650 battery ?

    Thanks
  • #40 21655487
    ngocnguyenme
    Level 4  
    Posts: 7
    >>21169869 Thank you so much. I was able to get my air box to show all values. But every time when I reboot the device (plug out and in), then I have to run the autoexec.bat manually to get all values to be shown again. How can I configure to run this script automatically at boot? Sorry, if my question sounds a bit silly. I am a total newbie to this custom fw stuff. Thanks in advance
  • #41 21655497
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14416
    Help: 650
    Rate: 12371
    How do you save autoexec.bat?

    The correct way:


    Helpful post? Buy me a coffee.
  • #42 21655612
    ppikart
    Level 1  
    Posts: 1
    Just because it's the only online discussion I can find about this sensor:

    Does anyone know how it dares to report a CO2-Value? Is it just the output of the VOC-sensor that is calculated into a CO2, VOC and formaldehyde-value?
  • #43 21655666
    ngocnguyenme
    Level 4  
    Posts: 7
    >>21655497 that already done, but I still get this after physically rebooting the device

    AirQualBox1 device interface screen with technical data and control buttons.
  • #44 21655679
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14416
    Help: 650
    Rate: 12371
    How your autoexec.bat looks like?

    Maybe you need to add a state query after startup, but probably not, that's tmSensor device.

    Simple work-around could also work - use low channels number for variables and then in configure startup set them to -1, to the value is kept between reboots.
    Helpful post? Buy me a coffee.
  • #45 21656298
    ngocnguyenme
    Level 4  
    Posts: 7
    >>21655679 I just copied from >>21169869, nothing changed. I really don't know how to start with "low channels number"? Could you explain it further please!
  • #46 21694892
    ngocnguyenme
    Level 4  
    Posts: 7
    Does someone still have a backup of the original fw (bin file)? If yes, please share it! I lost mine. I want to flash my airbox with esphome to utilise some spare pins for other purposes (ir control for example). Now I don't know to change from openbeken to esphome without a backup of the original fw. Any help is appreciated!
  • #47 21694989
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14416
    Help: 650
    Rate: 12371
    ngocnguyenme wrote:
    really don't know how to start with "low channels number"?

    Like with channels 1, 2, 3, 4 etc not 40, 45, 50. And then you can use setStartValue 1 -1 to make channel 1 remember state between reboots. The same for channel 2, 3, 4, etc. If that's what's the problem?

    OBK has IR driver I think.

    Added after 1 [minutes]:

    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/commands.md
    Helpful post? Buy me a coffee.
  • #48 21699862
    ngocnguyenme
    Level 4  
    Posts: 7
    >>21694989 I've just switched to ESPHome to utilise some free pins for other purposes and it's working fine now. Thanks again :)
  • #49 21744651
    io2345
    Level 9  
    Posts: 244
    Help: 1
    Rate: 6
    >>21636330 @kevinkorowin : I'm sorry, I missed your post. Of course you can add a battery, but it will serve only as buffer, not as constant power supply. This device isn't designed as battery driven device, it has no deep sleep, so the battery will not last too long

    Hinzugefügt nach 10 [Minuten]:

    >>21655612 @ppikart : Not sure about the CO2 / VOC values. The sensor has printed "BP0315-01# HMNST" on it, but I can't find online data about it. I can't test it for VOC and Formaldeyd, but of course for CO2. Just breathe on it, and values will change (takes some seconds, but it will)

    @ngocnguyenme : You could have achieved the same with OBK. Using spare pins was exactly what I did in this (https://www.elektroda.com/rtvforum/topic4067480.html#21593564) and other projects (like here: https://www.elektroda.com/rtvforum/topic4112845.html#21489313)
  • #50 21813188
    io2345
    Level 9  
    Posts: 244
    Help: 1
    Rate: 6
    >>21629226 "if there is a power outage, I probably will not remember it in a year or so. So it would be better, if device starts without issue"

    I knew that it will happen. Must have been a short power outage some weeks ago. No valid data since then, always the same values. Restarted the device from the webpage, and now correct values are transmitted.
    How can I avoid that in future? Is it possible to have the device restarted itself once a day?
  • #51 21816233
    io2345
    Level 9  
    Posts: 244
    Help: 1
    Rate: 6
    Can it be done with the "addRepeatingEvent" command?

    EDIT: I did add now this to autoexec.bat:
    
    alias regular_reboot backlog delay 24:00:00 reboot
    regular_reboot


    Let's wait and see if it works

    Hinzugefügt nach 1 [Stunden] 30 [Minuten]:

    For testing, I changed the time to one hour. Doesn't seem to work, or the entry in autoexec.bat is at the wrong position (?). Device is now online for 1 hour 12 minutes.
    Any suggestions?

    startDriver TuyaMCU
    tuyaMcu_defWiFiState 4
    tuyaMcu_setBaudRate 9600
    setChannelType 1 Temperature_div10
    setStartValue 1 -1
    linkTuyaMCUOutputToChannel 18 val 1
    setChannelType 6 Humidity_div10
    setStartValue 6 -1
    linkTuyaMCUOutputToChannel 19 val 6
    setChannelType 3 Custom
    setStartValue 3 -1
    SetChannelLabel 3 CH2O mg/m^3
    linkTuyaMCUOutputToChannel 2 val 3
    setChannelType 4 Custom
    setStartValue 4 -1
    SetChannelLabel 4 VOC ppm
    linkTuyaMCUOutputToChannel 21 val 4
    setChannelType 5 Custom CO2
    setStartValue 5 -1
    SetChannelLabel 5 CO2 ppm
    linkTuyaMCUOutputToChannel 22 val 5
    tuyaMcu_sendQueryState
    alias ALARM_ON setChannel 8 1
    alias ALARM_OFF setChannel 8 0
    alias regular_reboot backlog delay 1:00:00 reboot
    regular_reboot
    again:
    delay_s 10
    if $CH1>580||$CH6>890||$CH3>50||$CH4>200||$CH5>1200 then ALARM_ON else ALARM_OFF
    goto again

    Hinzugefügt nach 3 [Stunden] 16 [Minuten]:

    Delay is probably too long-
    Got things working by putting this into autoexec.bat:

    startDriver ntp
    ntp_setup 0.pool.ntp.org
    ntp_start
    ntp_timeZoneOfs 1
    addClockEvent 13:30:00 0x7F 1 reboot

Topic summary

✨ The discussion addresses issues with reading sensor values from the Tuya Smart Air Box Air Quality Monitor (BK7231N/CB3S) after switching to OpenBeken firmware. The original firmware correctly outputs sensor data including CH2O, temperature, humidity, VOC, and CO2 via specific data points (DPIDs). Initial troubleshooting involved verifying baud rates (default 9600), module connection integrity, and driver configurations in autoexec.bat. The key solution was to send the command "tuyaMcu_sendQueryState" after startup to retrieve sensor values, as values do not appear automatically on reboot. The working autoexec.bat includes starting the TuyaMCU driver, setting WiFi state, baud rate, defining channel types and labels, linking DPIDs to channels, and issuing the query state command. Further discussion identified the temperature/humidity sensor as a DHT20 and the VOC sensor as an HGS1000 from Hefei Micro Nano Sensing Technology Co. Ltd (HMNST), which uses UART communication but lacks direct OpenBeken support. Suggestions included periodic sending of the query state command and enabling power-saving modes. An additional topic explored adding an alarm buzzer on GPIO P8 (Pin 13) triggered by threshold exceedances on sensor channels, implemented via autoexec.bat scripting with conditional loops and channel control commands. The conversation also referenced firmware backup sharing and device templates for integration.
Generated by the language model.

FAQ

TL;DR: If your BK7231N/CB3S Tuya Air Box shows 0 values in OpenBeken, map 5 dpIDs, set baud to 9600, set Wi‑Fi state to 4, and add tuyaMcu_sendQueryState. "Now I got the values" after that command. This FAQ is for OpenBeken users who need temperature, humidity, CH2O, VOC, and CO2 to appear correctly after flashing. [#21169869]

Why it matters: This device can look fully flashed yet still report no useful air-quality data until the right TuyaMCU startup sequence runs.

Option Result on this Air Box Best use
OpenBeken + TuyaMCU + tuyaMcu_sendQueryState All 5 values can display correctly Keep TuyaMCU path and add automation
OpenBeken + tmSensor Can interfere here Battery-powered TuyaMCU devices
ESPHome Used successfully for spare pins and other purposes If you want custom GPIO or IR work

Key insight: The missing piece was not the channel map. It was forcing a TuyaMCU state refresh at boot with tuyaMcu_sendQueryState, while avoiding tmSensor on this mains-powered Air Box. [#21169869]

Quick Facts

  • The working dpID map is: 2 = CH2O mg/m^3 ÷100, 18 = temperature ÷10, 19 = humidity ÷10, 21 = VOC ppm ÷10, 22 = CO2 ppm. Those five datapoints are enough to expose all main readings in OpenBeken. [#21169769]
  • The confirmed working TuyaMCU settings were tuyaMcu_defWiFiState 4 and tuyaMcu_setBaudRate 9600. Without the later query command, the device could still boot with empty readings. [#21169842]
  • A working alarm add-on used CB3S P8 with a transistor switch, not a direct buzzer connection. The buzzer was rated 35 mA, and direct drive from the module pin was explicitly discouraged. [#21593564]
  • A practical self-recovery method used NTP plus addClockEvent 13:30:00 0x7F 1 reboot to force one reboot every day. That workaround targeted stuck values after power outages. [#21816233]
  • The thread identified two onboard sensors: a DHT20 for temperature and humidity, and an HMNST HGS1000 gas sensor module. OpenBeken support was clear for DHT20, but not for HGS1000 direct integration. [#21177061]

How do I make a Tuya Smart Air Box with BK7231N/CB3S show temperature, humidity, CH2O, VOC, and CO2 correctly in OpenBeken?

Use TuyaMCU, map the five dpIDs, and send a state query at boot. 1. Start TuyaMCU, set Wi‑Fi state 4, and baud 9600. 2. Link dpIDs 18, 19, 2, 21, 22 to channels for temperature, humidity, CH2O, VOC, and CO2. 3. Add tuyaMcu_sendQueryState to autoexec.bat so values appear after power-up, not only after a manual command. [#21169869]

Why does this Tuya Air Box only start showing sensor values after I run tuyaMcu_sendQueryState in OpenBeken?

Because this device does not reliably push its current TuyaMCU states to OpenBeken on its own at boot. The manual command forces the MCU to return the active dpID values, and that immediately populated all five readings in the log and UI. After each restart, the same query was needed until it was added to autoexec.bat. [#21169864]

What should a working autoexec.bat look like for the Tuya Smart Air Box Air Quality Monitor with dpIDs 2, 18, 19, 21, and 22?

A working file starts TuyaMCU, sets Wi‑Fi state 4, sets baud 9600, maps dpIDs 18/19/2/21/22 to channels 1–5, and ends with tuyaMcu_sendQueryState. Channel 1 is Temperature_div10, channel 2 is Humidity_div10, and channels 3 to 5 are custom labels for CH2O, VOC, and CO2. That exact layout was confirmed to work on July 27, 2024. [#21169869]

Which TuyaMCU settings matter most on this device, such as tuyaMcu_defWiFiState 4 and tuyaMcu_setBaudRate 9600?

The two key settings are tuyaMcu_defWiFiState 4 and tuyaMcu_setBaudRate 9600. On this Air Box, 9600 matched the working serial link, while Wi‑Fi state 4 was recommended during troubleshooting under startDriver TuyaMCU. These settings alone were not enough, but they were part of the final working configuration. [#21169842]

Why can startDriver tmSensor break or interfere with readings on this Air Box, and when should tmSensor be used instead?

It can interfere because this Air Box works through TuyaMCU state reporting, not the battery-oriented polling path tied to tmSensor. Removing startDriver tmSensor changed the serial behavior, and the final fix omitted it completely. Use tmSensor for battery-powered TuyaMCU devices, not this mains-powered USB-C Air Box. [#21171036]

What is tmSensor in OpenBeken, and why is it recommended only for battery-powered devices?

"tmSensor" is an OpenBeken driver that handles TuyaMCU sensor behavior for battery-powered devices, including state reporting patterns that differ from always-powered hardware. In this thread, an OpenBeken maintainer stated, "tmSensor is only for battery powered devices." That is why enabling it on this Air Box caused confusion instead of fixing the missing values. [#21171036]

What is a TuyaMCU dpID, and how do dpIDs map to OpenBeken channels on the BK7231N Air Box?

"TuyaMCU dpID" is a Tuya datapoint identifier that carries one sensor or status value between the main MCU and the Wi‑Fi module, with each dpID representing a specific function and value format. On this Air Box, dpID 18 maps to temperature ÷10, 19 to humidity ÷10, 2 to CH2O ÷100, 21 to VOC ÷10, and 22 to CO2 ppm. [#21169769]

How can I add a buzzer alarm to an unused CB3S pin like P8 and trigger it when temperature, humidity, CH2O, VOC, or CO2 exceed thresholds?

Use a transistor-switched buzzer on P8 and control it from a linked OpenBeken channel. 1. Assign P8 to channel 8 and set its role to Relay, Rel_n, LED, or LED_n. 2. Add alias ALARM_ON setChannel 8 1 and alias ALARM_OFF setChannel 8 0. 3. Run a loop such as if $CH1>580||$CH6>890||$CH3>50||$CH4>200||$CH5>1200 then ALARM_ON else ALARM_OFF. Do not drive a 35 mA buzzer directly from the CB3S pin. [#21595628]

Why doesn’t a multiline if/else script work in OpenBeken autoexec.bat, and what is the correct single-line syntax for alarm logic?

It fails because OpenBeken does not support multiline if/else syntax in autoexec.bat. The maintainer stated that directly, and the fix was a single-line command such as if $CH1>580||$CH2>890||$CH3>50||$CH4>200||$CH5>1200 then ALARM_ON else ALARM_OFF. Once rewritten to one line, the alarm logic worked. [#21595612]

How do I configure a CB3S GPIO pin to follow an OpenBeken channel, such as setting P8 to Relay or LED on channel 8?

You must assign both a role and a channel to the pin. setChannel 8 1 changes channel 8 only; it does not drive P8 until P8 is configured as Relay, Rel_n, LED, or similar and linked to channel 8. The maintainer noted that the channel number can be any value, but the pin-role mapping is mandatory. [#21595031]

What causes this Air Box to boot with zero or stale values until a restart, and how can I keep readings valid across reboots with setStartValue or state queries?

The device can boot without refreshing TuyaMCU datapoints, so channels stay at 0 or retain stale values until a restart or query. Two mitigations appeared in the thread: add tuyaMcu_sendQueryState at startup, and use low channel numbers with setStartValue <channel> -1 so the last values persist across reboots. A later example used channels 1, 3, 4, 5, 6 with setStartValue on each. [#21816233]

How can I schedule an automatic daily reboot in OpenBeken using NTP and addClockEvent to recover from stuck sensor values after power outages?

Start the NTP driver, set a time source, and schedule a clock event. The working example was: startDriver ntp, ntp_setup 0.pool.ntp.org, ntp_start, ntp_timeZoneOfs 1, and addClockEvent 13:30:00 0x7F 1 reboot. The user first tried a long delay alias, but daily reboot worked after switching to NTP-based scheduling. [#21816233]

What sensors are inside the Tuya Smart Air Box, and how were the DHT20 and HMNST HGS1000 identified in the thread?

The thread identified a DHT20 for temperature and humidity and an HMNST HGS1000 gas sensor module. The DHT20 was confirmed by a board photo on July 30, 2024, and the HGS1000 name later came from HMNST contact confirmation shared on July 31, 2024. OpenBeken support was described as straightforward for DHT20, while HGS1000 protocol support was not available. [#21174757]

OpenBeken vs ESPHome on the Tuya BK7231N Air Box: which is better if I want to use spare pins for alarms or IR control?

OpenBeken is sufficient if you want alarms or spare GPIO control, while ESPHome was chosen by one user for broader repurposing. This same Air Box already drove a buzzer from a spare pin under OpenBeken, and an OpenBeken maintainer also noted that OBK has an IR driver. ESPHome still worked fine for one user who switched to use free pins for other functions. [#21694989]

How does this Air Box derive its reported CO2 reading, and is it a true CO2 measurement or an estimate based on the VOC/formaldehyde sensor?

The thread does not prove that the CO2 value is a true dedicated CO2 measurement. Users confirmed a DHT20 plus an HMNST HGS1000 gas sensor, and one later question explicitly asked whether CO2 was calculated from the VOC sensor, but no definitive protocol or sensing method was posted. Treat the displayed CO2 as unverified within this thread, even though breathing on the unit changed the reading. [#21744651]
Generated by the language model.
ADVERTISEMENT