Elektroda.com
Elektroda.com
X

Energy-saving (?) Battery-operated door / window sensor for WiFi DS06

p.kaczmarek2 7050 38
This content has been translated flag-pl » flag-en View the original version here.
  • #31
    elbuit
    Level 5  
    p.kaczmarek2 wrote:
    Hello @elbuit . You are using uartprogram incorrectly. Please consult manual:
    https://github.com/OpenBekenIOT/hid_download_py
    Energy-saving (?) Battery-operated door / window sensor for WiFi DS06
    You are missing offset.
    [/url]

    :oops: I've missed that part, my apologies.
    Thanks for your help and to allow my tuya devices a new life with home assistant.

    I managed to write OpenBeken firmware and it works.
    But I think that I've broken the magnetic field sensor because although I put the magnet closer the device don't stops.

    By the way, I've seen that CB3S supports bluetooth.
    That could be interesting for a door sensor, to detect which devices are near when the door is opened.

    Thanks.
  • #32
    klaudi43
    Level 4  
    Hello,

    Unfortunately I don't have much time at the moment.
    I don't know if your problem is solved, but I also had problems with flashing the device initially. When flashing I had a write error again and again.
    I fixed it by changing the USB serial device. It was the same guy. I don't know why, but the other one works fine.

    I used the flashing tool (Buffalo in version 1.4.8 as described in the discussion).

    Greetings
    K
  • #33
    miroww1
    Level 6  
    Hello
    I have this door open sensor. I uploaded OpenBK version 1.15.468 to it, so far it works without any problems.
    I analyzed the board and drew a schematic. Maybe someone will like it.

    Energy-saving (?) Battery-operated door / window sensor for WiFi DS06

    Energy-saving (?) Battery-operated door / window sensor for WiFi DS06
  • #34
    p.kaczmarek2
    Moderator Smart Home
    Hello, thanks for the diagram. This door sensor, i.e. the one from TuyaMCU?

    Remember that if your door/window sensor does not have TuyaMCU and is implemented on the WiFi chip only, then you should consider its configuration to work with Deep Sleep and wake up by changing the state on the pin.

    Also (in any case) it is worth considering adding the PowerSave command to the short startup command, which in turn starts the hybrid sleep mode (the device supposedly works all the time, but it saves energy). PowerSave will soon be set to 1 by default in every release (you won't need to enable it), but we're still testing it.
  • #35
    miroww1
    Level 6  
    Hello

    I have a request, could you tell me how to implement a pin-triggered Deep sleep into Open BK. (I searched the web, but unfortunately I couldn't find the information I needed).
    I have already implemented power save.

    Thank you for your help.

    miroww1
  • #36
    p.kaczmarek2
    Moderator Smart Home
    @miroww1 for simple situations, it is enough to set the roles of, for example, a button for a pin and use the PinDeepSleep command, then the device will "sleep" and this button will wake it up, but more complex logic is needed for the door controller.

    I guess for the door sensor I will just write you a ready-made driver that will cover everything, can you look at this topic?
    https://www.elektroda.com/rtvforum/viewtopic.php?p=20455596#20455596
    There is a similar question and I would like to continue the discussion in one place.

    The sensor from this topic (from the first post), DS06, uses TuyaMCU, and there the external MCU gets sleep and turns off the WiFI module. Your door open sensor is different, yours doesn't have TuyaMCU, there is only Beken itself.

    Will you be able to help us with testing?
  • #38
    miroww1
    Level 6  
    Hello

    Thank you for your help, of course I will join the process of testing this software.
    Today I will try to configure according to the instructions.

    Regards
    miroww1
  • #39
    p.kaczmarek2
    Moderator Smart Home
    Today, 2023-04-30, Tuya battery devices driver has been updated to cover both formats with and without date.

    Here's a summary of a setup for such devices (like in the first post).

    1. Do UART capture to figure out dpId meanings:
    https://www.elektroda.com/rtvforum/viewtopic.php?p=20528459#20528459
    2. Flash OBK, you may need to cut traces because TuyaMCU will interfere with UART communication. You also will need to connect power to 3.3V of WiFi module because otherwise TuyaMCU can cut off its power (see first post)
    https://github.com/openshwprojects/BK7231GUIFlashTool
    3. Configure obk wifi and pass, also add autoexec with tuyaMCU dpIDs mapping , here is my sample:
    
    startDriver TuyaMCU
    startDriver tmSensor
    
    // may be needed, depends on device
    //tuyaMcu_setBaudRate 115200
    
    // map dpID 1 to channel 1
    linkTuyaMCUOutputToChannel 1 val 1
    setChannelType 1 OpenClosed
    
    // map dpID 3 to channel 3
    linkTuyaMCUOutputToChannel 3 val 3
    setChannelType 3 Custom
    

    4. configure HA to receive that, here is a small sample:
    Code: yaml
    Log in, to see the code

    5. Now remember, the wifi module will be on for a very short time when door state changes, TuyaMCU will later power it off and go into deep sleep, but you can also keep it powered longer by pressing for a long time (several seconds) the pair button multiple times
    6. now, door state changes will result in such or similar log (if you keep Web App Log Open, you may see it):
    
    Info:MAIN:Main_Init_Before_Delay
    Info:CFG:####### Boot Count 26 #######
    Warn:CFG:CFG_InitAndLoad: Correct config has been loaded with 7 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:MY_WIFI_SSID key:MY_WIFI_PASS
    Info:MAIN:Using SSID [MY_WIFI_SSID]
    Info:MAIN:Using Pass [MY_WIFI_PASS]
    Info:MQTT:MQTT_RegisterCallback called for bT t_mcu_door/ subT t_mcu_door/+/set
    Info:MQTT:MQTT_RegisterCallback called for bT bekens/ subT bekens/+/set
    Info:MQTT:MQTT_RegisterCallback called for bT cmnd/t_mcu_door/ subT cmnd/t_mcu_door/+
    Info:MQTT:MQTT_RegisterCallback called for bT cmnd/bekens/ subT cmnd/bekens/+
    Info:MQTT:MQTT_RegisterCallback called for bT t_mcu_door/ subT t_mcu_door/+/get
    Info:CMD:CMD_StartScript: started autoexec.bat at the beginning
    Info:MAIN:Main_Init_After_Delay done
    Info:MAIN:Started TuyaMCU.
    Info:MAIN:Started tmSensor.
    Info:GEN:Channel 1 type changed to OpenClosed
    Info:GEN:Channel 3 type changed to Custom
    Info:MAIN:Time 1, idle 247169/s, free 83744, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Time 2, idle 245680/s, free 83744, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 01 00 24 7B 22 70 22 3A 22 33 73 6C 70 69 72 6C 6E 6C 71 70 30 62 71 6F 31 22 2C 22 76 22 3A 22 31 2E 30 2E 30 22 7D C6 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 1 (QueryProductInformation) with 43 bytes
    Info:TuyaMCU:TuyaMCU_ParseQueryProductInformation: received {"p":"3slpirlnlqp0bqo1","v":"1.0.0"}
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 05 00 05 01 01 00 01 01 0D 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 5 (WiFiSelect) with 12 bytes
    Info:TuyaMCU:TuyaMCU_V0_ParseRealTimeWithRecordStorage: processing dpId 1, dataType 1-DP_TYPE_BOOL and 1 data bytes
    Info:TuyaMCU:TuyaMCU_V0_ParseRealTimeWithRecordStorage: raw data 1 byte: 
    Info:GEN:CHANNEL_Set channel 1 has changed to 1 (flags 0)
    
    Info:MQTT:Channel has changed! Publishing 1 to channel 1 
    Info:MAIN:Time 3, idle 94355/s, free 83808, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Time 4, idle 0/s, free 83808, 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 homeassistant
    mqtt_pass ma1oovoo0pooTie7koa8Eiwae9vohth1vool8ekaej8Voohi7beif5uMuph9Diex
    mqtt_clientID t_mcu_door
    mqtt_host 192.168.0.113:1883
    Info:MAIN:Time 5, idle 121902/s, free 83704, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:mqtt_connection_cb: Successfully connected
    Info:MQTT:mqtt_subscribed to t_mcu_door/+/set
    Info:MQTT:mqtt_subscribed to bekens/+/set
    Info:MQTT:mqtt_subscribed to cmnd/t_mcu_door/+
    Info:MQTT:mqtt_subscribed to cmnd/bekens/+
    Info:MQTT:mqtt_subscribed to t_mcu_door/+/get
    Info:MQTT:Publishing val obk61B58371 to t_mcu_door/host retain=0
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 02 00 00 01 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 2 (MCUconf) with 7 bytes
    Info:TuyaMCU:TuyaMCU_ProcessIncoming: TUYA_CMD_MCU_CONF, TODO!
    Info:MAIN:Time 6, idle 245750/s, free 83936, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Boot complete time reached (5 seconds)
    Info:CFG:####### Set Boot Complete #######
    Info:MQTT:Publishing val Build on Apr 30 2023 13:32:58 version 1.0.0 to t_mcu_door/build retain=0
    Info:MAIN:Time 7, idle 233534/s, free 83664, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:Publishing val 10:d5:61:b5:83:71  to t_mcu_door/mac retain=0
    Info:MAIN:Time 8, idle 247547/s, free 83936, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:Publishing val 3 to t_mcu_door/sockets retain=0
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 02 00 00 01 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 2 (MCUconf) with 7 bytes
    Info:TuyaMCU:TuyaMCU_ProcessIncoming: TUYA_CMD_MCU_CONF, TODO!
    Info:TuyaMCU:TUYAMCU received: 55 AA 00 05 00 05 03 04 00 01 02 13 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=0]: processing command 5 (WiFiSelect) with 12 bytes
    Info:TuyaMCU:TuyaMCU_V0_ParseRealTimeWithRecordStorage: processing dpId 3, dataType 4-DP_TYPE_ENUM and 1 data bytes
    Info:TuyaMCU:TuyaMCU_V0_ParseRealTimeWithRecordStorage: raw data 1 byte: 
    Info:GEN:CHANNEL_Set channel 3 has changed to 2 (flags 0)
    
    Info:MQTT:Channel has changed! Publishing 2 to channel 3 
    Info:MQTT:Publishing val 2 to t_mcu_door/3/get retain=0
    Info:MAIN:Time 9, idle 265333/s, free 72208, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 3/38 
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic t_mcu_door/3/get
    Info:MQTT:Publishing val -52 to t_mcu_door/rssi retain=0
    Info:MAIN:Time 10, idle 226762/s, free 83704, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:GEN:dhcp=0 ip=192.168.0.235 gate=192.168.0.1 mask=255.255.255.0 mac=10:d5:61:b5:83:71 
    Info:GEN:sta: 1, softap: 0, b/g/n
    Info:GEN:sta:rssi=-52,ssid=MY_WIFI_SSID,bssid=28:87:ba:a0:f5:6d ,channel=3,cipher_type:CCMP
    Info:MQTT:Publishing val 10 to t_mcu_door/uptime retain=0
    Info:MAIN:Time 11, idle 245307/s, free 83704, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:Publishing val 72208 to t_mcu_door/freeheap retain=0
    Info:MAIN:Time 12, idle 251851/s, free 72208, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 3/38 
    Info:MQTT:Publishing val 192.168.0.235 to t_mcu_door/ip retain=0
    Info:MAIN:Time 13, idle 245380/s, free 83936, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:Channel has changed! Publishing 1 to channel 1 
    Info:MQTT:Publishing val 1 to t_mcu_door/1/get retain=0
    Info:MAIN:Time 14, idle 247389/s, free 83936, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic t_mcu_door/1/get
    Info:MQTT:Channel has changed! Publishing 2 to channel 3 
    Info:MQTT:Publishing val 2 to t_mcu_door/3/get retain=0
    Info:MAIN:Time 15, idle 244718/s, free 83936, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic t_mcu_door/3/get
    Info:MAIN:Time 16, idle 493519/s, free 83936, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    

    After 4 seconds, I get WiFI with DHCP (quick wifi connect flag in flags). After 6 seconds, I get MQTT. After whole 16 seconds, the device goes to sleep. The communication speed can be improved soon.

    Here is how it looks in HA:
    Energy-saving (?) Battery-operated door / window sensor for WiFi DS06
    Energy-saving (?) Battery-operated door / window sensor for WiFi DS06