logo elektroda
logo elektroda
X
logo elektroda

[BK7231N CBU] Tuya WiFi Temperature and Humidity Sensor (Blue PCB, no TuyaMCU)

dmcbeing 6042 16
ADVERTISEMENT
  • I recently bought a few of 'Tuya WiFi Temperature and Humidity Sensor'.

    I looked for an existing thread for this exact device but only found a few users posting pictures of this board.

    Here is a picture of the PCB: PCB board of Tuya WiFi sensor with highlighted components and connections.

    And here is the firmware from an unused device:
    tuya_r..zip Download (1002.72 kB)
    Tuya JSON:
    Code: JSON
    Log in, to see the code

    It does not have a TuyaMCU and is using I2C to communicate with the Temp+Humidity sensor CHT8305.

    This device requires deep sleep to run on batteries longer than few days.
    Please see related topics for details:
    https://www.elektroda.com/rtvforum/topic4025593.html
    https://www.elektroda.com/rtvforum/topic3945688.html
    https://www.elektroda.com/rtvforum/find.php?q=CHT8305

    I have flashed esphome and aside from I2C, and deep-sleep, everything else works.
    
    esphome:
      name: upk2esphome-bk7231n
    
    bk72xx:
      board: cbu
    
    logger:
      baud_rate: 0
    
    # tuya:
    
    web_server:
    
    captive_portal:
    
    mdns:
    
    external_components:
      - source: /soft_i2c
    
    #api:
    #  password: ""
    #  reboot_timeout: 0s
    
    ota:
      password: ""
    
    wifi:
      ssid: !secret wifi_ssid
      password: !secret wifi_password
      use_address: 192.168.1.32
      fast_connect: true
      ap:
    
    mqtt:
      broker: mqtt.hlab.host
    
    button:
      - platform: restart
        name: Restart
    
    debug:
      update_interval: 30s
    
    text_sensor:
      - platform: debug
        reset_reason:
          name: Reset Reason
      - platform: libretiny
        version:
          name: LibreTiny Version
    sensor:
      - platform: uptime
        name: Uptime
        update_interval: 15s
        id: uptime_sensor
      - platform: adc
        pin: P23
        name: "Battery Level"
        update_interval: 15s
        on_value:
          then:
            - mqtt.publish_json:
                topic: temp_sensor
                payload: |-
                  root["batt"] = x;
                  root["uptime"] = id(uptime_sensor).state;
                  root["alert"] = id(alert).state;
    
    uart:
      rx_pin: RX1
      tx_pin: TX1
      baud_rate: 115200
    
    light:
      - platform: binary
        name: "Status"
        output: status_output
    
    output:
      - id: status_output
        platform: gpio
        pin: P16
    
    binary_sensor:
      - platform: gpio
        pin: 
          number: P14
          inverted: true
        name: "Button"
      - platform: gpio
        id: alert
        pin: 
          number: P7
          inverted: true
        name: "Alert"
    


    I hope this information is sufficient to 'port'/support openbeken for this device.

    Let me know if i can help any other way.

    Cool? Ranking DIY
    About Author
    dmcbeing
    Level 3  
    Offline 
    dmcbeing wrote 5 posts with rating 3. Been with us since 2024 year.
  • ADVERTISEMENT
  • #2 20906573
    p.kaczmarek2
    Moderator Smart Home
    I will edit your first post to add more information, but first of all, your current config is incorrect.
    You can't just:
    Quote:

    I flashed and aside from I2C, and deep-sleep, everything else works.

    This device must have deep sleep, otherwise it will drain batteries really, really fast. I can help you step by step with configuration, flash OBK to get it running.
    Helpful post? Buy me a coffee.
  • #3 20907778
    johnypean
    Level 4  

    I have it working quite well. I have gathered information from multiple threads about these sensors here. Even the battery is working and showing up in HASS.

    Code: JSON
    Log in, to see the code


    autoexec.bat:

    // Initial led blink
    SetChannel 1  1
    // hold button to get into safe mode
    // addEventHandler OnHold 20 SafeMode
    PowerSave
    mqtt_broadcastInterval 1
    mqtt_broadcastItemsPerSec 5
    Battery_Setup 2000 3000 1.87 2400 4096
    Battery_Measure
    startDriver CHT8305
    // HADiscovery on every boot doesn't seem necessary
    // scheduleHADiscovery
    SetChannel 1  0
    waitFor WiFiState 4
    // go to deep sleep if mqtt can't connect
    addRepeatingEventID 30 -1 1337 DeepSleep 120
    waitFor MQTTState 1
    cancelRepeatingEvent 1337
    publishChannels
    // Data sent led blink
    SetChannel 1  1
    delay_ms 100
    SetChannel 1  0
    // additional delay to get a chance to manually connect to device, everything else is already done
    delay_s 10
    // Deep sleep led blink
    SetChannel 1  1
    delay_ms 100
    SetChannel 1  0
    // Deep sleep for 30 mins
    DeepSleep 1800


    Flags:
    2,10,27,35,37

    Flag 35- Deactivate avty_t solved the problem with HASS showing unavailable on the last collected values during sleep periods.

    Can't get the button to wake up the device. If there was a possibility to use DeepSleep and PinDeepSleep simultaneously, it could be used to wake up and leave the device online. Now, pulling and reinserting the battery gives 10s to edit the autoexec.bat and remove the DeepSleep line. The additional 10s delay probably halves battery life, since init, wifi, and mqtt take around 10s prior.
    I'm thinking if there is a way to read mqtt message and disable DeepSleep if a specific message is received on the next wakeup. Maybe checking the button on boot and disabling DeepSleep would be used to get rid of the 10s delay. Haven't found a way how to do that.
  • ADVERTISEMENT
  • #4 20913628
    dmcbeing
    Level 3  
    Thanks for the replies @p.kaczmarek2 and @johnypean.

    I got stuck at flashing as the GUIFlashTool would not work in Linux ... it would freeze when writing the first page after erasing all flash blocks.
    Installing windows and flashing from there finally worked so I now have two sensors flashed with OpenBK.

    I took the configuration from @johnypean and it sort of works ...

    One of the nodes reports correct numbers (might need small offset/calibration but close enough)
    The other node however reports incorrect values, specifically negative values.

    
    Good data:
    Info:SENSOR:DRV_CHT8304_readEnv: Temperature:21.812500C Humidity:56.141357%
    Info:SENSOR:DRV_CHT8304_readEnv: Temperature:21.781250C Humidity:55.994873%
    Info:SENSOR:DRV_CHT8304_readEnv: Temperature:21.875000C Humidity:56.187133%
    Info:SENSOR:DRV_CHT8304_readEnv: Temperature:21.781250C Humidity:55.762939%
    Info:SENSOR:DRV_CHT8304_readEnv: Temperature:21.781250C Humidity:55.936889%
    Info:SENSOR:DRV_CHT8304_readEnv: Temperature:21.687500C Humidity:55.381469%
    Bad data:
    Info:SENSOR:DRV_CHT8304_readEnv: Temperature:-26.251430C Humidity:53.827342%
    Info:SENSOR:DRV_CHT8304_readEnv: Temperature:-26.231288C Humidity:31.952011%
    Info:SENSOR:DRV_CHT8304_readEnv: Temperature:-26.231288C Humidity:31.952011%
    Info:SENSOR:DRV_CHT8304_readEnv: Temperature:-26.191005C Humidity:88.202865%
    Info:SENSOR:DRV_CHT8304_readEnv: Temperature:-26.170862C Humidity:66.327537%
    Info:SENSOR:DRV_CHT8304_readEnv: Temperature:-26.150720C Humidity:69.452583%
    Info:SENSOR:DRV_CHT8304_readEnv: Temperature:-26.130578C Humidity:31.170747%
    Info:SENSOR:DRV_CHT8304_readEnv: Temperature:-26.090295C Humidity:24.920652%
    


    Funnily enough, the 'good' node also initially reported negative numbers but it then 'fixed' itself although I don't remember doing anything for it ...
  • ADVERTISEMENT
  • #5 20913633
    p.kaczmarek2
    Moderator Smart Home
    Are the device configs the same? Is the device hardware the same for both devices?
    Helpful post? Buy me a coffee.
  • #6 20913682
    dmcbeing
    Level 3  

    Yes, I copied and pasted all settings and autoexec.bat from the first device I flashed that reports correct values.
  • #7 20918364
    dmcbeing
    Level 3  
    I played a bit with the sensors in the previous days and redid my configuration, and now all sensors return valid readings.
    I also started playing with the deepsleep as @p.kaczmarek2 recommended.
    However i no longer get Battery voltage from mqtt, even though the webui shows correct values and am not sure why that is.

    My flags are 1092 and this is my autoexec.bat:

    
    addRepeatingEventID 100 -1 666 DeepSleep 80 // For testing, after testing i will increse DeepSleep to 15mins and decrease the interval to ~40s
    mqtt_broadcastItemsPerSec 20
    mqtt_broadcastInterval 1
    // SetChannel 2 1
    PowerSave 1
    
    startDriver CHT8305
    Battery_Cycle 1
    Battery_Setup 1000 3300 2
    delay_s 1
    
    // Schedule after deepsleep - Never
    CHT_Cycle 100
    Battery_Cycle 100
    
    waitFor MQTTState 1
    publishChannels
    // SetChannel 2 0
    


    Before i would get battery values on the 'temp1/voltage/get' topic (temp1 was the node name), but now no messages get posted at that topic ...
  • #8 20922847
    johnypean
    Level 4  
    If you activated Flag 36 - "[DRV] Deactivate Autostart of all drivers", you have to add
    startDriver Battery
    to autoexec.bat
    Had the same happen.
  • #9 20925404
    dmcbeing
    Level 3  
    @johnypean Nope, i don't have that enabled

    I have the following enabled:

    Flag 2 - [MQTT] Broadcast self state every N (def: 60) seconds (delay configurable by 'mqtt_broadcastInterval' and 'mqtt_broadcastItemsPerSec' commands)
    Flag 6 - [BTN] Instant touch reaction instead of waiting for release (aka SetOption 13)
    Flag 10 - [MQTT] Broadcast self state on MQTT connect
    Flag 37 - [WiFi] Quick connect to WiFi on reboot (TODO: check if it works for you and report on github)

    The most relevant i think is flag 10, which i guess should send the battery status once mqtt works, bu in my case it does not seem to do so.

    Fun fact ... i tried to verify the flags value (1092) and did (1<<2)+(1<<6)+(1<<10)+(1<<37) and the result is different (137438954564), but this is simply because the (1<<37) is beyond the 32-bit limit, not sure if it counts as a bug :D
  • #10 20935068
    nacxoffw
    Level 5  
    Hi!
    Thanks a lot about this post and the information given.

    I have one of this PCB with CBU chip.

    Here a resume about my configuration:
    Screenshot of the OpenBK7231N_HumedadAle user interface showing temperature, humidity, battery level, and other details. Screenshot showing port configuration for a PCB board with CBU chip. Screenshot of script code with configuration information about sleep mode.
    Flags to 1092

    Logs about MQTT:
    
    Info:MAIN:Time 97, idle 59042/s, free 75040, MQTT 1(1), bWifi 1, secondsWithNoPing 31, socks 2/38 POWERSAVE
    Info:MQTT:Publishing val zzzzzz to homeassistant/humedadAle/ssid retain=0
    Info:MQTT:Publishing val 2 to homeassistant/humedadAle/sockets retain=0
    Info:MQTT:Publishing val -54 to homeassistant/humedadAle/rssi retain=0
    Info:MQTT:Publishing val 97 to homeassistant/humedadAle/uptime retain=0
    Info:MQTT:Publishing val 75040 to homeassistant/humedadAle/freeheap retain=0
    Info:MQTT:Publishing val 192.168.zz.zz to homeassistant/humedadAle/ip retain=0
    Info:MQTT:Channel has changed! Publishing 0 to channel 0 
    Info:MQTT:Publishing val 0 to homeassistant/humedadAle/0/get retain=0
    Info:MQTT:Channel has changed! Publishing 0 to channel 1 
    Info:MQTT:Publishing val 0 to homeassistant/humedadAle/1/get retain=0
    Info:MQTT:Channel has changed! Publishing 218 to channel 2 
    Info:MQTT:Publishing val 218 to homeassistant/humedadAle/2/get retain=0
    Info:MQTT:Channel has changed! Publishing 57 to channel 3 
    Info:MQTT:Publishing val 57 to homeassistant/humedadAle/3/get retain=0
    Info:MQTT:Channel has changed! Publishing 0 to channel 5 
    Info:MQTT:Publishing val 0 to homeassistant/humedadAle/5/get retain=0
    Info:MQTT:Channel has changed! Publishing 0 to channel 6 
    Info:MQTT:Publishing val 0 to homeassistant/humedadAle/6/get retain=0
    Info:MAIN:Time 98, idle 78157/s, free 75040, MQTT 1(1), bWifi 1, secondsWithNoPing 32, socks 2/38 POWERSAVE
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic homeassistant/humedadAle/0/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic homeassistant/humedadAle/1/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic homeassistant/humedadAle/2/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic homeassistant/humedadAle/3/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic homeassistant/humedadAle/5/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic homeassistant/humedadAle/6/get
    


    And a problem like you, the battery is nor publishing... have you solved it @dmcbeing?
    On the other hand... any chance to make phisical button decrease sleep time or stop it to TESTING?
  • #11 20935801
    nacxoffw
    Level 5  
    Solved!!

    Setting Channel 4 for gpio of configured battery send MQTT data.
    View of the OpenBK7231N app screen displaying device information and sensor data.

    Data appear as unavailable in sleep time is solved after enable flag option 35 and remove MQTT item and reasync in HomeAssistant.

    Futhermore the physical button question left!!! Please help, think is a good idea to sabe battery.
  • #12 21015579
    crispybeken
    Level 2  
    I've got one of these devices, too. But I can't find a template in the WebApp. Could you please post your template here?
  • #13 21057398
    mcexmltv
    Level 2  
    Newbie here, anyone could be kind and post a how to, or at least post the files.
    Thanks in advance.
  • #14 21057906
    p.kaczmarek2
    Moderator Smart Home
    Hello @mcexmltv , what kind of information do you need exactly? Are you asking about device configuration, or about flashing?
    For flashing, please see:
    https://github.com/openshwprojects/BK7231GUIFlashTool
    You can also check our generic flashing guides on Youtube:
    https://www.youtube.com/playlist?list=PLzbXEc2ebpH0CZDbczAXT94BuSGrd_GoM
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #15 21066183
    mcexmltv
    Level 2  
    Thanks @p.kaczmarek2 ,
    finally had some time to do some research.
    Here is what I am looking for.
    I have ESPHome installed. How do I flash openBK OTA or do I have to use UART?
    If OTA is possible what are the steps?
    Thanks
  • #16 21066328
    p.kaczmarek2
    Moderator Smart Home
    They have OTA locked against flashing our/Tuya RBL format but someone has found a work around (converted files...):
    https://github.com/BenJamesAndo/OpenBeken_uf2_firmware

    Let me know how it works for you, I will be happy to help you futher.
    Helpful post? Buy me a coffee.
  • #17 21354384
    psyko_chewbacca
    Level 6  
    >>20904515

    Hi,

    where do I find this "soft_i2c" external component?
    I have an i2c device I'd like to interface to a bk7231n in ESPHome.

    Thanks!

Topic summary

The discussion centers on the Tuya WiFi Temperature and Humidity Sensor featuring a BK7231N CBU chip and a blue PCB without TuyaMCU. Users share experiences with flashing the device using OpenBK firmware, highlighting challenges such as GUIFlashTool freezing on Linux and successful flashing on Windows. Configuration details include pin assignments for battery relay, button, LED, and CHT8305 sensor lines, along with an autoexec.bat script implementing deep sleep to conserve battery life and MQTT communication for sensor data and battery voltage reporting. Issues with inconsistent sensor readings and missing battery voltage MQTT messages were resolved by adjusting device flags (notably flag 35 for MQTT data during sleep) and ensuring the Battery driver is started if autostart is disabled. Users also discuss MQTT broadcast intervals, power-saving modes, and calibration offsets. Additional inquiries address OTA flashing limitations due to locked firmware and references to alternative flashing methods using converted firmware files. The thread includes requests for device templates and guidance on interfacing I2C devices with BK7231N in ESPHome, with a mention of the "soft_i2c" external component. Overall, the conversation provides practical insights into firmware flashing, configuration, power management, and MQTT integration for this specific Tuya sensor hardware.
Summary generated by the language model.
ADVERTISEMENT