logo elektroda
logo elektroda
X
logo elektroda

[bk7231n / cbu / mcu] Milfra MFA05F Motion Sensor Light Switch, teardown and dpId

gokeeper 2970 38
ADVERTISEMENT
  • #1 21055031
    gokeeper
    Level 4  
    I recently purchased a few milfra mfa05f motion sensor light switches, they use CBU board with tuya mcu.

    All issued fixed now! Here are some photos, screenshots, dpids and autoexect.bat

    MILfra MFA05F motion sensor light switch. Motion sensor light switch model MFA05F with connected wires. Close-up image of the inside of a light switch enclosure. PCB board with electronic components and connected wires Close-up of an electronic board above a motion sensor light switch. Circuit board with mounted electronic components and a button. Smart switch packaging with Google Assistant and Amazon Alexa logos. Photo of MFA05F light switch box with Wi-Fi option checked. MFA05F motion sensor light switch interface on a phone screen with PIR, ON, timing, and setting icons. Screenshot of motion sensor light switch settings in a mobile app.


    dpIds

    
    1
    开关1
    switch_1	Boolean	
    "{true,false}"
    
    14
    上电状态设置
    relay_status	Enum	
    {
      "range": [
        "off",
        "on",
        "memory"
      ]
    }
    
    15
    指示灯状态设置
    light_mode	Enum	
    {
      "range": [
        "none",
        "relay",
        "pos"
      ]
    }
    
    43
    光敏开关
    cds_switch	Boolean	
    "{true,false}"
    
    44
    光敏状态
    cds_state	Enum	
    {
      "range": [
        "on",
        "off"
      ]
    }
    
    
    45
    光照度检测阀值
    cds_threshold	Enum	
    {
      "range": [
        "default",
        "now"
      ]
    }
    
    46
    感应开关
    switch_pir	Boolean	
    "{true,false}"
    
    47
    感应状态
    pir_state	Enum	
    {
      "range": [
        "on",
        "off"
      ]
    }
    
    
    48
    感应灵敏度
    pir_sensitivity	Enum	
    {
      "range": [
        "low",
        "middle",
        "high"
      ]
    }
    
    49
    感应延时
    pir_delay	Integer	
    {
      "unit": "s",
      "min": 5,
      "max": 3600,
      "scale": 0,
      "step": 1
    }
    
    101
    PIR结束时间设置
    appointment_time	Integer	
    {
      "unit": "min",
      "min": 0,
      "max": 1440,
      "scale": 0,
      "step": 1
    }
    
    102
    PIR开始时间设置
    target_time	Integer	
    {
      "unit": "min",
      "min": 0,
      "max": 1440,
      "scale": 0,
      "step": 1
    }
    
    103
    定时
    timer	Raw	
    {
      "maxlen": 128
    }
    


    device status from tuya website

    
    {
        "result": {
          "properties": [
            {
              "code": "switch_1",
              "custom_name": "",
              "dp_id": 1,
              "time": 1713732560211,
              "value": true
            },
            {
              "code": "relay_status",
              "custom_name": "",
              "dp_id": 14,
              "time": 1713727545549,
              "value": "off"
            },
            {
              "code": "light_mode",
              "custom_name": "",
              "dp_id": 15,
              "time": 1713727545554,
              "value": "relay"
            },
            {
              "code": "cds_switch",
              "custom_name": "",
              "dp_id": 43,
              "time": 1713730746434,
              "value": false
            },
            {
              "code": "cds_state",
              "custom_name": "",
              "dp_id": 44,
              "time": 1713727545656,
              "value": "on"
            },
            {
              "code": "cds_threshold",
              "custom_name": "",
              "dp_id": 45,
              "time": 1713730823352,
              "value": "default"
            },
            {
              "code": "switch_pir",
              "custom_name": "",
              "dp_id": 46,
              "time": 1713727936883,
              "value": true
            },
            {
              "code": "pir_state",
              "custom_name": "",
              "dp_id": 47,
              "time": 1713727545679,
              "value": "on"
            },
            {
              "code": "pir_sensitivity",
              "custom_name": "",
              "dp_id": 48,
              "time": 1713730849083,
              "value": "middle"
            },
            {
              "code": "pir_delay",
              "custom_name": "",
              "dp_id": 49,
              "time": 1713727545700,
              "value": 5
            },
            {
              "code": "appointment_time",
              "custom_name": "",
              "dp_id": 101,
              "time": 1713727545856,
              "value": 1439
            },
            {
              "code": "target_time",
              "custom_name": "",
              "dp_id": 102,
              "time": 1713727545868,
              "value": 60
            },
            {
              "code": "timer",
              "custom_name": "",
              "dp_id": 103,
              "time": 1713727546706,
              "value": "AA=="
            }
          ]
        },
        "success": true,
        "t": 1713732562424,
        "tid": "a1b5376b002011efa39e7a9cb4325afa"
      }
    


    autoexec.bat

    
    //ntp
    startDriver NTP
    ntp_setServer 1.ca.pool.ntp.org
    
    startDriver TuyaMCU
    tuyaMcu_sendCurTime
    
    // set TuyaMCU baud rate
    //tuyaMcu_setBaudRate 115200
    // emulate being connected to cloud
    tuyaMCU_defWiFiState 4
    
    cleario
    
    //main relay
    setChannelType 1 Toggle
    linkTuyaMCUOutputToChannel 1 1 1
    setChannelLabel 1 relay
    
    //brightless sensor switch
    setChannelType 2 Toggle
    linkTuyaMCUOutputToChannel 43 1 2
    setChannelLabel 2 cbs
    //enable cbs sensor
    //setChannel 2 1
    
    //motion sensor
    setChannelType 3 Toggle
    linkTuyaMCUOutputToChannel 46 1 3
    setChannelLabel 3 pir
    //enable pir sensor
    //setChannel 3 1
    
    //motion sensor delay
    linkTuyaMCUOutputToChannel 49 2 4
    setChannelType 4 TextField
    setChannelLabel 4 PIR-delay
    //set motion sensor delay to 120s
    setChannel 4 120
    
    //motion sensor sensitivity
    linkTuyaMCUOutputToChannel 48 4 5
    setChannelType 5 LowMidHigh
    setChannelLabel 5 PIR-sensitivity
    //set motion sensor sensitivity to Mid
    setChannel 5 1
    
    //set status led to white while relay is off, red while relay is on
    tuyaMcu_sendState 15 4 1
    
    //set pir start time
    tuyaMcu_sendState 102 2 1
    
    //set pir end time
    tuyaMcu_sendState 101 2 1440
    
  • ADVERTISEMENT
  • #2 21058675
    p.kaczmarek2
    Moderator Smart Home
    Are you sure that you're mapping this to channel with a correct variable type?

    Have you tried to use tuyaMcu_sendState command to set state directly, without doing the channel mapping?
    Helpful post? Buy me a coffee.
  • #3 21062630
    gokeeper
    Level 4  
    Thanks for the reply, I tried tuyaMcu_sendState but same result. However, I found out as soon as I configured mqtt server, the status LED / DPid 15 works as expected. I have tuyaMCU_defWiFiState 4 in autoexec.bat all the time, no idea what's the connection with mqtt server.
  • #4 21062761
    p.kaczmarek2
    Moderator Smart Home
    Can you share your full autoexec.bat?

    The tuyaMCU_defWiFiState 4 can't just randomly work or not, are you sure that you are saving and either reexecuting autoexec.bat or restarting your device?

    Does the device fix itself after you power it on and off?
    Helpful post? Buy me a coffee.
  • #5 21062811
    gokeeper
    Level 4  
    It isn't randomly work or not, it suddenly stopped working. I just found out it's because I didn't set local time, since the pir sensor will only work at centain time of the day (dpId 102 and 101). All good after I add tuyaMcu_sendCurTime.

    full autoexec.bat
    
    //ntp
    startDriver NTP
    ntp_setServer 1.ca.pool.ntp.org
    
    startDriver TuyaMCU
    tuyaMcu_sendCurTime
    
    // set TuyaMCU baud rate
    //tuyaMcu_setBaudRate 115200
    // emulate being connected to cloud
    tuyaMCU_defWiFiState 4
    
    cleario
    
    //main relay
    setChannelType 1 Toggle
    linkTuyaMCUOutputToChannel 1 1 1
    setChannelLabel 1 relay
    
    //brightless sensor switch
    setChannelType 2 Toggle
    linkTuyaMCUOutputToChannel 43 1 2
    setChannelLabel 2 cbs
    //enable cbs sensor
    //setChannel 2 1
    
    //motion sensor
    setChannelType 3 Toggle
    linkTuyaMCUOutputToChannel 46 1 3
    setChannelLabel 3 pir
    //enable pir sensor
    //setChannel 3 1
    
    //motion sensor delay
    linkTuyaMCUOutputToChannel 49 2 4
    setChannelType 4 TextField
    setChannelLabel 4 PIR-delay
    //set motion sensor delay to 120s
    setChannel 4 120
    
    //motion sensor sensitivity
    linkTuyaMCUOutputToChannel 48 4 5
    setChannelType 5 LowMidHigh
    setChannelLabel 5 PIR-sensitivity
    //set motion sensor sensitivity to Mid
    setChannel 5 1
    
    //set status led to white while relay is off, red while relay is on
    tuyaMcu_sendState 15 4 1
    
    //set pir start time
    tuyaMcu_sendState 102 2 1
    
    //set pir end time
    tuyaMcu_sendState 101 2 1440
    
    
  • #6 21062891
    p.kaczmarek2
    Moderator Smart Home
    I see, is everything working correctly for you now? You may also want to enable TuyaMCU queue in the flags.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #7 21063555
    gokeeper
    Level 4  

    p.kaczmarek2 wrote:
    I see, is everything working correctly for you now?

    Yes, feel free to add the data to the device database.

    p.kaczmarek2 wrote:
    You may also want to enable TuyaMCU queue in the flags.

    Will do, thanks!
  • #8 21063862
    divadiow
    Level 35  
    gokeeper wrote:
    Yes, feel free to add the data to the device database.


    please post your device template from web app

    Screenshot from a web application showing device configuration.
  • ADVERTISEMENT
  • #9 21063865
    gokeeper
    Level 4  

    divadiow wrote:
    gokeeper wrote:
    Yes, feel free to add the data to the device database.


    please post your device template from web app

    Screenshot from a web application showing device configuration.

    This is a mcu device, I have included autoexec.bat in OP.
  • #10 21063870
    divadiow
    Level 35  
    indeed but the template makes adding the device to device list easier
  • ADVERTISEMENT
  • Helpful post
    #11 21063907
    gokeeper
    Level 4  

    Got it, here it is

    
    {
      "vendor": "Tuya",
      "bDetailed": "0",
      "name": "Milfra MFA05F Motion Sensor Light Switch",
      "model": "MFA05F",
      "chip": "BK7231N",
      "board": "CBU",
      "flags": "1024",
      "keywords": [
        "Milfra",
        "MFA05F",
        "Switch",
        "Motion Sensor",
        "BK7231N",
        "CBU",
        "MCU"
      ],
      "pins": {},
      "command": "",
      "image": "https://obrazki.elektroda.pl/9024105700_1714244652.jpg",
      "wiki": "https://www.elektroda.com/rtvforum/viewtopic.php?p=21063870#21063870"
    }
    

  • #13 21064282
    p.kaczmarek2
    Moderator Smart Home
    Thank you, the PR is now accepted. The device should be soon live at:
    https://openbekeniot.github.io/webapp/devicesList.html
    We have 565 devices currently, but I would love to get to 600 soon!
    Helpful post? Buy me a coffee.
  • #14 21092088
    roywalker777
    Level 3  

    @gokeeper Can you explain how you flashed this? Did you have to desolder the CBU? I can't get mine to connect using the TX/RX, GND, and 3.3v on the connector. Don't suppose you made/can make a video?
  • #16 21092594
    roywalker777
    Level 3  
    Same as yours... was trying to flash via serial.
  • #17 21153165
    DexEdson
    Level 4  
    Has anyone been able to flash this via serial without removing the chip? I received one that has firmware 2.1.17 so unfortunately I can't flash with cloudcutter. I have been trying to use ltchiptool, but it never connects to the chip. Connecting CEN to GND for 1/2 second seems to reset it since the light blinks, but no matter how many times I do it, ltchiptool never connects.
  • #18 21153171
    p.kaczmarek2
    Moderator Smart Home
    This is TuyaMCU device. You can't really flash it as it is. You need to either remove the WiFi module, or remove the MCU, or cut the connection to MCU.

    Alternatively, if you can, and know how, you can put MCU in the RESET state for the time of the flashing.
    Helpful post? Buy me a coffee.
  • #19 21153263
    DexEdson
    Level 4  
    >>21153171 There is an RST pin, I will try connecting it to GND while flashing.
  • #20 21153264
    p.kaczmarek2
    Moderator Smart Home
    Let us know how it goes. How do you know which pin is MCU RST?
    Helpful post? Buy me a coffee.
  • #21 21154883
    DexEdson
    Level 4  
    >>21153264 It worked! There is a spot labeled 'RST' on the board. I kept it connected to GND during power on. Then I tapped CEN to GND a few times and eventually ltchiptool started flashing.

    I was hoping to be able to read the motion sensor data without triggering the relay, so I could use this switch on a circuit with smart bulbs. Unfortunately everything seems to be hard coded into the MCU. I installed ESPHome and set logging to verbose, but no datapoint is logged for motion detection. I'm still glad I was able to cut the cloud, I'll just have to find a different use for this thing.
  • #22 21155031
    p.kaczmarek2
    Moderator Smart Home
    Is it possible to set PIR sensitivity there?

    Maybe you could just remove the MCU and connect relay and PIR to WiFiModule.

    However, some PIRs have a sensitivity setup via PWM, so maybe you would also need to take care about that...
    Helpful post? Buy me a coffee.
  • #23 21156163
    DexEdson
    Level 4  
    >>21155031 There is a PIR sensitivity setting through the MCU. I wouldn't even need to move the relay... as long as the PIR is disconnected from the MCU and directly accessible from GPIO, the relay can be controlled by automation. But this is getting too complex for me, too bad this version is not as simple as the original MFA05. If anyone knows where to get the original MFA05 with the ESP board, please let me know!!
  • #24 21156232
    p.kaczmarek2
    Moderator Smart Home
    Do you have 2MB flash backup? Maybe there is a dpID to decouple relay from PIR? There are some dpIDs in the first post, did you check all of them? @divadiow ?
    Helpful post? Buy me a coffee.
  • #25 21156301
    divadiow
    Level 35  
    I can try to confirm existing info/get missing with full firmware backup or config extract.

    OpenBK user interface page displaying device status for Plug, USB1, and USB2.
  • #26 21163009
    ljnett
    Level 2  
    I got it flashed by holding rst to ground. When I try to apply the template it seems to take it but then just goes back to default. I updated autoexc.bat and then get the three switches as shown above, but pir does not appear to work. Can toggle the main relay just fine. Suggestions on what I am doing wrong?
  • #27 21163054
    p.kaczmarek2
    Moderator Smart Home
    So what is your autoexec.bat now? If relays are working, then communication must be working. Maybe you need to send a query state every few seconds?
    Helpful post? Buy me a coffee.
  • #28 21164315
    ljnett
    Level 2  
    I used the autoexec.bat from the post above. It just appears PIR sensor and light sensor are not working. The relay toggles if I push the switch button or toggle it from the browser. I'm thinking I may just have a defective unit as I never tried it before flashing. If I can get the sensor working, I would also like to disconnect the relay from it.
  • #29 21177153
    p.kaczmarek2
    Moderator Smart Home
    Maybe TuyaMCU expects some extra data, like setting the sensitivity of the PIR sensor, at least once in it's lifetime?
    Helpful post? Buy me a coffee.
  • #30 21221857
    roywalker777
    Level 3  
    Did anyone get the PIR sensor to activate? @ljnett It's not defective, I have 2 of them and with Tasmota or ESPhome, they both are like that.

Topic summary

The discussion centers on the Milfra MFA05F motion sensor light switch, which uses a BK7231N chip on a CBU board with a Tuya MCU. Initial issues with device functionality were resolved by configuring the MQTT server and setting local time via the tuyaMcu_sendCurTime command, as the PIR sensor operates only during certain times (DPIDs 101 and 102). The user shared the full autoexec.bat script and device template, which was accepted into the OpenBeken device database. Flashing the device requires holding the MCU reset (RST) pin to ground during power-on to enable serial flashing, as the MCU and WiFi module are tightly integrated. Attempts to separate PIR sensor data from relay control were complicated by hardcoded MCU firmware, with no direct datapoint logging for motion detection in ESPHome or Tasmota. Sensitivity settings exist but require MCU communication. Some users reported intermittent PIR reliability and delays in relay activation. The device template includes key DPIDs for switch, relay status, PIR sensor, and brightness sensor. The community suggests sending periodic state queries and enabling TuyaMCU queue flags for stability. The original MFA05 with an ESP board is noted as simpler to flash and modify, but the MFA05F with BK7231N and Tuya MCU is more complex due to integrated MCU control.
Summary generated by the language model.
ADVERTISEMENT