logo elektroda
logo elektroda
X
logo elektroda

NAS-AB02W6 Ver 2.0 Tuya Siren+Temp+Humidity Sensor: Control LEDs with OpenBK Firmware

rylos78 3591 33
ADVERTISEMENT
  • #1 20376475
    rylos78
    Level 3  
    NAS-AB02W6 Ver 2.0 Tuya Siren+Temp+Humidity Sensor: Control LEDs with OpenBK Firmware
    Hi All! Great project I didn't know until 2 hours ago, keep up the good work!
    Now I'm just started programming a recent Tuya Siren+Temperature+Humidity sensor (old ESP8266 version was named NAS-AB02W (without 6) this one is the old: https://templates.blakadder.com/neo_coolcam_NAS-AB02W.html ; the one I got from aliexpress has the BK7231N and it's using TuyaMCU.

    I've programmed it just fine using RXD-TXD pins and touching CEN pin with UART3v3 GND pin just after flash program starts.
    I've figured out how to map the dpid I need for now, but there is a thing I'm not able to change: this siren has LEDS that are flashing when siren is ringing and stay off in all other states, with original firmware.
    With OpenBK flashed, the leds just flash after boot and I'm not able to stop them. Any suggestion what to look for?
    Many thanks in advance
    RyLoS
  • ADVERTISEMENT
  • #2 20376584
    p.kaczmarek2
    Moderator Smart Home
    Hello @rylos78 , can you post your autoexec.bat, how advanced are you with this device?

    We already had a report from a user saying that his device buzzer was going off when there was no MQTT connected, it was strange, but can you check this - do you have both WiFi and MQTT online when testing this device?

    Have you checked is there a setting for those LEDs in TuyaMCU dpIds?
    Helpful post? Buy me a coffee.
  • #3 20381608
    rylos78
    Level 3  
    I've tried a lot of things and the results are:
    dpid 103 is alarm duration time (in seconds), default is 10.
    When 104 (toggle) is set to 1 (switch on) the bell will ring for dpid 103 duration, after switch 102 is returned to 0.
    Temperature is dpid 105 and humidity is 106.
    104 - 105 - 106 are working fine with openbeken.

    There is a problem on dpid 102 that is chime sound selection (it's a value from 0 to 17) = 18 ring tones.
    At startup it's defaulted to value 5. I can change it with setchannel on command of webapp (channel is set to textField). I need value 12 permanent.
    If I put this on web config as startup value, it remains 5 after a reboot.
    I've tried also setChannel 4 12 on autoexec.bat but value after reboot is still 5.
    I've tried also a delay before setchannel but value is still 5.
    I can change it only from command line. Any clue?

    my actual autoexec.bat:
    
    See post #5
    
  • Helpful post
    #4 20381721
    p.kaczmarek2
    Moderator Smart Home
    Good job with writing the config. I will try to help you with the further steps.
    rylos78 wrote:

    There is a problem on dpid 102 that is chime sound selection (it's a value from 0 to 17) = 18 ring tones.
    At startup it's defaulted to value 5. I can change it with setchannel on command of webapp (channel is set to textField). I need value 12 permanent.
    If i put this on web config as startup value, it reamains 5 after a reboot.
    I've tried also setChannel 4 12 on autoexec.bat but value after reboot is still 5.
    I've tried also a dealy before setchannel but value is still 5.
    I can change it only from commandline. Any clue?

    We do not have implemented yet the initial state sending to TuyaMCU, it was never needed, but I will try to figure out something for you.

    The most simple solution would be:
    
    addRepeatingEvent 5 1 setChannel 4 12
    

    5 is a delay in seconds, customizable, 1 is number of repeats - do it once.

    But it may not be a perfect solution. I've been thinking what else I can do for you quickly to solve your issue and I came up with this:
    https://github.com/openshwprojects/OpenBK7231...mmit/93debb94eb3b4c380812ed4b3e129dd7a5994ed5
    You will need to update the firmware to get that.
    This is an event, TuyaMCUParsed, with argument showing packet type:
    
    
    #define TUYA_CMD_HEARTBEAT     0x00
    #define TUYA_CMD_QUERY_PRODUCT 0x01
    #define TUYA_CMD_MCU_CONF      0x02
    #define TUYA_CMD_WIFI_STATE    0x03
    #define TUYA_CMD_WIFI_RESET    0x04
    #define TUYA_CMD_WIFI_SELECT   0x05
    #define TUYA_CMD_SET_DP        0x06
    #define TUYA_CMD_STATE         0x07
    #define TUYA_CMD_QUERY_STATE   0x08
    #define TUYA_CMD_SET_TIME      0x1C
    #define TUYA_CMD_WEATHERDATA   0x21
    #define TUYA_CMD_SET_RSSI      0x24
    

    Usage:
    addEventHandler TuyaMCUParsed 0x02 setChannel 4 12
    

    Or, if you want a delay:
    
    addEventHandler TuyaMCUParsed 0x02 addRepeatingEvent 1 1 setChannel 4 12
    

    I haven't tested it so tell me if there is any problem.
    Futhermore...
    I don't know when exactly can you already start setting channels
    So you might need to try one of these:
    
    #define TUYA_CMD_QUERY_PRODUCT 0x01
    #define TUYA_CMD_MCU_CONF      0x02
    #define TUYA_CMD_WIFI_STATE    0x03
    

    You will need some experiments to get it running. It's up to you to choose the working way. You can just use a delay like 5 seconds and assume that it will be ok, or you can try using the Event Handler I've just added for you. Good luck!
    Helpful post? Buy me a coffee.
  • #5 20383126
    rylos78
    Level 3  
    Wow! Thank you for your support.
    Ok first problem was this linkTuyaMCUOutputToChannel 102 val 4, apparently it was working and setting a value was working too but in reality chime sound was not changing.
    After setting it as linkTuyaMCUOutputToChannel 102 enum 4 it was starting working and set value was retained on reboot too.
    However I've also tested your new event and put this on autoexec.bat "addEventHandler TuyaMCUParsed 0x02 setChannel 4 11" and it's working fine if I change value then reboot.
    As of now I can say this device is fully supported right now.
    Will edit this message later adding my actual autoexec.bat. Here it is:
    
    //Drivers
    startDriver TuyaMCU
    //startDriver NTP
    //ntp_timeZoneOfs 1:00
    //
    //Channels
    setChannelType 1 toggle
    setChannelType 2 Temperature_Div10
    setChannelType 3 Humidity
    //ch4 = chime sound
    setChannelType 4 TextField
    //ch5 = volume 0->high 1->middle 2->low
    setChannelType 5 TextField
    //ch6 = alarm duration in sec
    setChannelType 6 TextField
    //
    //Links & Vars
    linkTuyaMCUOutputToChannel 104 bool 1
    linkTuyaMCUOutputToChannel 105 val 2
    linkTuyaMCUOutputToChannel 106 val 3
    linkTuyaMCUOutputToChannel 102 enum 4
    linkTuyaMCUOutputToChannel 116 enum 5
    linkTuyaMCUOutputToChannel 103 val 6
    //
    //Events
    //addEventHandler TuyaMCUParsed 0x02 setChannel 4 11
    addEventHandler TuyaMCUParsed 0x02 addRepeatingEvent 3 1 setChannel 4 11
    addEventHandler TuyaMCUParsed 0x02 addRepeatingEvent 3 1 setChannel 6 120
    
  • Helpful post
    #6 20383147
    p.kaczmarek2
    Moderator Smart Home
    Thank you, would you be able to at least provide few more photos of the device inside (PCB board) or/and packaging to make the entry to https://openbekeniot.github.io/webapp/devicesList.html complete? Or maybe where the device was bought?
    It's important to use to provide enough documentation so future users so they can easily flash their devices.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #7 20389108
    rylos78
    Level 3  
    Device was bought here: AliExpress Siren Temperature Humidity Sensor
    For autoexec.bat see post #5
    Here my Home Assistant MQTT (mqtt.yaml) config:
    
      switch:
        - name: "Siren1"
          state_topic: "Siren1/1/get"
          command_topic: "Siren1/1/set"
          unique_id: "siren1switch"
          qos: 1
          availability_topic: "Siren1/connected"
          payload_on: 1
          payload_off: 0
          retain: true
      sensor:
        - name: "Siren1 Temperature"
          device_class: temperature
          unique_id: "siren1temperature"
          state_topic: "Siren1/2/get"
          value_template: "{{ ((value | float * 0.1 | round(1))) }}"
          unit_of_measurement: '°C'
          qos: 1
          availability_topic: "Siren1/connected"
        - name: "Siren1 Humidity"
          device_class: humidity
          unique_id: "siren1humidity"
          state_topic: "Siren1/3/get"
          value_template: "{{ value }}"
          unit_of_measurement: '%RH'
          qos: 1
          availability_topic: "Siren1/connected"
    
  • #8 20389203
    p.kaczmarek2
    Moderator Smart Home
    Thank you. We will soon have Automatic Home Assistant Discovery for TuyaMCU as well, but that's not ready yet.
    I will post here a backup screenshots from the offer you linked (because links tends to expire):
    NAS-AB02W6 Ver 2.0 Tuya Siren+Temp+Humidity Sensor: Control LEDs with OpenBK Firmware
    NAS-AB02W6 Ver 2.0 Tuya Siren+Temp+Humidity Sensor: Control LEDs with OpenBK Firmware NAS-AB02W6 Ver 2.0 Tuya Siren+Temp+Humidity Sensor: Control LEDs with OpenBK Firmware NAS-AB02W6 Ver 2.0 Tuya Siren+Temp+Humidity Sensor: Control LEDs with OpenBK Firmware NAS-AB02W6 Ver 2.0 Tuya Siren+Temp+Humidity Sensor: Control LEDs with OpenBK Firmware NAS-AB02W6 Ver 2.0 Tuya Siren+Temp+Humidity Sensor: Control LEDs with OpenBK Firmware NAS-AB02W6 Ver 2.0 Tuya Siren+Temp+Humidity Sensor: Control LEDs with OpenBK Firmware NAS-AB02W6 Ver 2.0 Tuya Siren+Temp+Humidity Sensor: Control LEDs with OpenBK Firmware NAS-AB02W6 Ver 2.0 Tuya Siren+Temp+Humidity Sensor: Control LEDs with OpenBK Firmware
    Are you using PowerSave for this device, as according to the photos is supports battery mode? But even if it's powered by wire... PowerSave can always save some energy.
    Helpful post? Buy me a coffee.
  • #9 20389224
    rylos78
    Level 3  
    Device has 2 battery slots for backup, there is also a DPID 101 with state of power and charge
    
    dpId 101 - power type (1 - battery high; 2 - medium; 3 - low; 4 - usb port)
    

    I will enable PowerSave and test it for a while. Thank you.
  • ADVERTISEMENT
  • #10 20389558
    p.kaczmarek2
    Moderator Smart Home
    We're also working on deep sleep feature, a feature where basically WiFi module goes into total hibernation for a given amount of time and then wakes up for few seconds and checks the sensors, only to report values (if needed) and sleep again.
    Helpful post? Buy me a coffee.
  • #11 20406088
    ionoleinic
    Level 10  
    Hi, I got a similar device NEO nas AB02W6 from AliExpress, based on Beken7231N module.
    The related photos of siren:
    NAS-AB02W6 Ver 2.0 Tuya Siren+Temp+Humidity Sensor: Control LEDs with OpenBK Firmware
    NAS-AB02W6 Ver 2.0 Tuya Siren+Temp+Humidity Sensor: Control LEDs with OpenBK Firmware NAS-AB02W6 Ver 2.0 Tuya Siren+Temp+Humidity Sensor: Control LEDs with OpenBK Firmware NAS-AB02W6 Ver 2.0 Tuya Siren+Temp+Humidity Sensor: Control LEDs with OpenBK Firmware NAS-AB02W6 Ver 2.0 Tuya Siren+Temp+Humidity Sensor: Control LEDs with OpenBK Firmware NAS-AB02W6 Ver 2.0 Tuya Siren+Temp+Humidity Sensor: Control LEDs with OpenBK Firmware

    Want to ask: Should I do tuya mcu capture of packets before flashing or not?
    It seems to be similar with @rylos78's siren.
    Thank you.
  • #12 20406115
    p.kaczmarek2
    Moderator Smart Home
    It's up to you, @ionoleinic , but it's always safe to do both packet capture and firmware backup first.
    Keep in mind that TuyaMCU is using the same port which one is used for flashing, so not much extra work is needed to do the capture. It should be easy. As far as I remember you already did UART capture in the past, right?
    Helpful post? Buy me a coffee.
  • #13 20406164
    ionoleinic
    Level 10  
    p.kaczmarek2 wrote:
    As far as I remember you already did UART capture in the past, right?

    Yes, with Temp and Hum sensor.
    I will try to do capture and backup.
    I also got another BL-602 based device, it is a Magic home Led Controller. What to do with it? Try to flash or not? The bulb that was based on bl-602 now is disassembled and I don't know what to do with this...
  • #14 20406205
    p.kaczmarek2
    Moderator Smart Home
    I've worked on BL602 recently and added OTA feature, so it's certainly giving a try. I don't know still about that "newer" BL602 devices. I don't have any of them. I would need to get one piece of new BL602 for research.

    Try flashing that magic led strip with OpenBL602 and we will see.
    Helpful post? Buy me a coffee.
  • #15 20564020
    jobstjn
    Level 2  
    This also works for ab02w6 v4, brought from the same aliexpress provider. Setting default values is troublesome though, but this configuration worked best:

    addEventHandler TuyaMCUParsed 0x02 addRepeatingEvent 2.5 1 setChannel 4 7 addEventHandler TuyaMCUParsed 0x02 addRepeatingEvent 3 1 setChannel 6 30

    If the event happens too fast or too late it won't work. Or if both ran at the same time, only one will be picked up. That will give about 50% chance both configs will be picked up on boot (await ~25 seconds in before switching it on from within the GUI). The PCB is similar to v2, and does not require soldering, since GND & 3.3V are hollow, and CEN, RT, RX are recessed.
  • ADVERTISEMENT
  • #16 20570015
    jobstjn
    Level 2  
    There's one issue: if the device disconnects from mqtt it becomes de-synchronized (the gui still reports the last config, but the device will act on default values).

    example:
    on boot default alarm duration is 10s, set it to 20s, mqtt server down, gui still reports 20s but now will play for 10s, set it to 20s through mqtt (this mqtt command is ignored, perhaps the device sees it as a duplicated value?), the solution is to set duration to any value other than 20s, then set it to 20s.

    action:
    - service: mqtt.publish
    data:
    topic: Siren1/6/set
    payload: 10
    - delay: '.5'
    - service: mqtt.publish
    data:
    topic: Siren1/1/set
    payload: 1
    - delay: '.5'
    - service: mqtt.publish
    data:
    topic: Siren1/6/set
    payload: 30

    (A half a second delay between commands worked best for me.)

    Or if the EventHandler was set, or if use retain: true was set so the latest state is retrieved from mqtt server... just reboot the device.
  • #17 20570108
    p.kaczmarek2
    Moderator Smart Home
    Hello, I see you have a nice progress on figuring it out.

    If you think that device has default values after reboot, then you can consider using channel memory feature.

    In Config, go to Startup, and for each channel you want to be remembered after reboot, enter value -1.

    Then, on every change, this channel will be saved in flash memory (in our flash vars partition featuring erase-cycle optimization to reduce flash wear).

    This will work for simple Relays, so relay devices can remember their state after reboot, but it can also work for custom channel values, anything.

    Let me know if that helps, I assumed that you are referring to data loss after reboot, but I am not sure.... maybe you are also missing a "Broadcast self state on MQTT connect" flag?
    Helpful post? Buy me a coffee.
  • #18 20570150
    jobstjn
    Level 2  
    Hi sir,

    1st it's the startup bug:
    there's a ~50% chance this config gets applied upon boot (so several tries are needed):
    addEventHandler TuyaMCUParsed 0x02 addRepeatingEvent 2.5 1 setChannel 4 7
    addEventHandler TuyaMCUParsed 0x02 addRepeatingEvent 3 1 setChannel 6 30
    (I think it's something similar for retain: true as a mqtt config strategy)

    2nd it's when the device disconnects from mqtt server (server down):
    gui will still report last config but device will act on default values (e.g. song 5, 10s). Regardless of when or if it reconnects.
    a regular hass automation config will stop working here, need to apply the hack above

    Additionally the minor issue of requiring delay between mqtt commands, perhaps network related?.

    I am unsure how would those ideas fix these issues.
  • #19 20576819
    acapruzzi67
    Level 1  
    Hi Folks,

    I'm just starting to interface in HASSIO the NEO Coolcam Siren NAS-AB02W6, and just flashed the device with OpenBK.

    May anyone suggest the PIN configuration to be used.

    Thanks.
  • #20 20576823
    p.kaczmarek2
    Moderator Smart Home
    Hello, do you have a 2MB flash dump?

    This tool:
    https://github.com/openshwprojects/BK7231GUIFlashTool
    can extract GPIO from 2MB Tuya flash dump.
    See example below:
    NAS-AB02W6 Ver 2.0 Tuya Siren+Temp+Humidity Sensor: Control LEDs with OpenBK Firmware
    Helpful post? Buy me a coffee.
  • #21 20623474
    ionoleinic
    Level 10  

    It doesn't work on devices that use Tuya MCU...
    NAS-AB02W6 Ver 2.0 Tuya Siren+Temp+Humidity Sensor: Control LEDs with OpenBK Firmware
  • #22 20623995
    p.kaczmarek2
    Moderator Smart Home
    Well, right, but at least it can detect the baud rate of TuyaMCU protocol.
    Helpful post? Buy me a coffee.
  • #23 20852694
    jleepblcjleeca
    Level 2  

    I also have NEO Coolcam Siren NAS-AB02W6 and just flashed the device with OpenBK. However, I don't know how to configure pins in the following screen;

    Screenshot of pin configuration for OpenBK7231N device.

    May anyone suggest the PIN configuration to be used?
  • #24 20852700
    p.kaczmarek2
    Moderator Smart Home
    Have you tried to do the GPIO extraction process?


    Helpful post? Buy me a coffee.
  • #25 20852717
    jleepblcjleeca
    Level 2  

    >> Have you tried to do the GPIO extraction process?
    Yes, I already tried but it doesn't work on devices that use Tuya MCU...
  • #26 21092851
    ferbulous
    Level 18  
    Hi, how’s the battery life on this siren?
  • #28 21135638
    itelektronik
    Level 2  
    Hello,

    you do not need to configure any pins.
    The Bekenchip talks directly with the tuya chip via serial connection (the same serial port you use to flash). This tuya chip does anything else (sound led).
    All you have to do is creating an autoexec.bat in the filesystem of openbeken and paste the code from rylos87 in post #5 (https://www.elektroda.com/rtvforum/topic3947937.html#). Then restart it and it works.

    Best regards.
  • #29 21135661
    p.kaczmarek2
    Moderator Smart Home
    Just make sure first that you have indeed TuyaMCU vesion. There are often many versions of the same device available, some of them may use TuyaMCU, and some may just use deep sleep directly.
    Helpful post? Buy me a coffee.
  • Helpful post
    #30 21135668
    itelektronik
    Level 2  
    Here is a short how-to flash the NAS-AB02W6-V4 Siren and get it working.

    1.) Flash the Beken7231N module.
    I just connected TXD and RXD (its the second and third hole marked on the picture) to my USB-Serial-Interface, launched the OpenBekenFlasher, started Backup&Flash and then connected USB Power to the Siren. I think it is a good idea to use the computer as USB-power source to have the same ground level.
    Close-up of a circuit board with highlighted TXD and RXD holes.

    2.) Start the device. Connect to the "Openbeken*****" wifi. Open http://192.168.4.1 in your browser. Configure wifi.

    3.) Discover the IP address of the device and connect to it.

    4.) Launch Web Application
    Screenshot of the configuration interface for the NAS-AB02W6-V4 siren.

    5.) On the Top-menu click on "file system". then choose "create file". say "OK" to autoexec.bat
    File editor interface with a field for creating a new file autoexec.bat.
    6.) In the middle click on the new file paste the autoexec.bat contents from post #5 there. Click "Safe"
    If you have the device without temperature and humidity, you can delete the according lines (8,9,19,20).
    Editing interface for autoexec.bat file in a web application.

    7.) restart the device and have fun :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-)
    Screenshot of the WLAN-SIRENE-01 interface with Toggle 1 button and channel settings options.

Topic summary

The discussion revolves around programming the NAS-AB02W6 Ver 2.0 Tuya Siren with temperature and humidity sensor capabilities using OpenBK firmware. Users share their experiences with configuring the device, particularly focusing on controlling LED behavior during alarm states and setting chime sounds. Key issues include retaining settings after reboot, managing MQTT connections, and ensuring proper command execution through autoexec.bat scripts. Solutions involve using specific dpIds for configuration, implementing event handlers, and utilizing the TuyaMCU protocol for communication. Users also discuss the importance of capturing packets and backing up firmware before flashing the device.
Summary generated by the language model.
ADVERTISEMENT