logo elektroda
logo elektroda
X
logo elektroda

Motion sensor with BK7231N and TuyaMCU battery powered devices protocol

caubergjef57 14073 193
ADVERTISEMENT
  • #181 20643778
    spin55
    Level 17  
    https://www.elektroda.com/rtvforum/topic3937723-180.html#gallery-4

    Delete this because you no longer need it. You already have it in autoexec.bat. We'll take the automation issue in stride later.

    Added after 1 [minutes]:

    First, you have to make sure that everything works well step by step.


    Added after 11 [minutes]:

    If you want an immediate response, it might not be this type of battery device. I have personally verified that Zigbee devices are a much better solution because they respond faster and consume much less. If you want something based on WIFI you will have to use a PIR with a permanent connection to the network and without a TuyaMCU chip.
    Maybe @p.kaczmarek2 can have a more informed opinion on this.
  • ADVERTISEMENT
  • Helpful post
    #182 20645222
    spin55
    Level 17  

    In case you want to play with the device, I leave you these notes that, although they are already discussed throughout the thread, can help to focus the issue.

    If you configure the Realterm Display tab as I indicated above, you will see your Rx information like this:

    Motion sensor with BK7231N and TuyaMCU battery powered devices protocol

    There you can see a complete cycle from when the power is connected until it enters pairing mode by long pressing the button.

    And you can see the changes if you monitor channel 1 on MQTT in Home Assistant (HA):

    Motion sensor with BK7231N and TuyaMCU battery powered devices protocol

    To know the Tuya protocol for battery powered devices:

    https://developer.tuya.com/en/docs/iot/tuyacl...niversalserialaccessprotocol?id=K95afs9h4tjjh

    And to make it easier for you to interpret those commands:

    https://www.elektroda.com/rtvforum/topic3970199.html

    Greetings
  • #183 20645366
    dmarcondescctv
    Level 6  
    Hi Spin55,

    Thanks for the 2 posts. I have removed the lines that you mentioned. No problems there.

    With the device, it may not be the correct hardware for my application, as you mentioned.

    Sometimes, I see a movement detection, and it never gets to HA. Funny enough, when I'm monitoring with Realterm, it works 100% :)

    Happy to hear your or someone else's suggestion for a PIR.

    I was looking for some BLE PIR, which sends a beacon when it detects movement. So that I could get it on my ESP32 BLE tracker.

    Anyways, thanks for your inputs, and I will keep playing with some settings.

    BTW, just to help someone else that finds this post: To get PIR on the "pairing" mode, I click on the button 5 times, then press and hold for 6 seconds. This usually works well and keeps the PIR connected for a long time.
  • ADVERTISEMENT
  • #184 20645367
    p.kaczmarek2
    Moderator Smart Home

    We're working on a YouTube presentation with my door sensor and the device that @spin55 sent, but we are very busy, so we don't know when it will be released. Please follow our IoT guides Elektroda channel to get a notification when it's released:
    https://www.youtube.com/@elektrodacom
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #185 20646690
    spin55
    Level 17  
    dmarcondescctv wrote:
    Happy to hear your or someone else's suggestion for a PIR.


    https://www.elektroda.com/rtvforum/topic3975583.html#gallery-35

    Motion sensor with BK7231N and TuyaMCU battery powered devices protocol
    https://es.aliexpress.com/item/10050047382480..._id=202307080643418529150435676320008874913_4

    I have carried out a test with this PIR that is powered by 3xAAA batteries and has a CBU module. I have removed the batteries and have fed it with 5V. I have removed autoexec.bat and changed the pinout:

    Code: JSON
    Log in, to see the code


    You can leave only "16" and "26", the rest is left over since it will be permanently powered.

    After intrusion detection it takes about 35 seconds to reset the sensor compared to 1:20 minutes for the NEO, but it can be reduced to 2 seconds with a small modification (although I haven't tested it). Once reset, detection is fast because it is always online. Something similar happens with door sensors.

    I have experimented with this model because it is what I have at hand, but anyone that does not have a TuyaMCU chip and is powered by microUSB at 5V will work.

    This is in terms of a cheap Wi-Fi solution, but the ideal is to use battery-powered Zigbee devices because the consumption is much lower, it is faster and they have other obvious advantages, but that is another topic.

    Grettings
  • #186 20646772
    p.kaczmarek2
    Moderator Smart Home
    @spin55 my guide for that one (non-TuyaMCU version) is almost ready:
    Motion sensor with BK7231N and TuyaMCU battery powered devices protocol
    I will post it soon, first in Polish, then English:
    Motion sensor with BK7231N and TuyaMCU battery powered devices protocol
    Helpful post? Buy me a coffee.
  • #187 20652350
    dmarcondescctv
    Level 6  

    Thanks @spin55, I will have a look and maybe order one to play with it.
  • #188 20652417
    p.kaczmarek2
    Moderator Smart Home
    I have posted some information about that sensor, currently in polish:
    https://www.elektroda.pl/rtvforum/topic3988602.html
    Maybe we will setup English translation soon
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #189 20652618
    spin55
    Level 17  
    dmarcondescctv wrote:
    Thanks @spin55, I will have a look and maybe order one to play with it.


    In case you decide to try it, I have carried out the test under these conditions:

    PIR permanently powered at 5V.

    Pin Configuration:

    "pins": {
    "16": "dInput;1",
    "26": "LED;2"
    }


    autoexec.bat configuration:

    setChannel 1 0
    addChangeHandler Channel1 == 1 backlog setChannel 2 1; setChannel 2 0;


    Binary_sensor PIR configuration:

    mqtt:
      binary_sensor:
        - unique_id: "OpenBK7231N_FF858113_binary_PIR"
          name: "Motion sensor_5"
          state_topic: "obkFF858103/1/get"
          qos: 1
          payload_on: 1
          payload_off: 0


    Sensor PIR configuration:

    mqtt:
      sensor:
        - unique_id: "OpenBK7231N_FF858103_PIR"
          name: "PIR_5"
          state_topic: "obkFF858103/1/get"
          value_template: '{{ value | replace("0", "Idle") | replace("1", "Activated") }}'



    Automations.yaml configuration:

    - id: '1688763517168'
      alias: PIR_5 light on test
      description: ''
      trigger:
      - platform: state
        entity_id:
        - sensor.pir_5
        from: Idle
        to: Activated
      condition: []
      action:
      - type: turn_on
        device_id: 95b49c8884f3ae33ab45fd2503ce1552
        entity_id: switch.computer_light_room
        domain: switch
      mode: single
    - id: '1688763517178'
      alias: PIR_5 light off test
      description: ''
      trigger:
      - platform: state
        entity_id:
        - sensor.pir_5
        from: Activated
        to: Idle
      condition: []
      action:
      - type: turn_off
        device_id: 95b49c8884f3ae33ab45fd2503ce1552
        entity_id: switch.computer_light_room
        domain: switch
      mode: single


    Added after 2 [minutes]:

    p.kaczmarek2 wrote:
    I have posted some information about that sensor, currently in polish:
    https://www.elektroda.pl/rtvforum/topic3988602.html
    Maybe we will setup English translation soon


    Very good article, like all the great work you do.

    Congratulations

    By default the PIR takes 33 seconds to reset, but this time can easily be cut to 2 seconds by grounding pin 6.

    Motion sensor with BK7231N and TuyaMCU battery powered devices protocol Motion sensor with BK7231N and TuyaMCU battery powered devices protocol Motion sensor with BK7231N and TuyaMCU battery powered devices protocol Motion sensor with BK7231N and TuyaMCU battery powered devices protocol
  • #190 20652721
    dmarcondescctv
    Level 6  

    Bought one. Hope it is not too hard to flash it :)
    I will find out when it gets here, usually takes many weeks.
    Cheers
  • #191 20843904
    caubergjef57
    Level 4  

    Motion sensor with BK7231N and TuyaMCU battery powered devices protocol

    Hi,

    So what is the end configuration, flags, autoexec.bat and startup commands for this device?

    Greetings, jef
  • #192 20981771
    p4nd0ra
    Level 3  
    Hello,
    I am trying to make this device work but it will not get back online from sleep.
    An extract from the logs:

    Info:CFG:####### Boot Count 66 #######
    Warn:CFG:CFG_InitAndLoad: Correct config has been loaded with 44 changes count.
    Error:CMD:no file early.bat err -2
    Info:GEN:PIN_SetupPins pins have been set up.
    Info:MAIN:Main_Init_Before_Delay done
    Info:MAIN:Main_Init_Delay
    Info:MAIN:Main_Init_Delay done
    Info:MAIN:Main_Init_After_Delay
    Info:MAIN:ssid:xxxx key:xxxxxx
    Info:MAIN:Using SSID [xxxx]
    Info:MAIN:Using Pass [xxxxx.]
    Info:MQTT:MQTT_RegisterCallback called for bT BR_M_S/ subT BR_M_S/+/set
    Info:MQTT:MQTT_RegisterCallback called for bT bekens_n/ subT bekens_n/+/set
    Info:MQTT:MQTT_RegisterCallback called for bT cmnd/BR_M_S/ subT cmnd/BR_M_S/+
    Info:MQTT:MQTT_RegisterCallback called for bT cmnd/bekens_n/ subT cmnd/bekens_n/+
    Info:MQTT:MQTT_RegisterCallback called for bT BR_M_S/ subT BR_M_S/+/get
    Info:CMD:CMD_StartScript: started autoexec.bat at the beginning
    Info:MAIN:Started TuyaMCU.
    Info:MAIN:Started tmSensor.
    Info:GEN:Channel 1 type changed to readonly
    Info:GEN:Channel 4 type changed to readonly
    Info:GEN:Channel 4 type changed to BatteryLevelPercent
    Info:GEN:CHANNEL_Set channel 1 has changed to 2 (flags 0)
    
    Info:MQTT:Channel has changed! Publishing 2 to channel 1 
    Info:MAIN:Main_Init_After_Delay done
    Info:MAIN:Time 1, idle 268548/s, free 73752, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:TuyaMCU:Received: 55 AA 00 01 00 24 7B 22 70 22 3A 22 6C 79 64 77 6F 62 77 79 71 78 69 79 6F 62 39 68 22 2C 22 76 22 3A 22 31 2E 30 2E 35 22 7D 62 
    Info:TuyaMCU:ProcessIncoming[v=0]: cmd 1 (QueryProductInformation) len 43
    Info:TuyaMCU:ParseQueryProductInformation: received {"p":"lydwobwyqxiyob9h","v":"1.0.5"}
    Info:MAIN:Time 2, idle 181611/s, free 73496, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Time 3, idle 61711/s, free 73472, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Time 4, idle 0/s, free 73472, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Time 5, idle 0/s, free 73472, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTING - 1
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTED - 4
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTED - 4
    Info:MQTT:mqtt_userName openbeken
    mqtt_pass xxxxxxxx
    mqtt_clientID BR_M_S
    mqtt_host 192.168.64.252:1883
    Info:MAIN:Time 6, idle 110720/s, free 64976, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 3/38 
    Info:MAIN:Boot complete time reached (5 seconds)
    Info:CFG:####### Set Boot Complete #######
    Info:MQTT:mqtt_connection_cb: Successfully connected
    Info:MQTT:mqtt_subscribed to BR_M_S/+/set
    Info:MQTT:mqtt_subscribed to bekens_n/+/set
    Info:MQTT:mqtt_subscribed to cmnd/BR_M_S/+
    Info:MQTT:mqtt_subscribed to cmnd/bekens_n/+
    Info:MQTT:mqtt_subscribed to BR_M_S/+/get
    Info:TuyaMCU:Received: 55 AA 00 02 00 00 01 
    Info:TuyaMCU:ProcessIncoming[v=0]: cmd 2 (MCUconf) len 7
    Info:TuyaMCU:ProcessIncoming: TUYA_CMD_MCU_CONF, TODO!
    ming_publish_cb topic BR_M_S/7/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/8/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/9/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/10/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/11/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/12/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/13/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/14/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/15/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/16/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/17/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/18/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/19/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/20/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/21/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/22/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/23/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/24/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/25/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/26/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/27/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/28/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/29/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/30/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/31/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/32/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/33/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/34/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/35/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/36/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/37/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/38/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/39/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/41/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/42/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/43/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/44/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/45/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/46/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/47/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/48/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/49/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/50/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/51/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/52/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/53/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/54/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/55/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/56/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/57/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/58/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/59/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/60/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/61/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/62/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/63/get
    Info:MQTT:Publishing val BR_M_S to BR_M_S/host retain=1
    Info:MAIN:Time 7, idle 92402/s, free 73744, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:Publishing val Build on Feb 24 2024 20:18:08 version 1.17.483 to BR_M_S/build retain=1
    Info:MAIN:Time 8, idle 182924/s, free 73472, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:Publishing val 1c:90:ff:d0:ff:44 to BR_M_S/mac retain=1
    Info:MAIN:Time 9, idle 186932/s, free 73744, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:TuyaMCU:Received: 55 AA 00 02 00 00 01 
    Info:TuyaMCU:ProcessIncoming[v=0]: cmd 2 (MCUconf) len 7
    Info:TuyaMCU:ProcessIncoming: TUYA_CMD_MCU_CONF, TODO!
    Info:TuyaMCU:Received: 55 AA 00 05 00 05 01 04 00 01 00 0F 
    Info:TuyaMCU:ProcessIncoming[v=0]: cmd 5 (WiFiSelect) len 12
    Info:TuyaMCU:V0_ParseRealTimeWithRecordStorage: processing id 1, dataType 4-enum and 1 data bytes
    Info:TuyaMCU:V0_ParseRealTimeWithRecordStorage: byte 0
    Info:GEN:CHANNEL_Set channel 1 has changed to 0 (flags 0)
    
    Info:MQTT:Channel has changed! Publishing 0 to channel 1 
    Info:MQTT:Publishing val 0 to BR_M_S/1/get retain=1
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic BR_M_S/1/get
    Info:MQTT:Publishing val FM_SH to BR_M_S/ssid retain=1
    Info:MAIN:Time 10, idle 176067/s, free 62048, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 3/38 
    Info:GEN:dhcp=0 ip=192.168.64.69 gate=192.168.64.254 mask=255.255.255.0 mac=1c:90:ff:d0:ff:44
    Info:GEN:sta: 1, softap: 0, b/g/n
    Info:GEN:sta:rssi=-57,ssid=FM_SH,bssid=48:22:54:40:51:c8,channel=11,cipher_type:CCMP
    Info:MQTT:Publishing val 2 to BR_M_S/sockets retain=1
    Info:MAIN:Time 11, idle 179999/s, free 73744, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:Publishing val -57 to BR_M_S/rssi retain=1
    Info:MAIN:Time 12, idle 187769/s, free 73744, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:Publishing val 12 to BR_M_S/uptime retain=1
    Info:MAIN:Time 13, idle 188531/s, free 73744, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:Publishing val 73744 to BR_M_S/freeheap retain=1
    Info:MAIN:Time 14, idle 185052/s, free 73744, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Main_Init_Before_Delay


    Any ideas?
  • #193 20981874
    p.kaczmarek2
    Moderator Smart Home
    Why do you think it does not wake up back from the sleep? It's TuyaMCU device, the MCU handles the wake up procedure. It should always wake up, as we don't change the firmware of the MCU, just of the WiFi module.
    Helpful post? Buy me a coffee.
  • #194 20982385
    p4nd0ra
    Level 3  

    That is a very good question. I have 3 of those and all exhibit the same issue.
    When pressing the reset button it connects back to the network and I can access it for some time.
    AP mode can be triggered as well.

    What is this message by the way?
    TuyaMCU:ProcessIncoming: TUYA_CMD_MCU_CONF, TODO!

Topic summary

The discussion revolves around configuring a motion sensor device powered by the BK7231N chip and utilizing the TuyaMCU protocol. Users share experiences and troubleshooting steps related to flashing the device, setting up the autoexec.bat file, and ensuring proper communication between the TuyaMCU and the Wi-Fi module. Key issues include the device not waking from sleep, MQTT communication problems, and the need for specific commands to maintain connectivity. Solutions involve using RealTerm for monitoring, adjusting baud rates, and ensuring the correct setup of drivers and commands in the autoexec.bat file. Users also discuss the importance of maintaining a stable power supply and the potential for firmware updates to improve functionality.
Summary generated by the language model.
ADVERTISEMENT