logo elektroda
logo elektroda
X
logo elektroda

Configuring PIR Sensor with CB3S Module and Tuya Chip: Step-by-Step Guide

vitya123 1581 4
ADVERTISEMENT
  • Here is a config guide for a PIR sensor that is not yet on the LIST.
    This is the product pic borrowed from the marketplace:
    White PIR motion sensor with a smartphone app and Tuya and Alexa logos.
    after removing the PCB from the case this is what we find:
    Image of the PIR sensor PCB with the SOIC chip removed. PIR sensor module with visible components on the PCB, including the CB3S module and PIR lens.

    The UART lines (Tx and Rx) we use for programming the CB3S module are shared by the CB3S module and the Tuya chip (the 8 pin SOIC chip at the top left). This means we need to free these pins temporarily. This can be done in a few ways:

    1. Remove the SOIC chip temporarily
    2. Remove the CB3S module temporarily
    3. Break the Rx/Tx lines temporarily

    I opted for the first option and removed the SOIC chip with hot air. I also soldered on a few wires to strategically important places:
    CB3S module with attached wires on a PCB.
    Red: 3.3V, Black: GND, White: Monitor/Debug

    Close-up of a PCB with a CB3S module and PIR sensor, showing soldered wires.
    Blue: Tx, Green: Rx. You can also see the SOIC chip removed in the top left corner.

    Note: The 3.3V can be connected to the battery terminal, but the GND must be connected directly to the CB3S module, otherwise it will reset every few seconds if you don't press the button every few seconds...

    Using the flasher utility is straightforward. Make a backup, then upload the new firmware.
    This is the Autoexec.bat file I use (with help of this forum):

    startDriver TuyaMCU
    startDriver tmSensor
    setChannelType 1 readonly
    //Link dpid al canal 1
    linkTuyaMCUOutputToChannel 1 val 1
    setChannelType 3 readonly
    //Link dpid al canal 3
    linkTuyaMCUOutputToChannel 3 val 3
    SetChannel 1 2


    No special configuration is needed, just change the MQTT settings and any flags you need and that's it:
    Screenshot of OpenBK7231N software system console.

    At the end don't forget to remove the temporary wires and reattach the 8 pin SOIC chip.

    Finished!

    Here is a more detailed guide: https://diy.viktak.com/2025/02/tuya-pir-sensor-conversion-to-open-source-walkthrough.html

    Cool? Ranking DIY
    About Author
    vitya123
    Level 6  
    Offline 
    vitya123 wrote 51 posts with rating 10, helped 1 times. Been with us since 2024 year.
  • ADVERTISEMENT
  • #2 21359258
    @GUTEK@
    Level 31  
    Thanks for the description.
    I bought this sensor a few months ago and somehow it's been lying around, I had no idea where to use it.
    I reprogrammed it as described, it works fine.
    In HA it added me two entities 1 and 3. Entity 1 is motion detection, it takes the value 0 when it detects motion and 1 when there is no motion.
    What I don't know is what entity 3 means, it has a value of 2. Is it the battery charge level?
  • ADVERTISEMENT
  • #3 21359581
    vitya123
    Level 6  
    I'm not sure. I don't have it with me right now, so I can't check, but I think it is the "reset" button on it. Can you please try and confirm this?
  • ADVERTISEMENT
  • #4 21359673
    spin55
    Level 17  
    @GUTEK@ wrote:
    What I don't know is what entity 3 means, it has a value of 2. Is it the battery charge level?


    Yes, it is the battery value in Enum format and it takes three possible values: 0,1,2, which the script models to Low,Mid,High format if you modify it like this:

    startDriver TuyaMCU
    startDriver tmSensor
    setChannelType 1 readonly
    //Link dpid al canal 1
    linkTuyaMCUOutputToChannel 1 val 1
    
    setChannelType 3 ReadOnlyLowMidHigh
    setChannelLabel 3 BatteryLevel 
    //Link dpid al canal 3
    linkTuyaMCUOutputToChannel 3 val 3
    
    SetChannel 1 2


    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/commands-extended.md
  • #5 21400401
    @GUTEK@
    Level 31  
    I'm a bit late writing back. I set the detector like this:

    flags: 7, 10, 19, 35, 37

    autoexec.bat file:
    startDriver TuyaMCU
    startDriver tmSensor
    setChannelType 1 Motion_n
    setChannelLabel 1 Motion
    linkTuyaMCUOutputToChannel 1 val 1
    setChannelType 3 ReadOnlyLowMidHigh
    setChannelLabel 3 BatteryLevel
    linkTuyaMCUOutputToChannel 3 enum 3
    SetChannel 1 2
    .
    This allows the HA to detect the detector as a motion detector. An entity called Motion. And the battery level has three states Low/Medium/High, here unfortunately the Battery entity is not detected as a battery by HA, but this doesn't interfere with anything.
ADVERTISEMENT