logo elektroda
logo elektroda
X
logo elektroda

[BK7231T] Setting Up TreatLife DS02F Ceiling Fan Controller - Non-ESP Flashing

rb2k 1497 19
ADVERTISEMENT
  • #1 20463901
    rb2k
    Level 3  
    [BK7231T] Setting Up TreatLife DS02F Ceiling Fan Controller - Non-ESP Flashing

    Grabbed one from here: https://www.amazon.com/gp/product/B08P5D3ZKW/
    Was flashable using tuya cloudcutter and this template: https://github.com/tuya-cloudcutter/tuya-clou...r/devices/treatlife-ds02f-fan-controller.json
    Apparently used to be an esp device (as seen over here: https://templates.blakadder.com/treatlife_DS02F.html)

    I'm new to non-ESP flashing and I'm still trying to figure out how to correctly set this up based on the existing templates or similar treatlife devices. Does anyone have any idea? Would this require a teardown? :)
  • ADVERTISEMENT
  • #2 20463990
    p.kaczmarek2
    Moderator Smart Home
    Hello, this fan controller is a TuyaMCU device. Most likely very similar to that one:
    [BK7231T] TreatLife 3 Way Smart Dimmer Switch (DS02S)
    You will need to know dpIDs of each function, so we can write a config.

    I'd suggest this approach - go to Launch Web Application, LittleFS tab, create autoexec.bat, enter this content:
    
    startDriver TuyaMCU
    tuyaMcu_setBaudRate 115200
    

    save the file.

    Then, we will need log from reboot. Go to Log tab, then reboot device, clear the log, keep log tab open, set log level to "Debug", and once device reconnects and new log shows up, try pressing buttons on the device, etc, etc. Then copy paste full log here. The log will contain received TuyaMCU packets and we can look at their IDs and then write config to display them on screen.

    You might also want to see this:
    Tuya 5 Speed Fan Controller by TEQOOZ - Home Assistant
    QIACHIP Universal WIFI Ceiling Fan Light Remote Control Kit - BK7231N - CB2S
    Helpful post? Buy me a coffee.
  • #3 20464363
    rb2k
    Level 3  
    Not 100% sure if it accepted me setting things to 'debug', but these are the ones I could see:

    Button to turn fan off/on:
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 1, dataType 1-DP_TYPE_BOOL and 1 data bytes
    0 = off, 1 = on

    Button to set faster/slower fan speed:
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 3, dataType 4-DP_TYPE_ENUM and 1 data bytes
    Seems to be value 0 (slow) to 3 (fast)


    Other things I saw:
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 7 (State) with 12 bytes

    Here's the full logs:

    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 07 00 08 69 02 00 04 00 00 00 0B 8B 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 7 (State) with 15 bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 105, dataType 2-DP_TYPE_VALUE and 4 data bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: raw data 4 int: 11
    Debug:TuyaMCU:TuyaMCU_ApplyMapping: id 105 with value 11 is not mapped
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 03 00 00 05 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 3 (WiFiState) with 7 bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 07 00 05 01 01 00 01 01 12 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 7 (State) with 12 bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 1, dataType 1-DP_TYPE_BOOL and 1 data bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: raw data 1 byte: 
    Debug:TuyaMCU:TuyaMCU_ApplyMapping: id 1 with value 1 is not mapped
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 07 00 05 03 04 00 01 01 17 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 7 (State) with 12 bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 3, dataType 4-DP_TYPE_ENUM and 1 data bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: raw data 1 byte: 
    Debug:TuyaMCU:TuyaMCU_ApplyMapping: id 3 with value 1 is not mapped
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 07 00 05 03 04 00 01 02 18 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 7 (State) with 12 bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 3, dataType 4-DP_TYPE_ENUM and 1 data bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: raw data 1 byte: 
    Debug:TuyaMCU:TuyaMCU_ApplyMapping: id 3 with value 2 is not mapped
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 07 00 05 03 04 00 01 03 19 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 7 (State) with 12 bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 3, dataType 4-DP_TYPE_ENUM and 1 data bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: raw data 1 byte: 
    Debug:TuyaMCU:TuyaMCU_ApplyMapping: id 3 with value 3 is not mapped
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 07 00 05 03 04 00 01 02 18 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 7 (State) with 12 bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 3, dataType 4-DP_TYPE_ENUM and 1 data bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: raw data 1 byte: 
    Debug:TuyaMCU:TuyaMCU_ApplyMapping: id 3 with value 2 is not mapped
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 07 00 05 03 04 00 01 01 17 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 7 (State) with 12 bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 3, dataType 4-DP_TYPE_ENUM and 1 data bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: raw data 1 byte: 
    Debug:TuyaMCU:TuyaMCU_ApplyMapping: id 3 with value 1 is not mapped
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 07 00 05 03 04 00 01 00 16 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 7 (State) with 12 bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 3, dataType 4-DP_TYPE_ENUM and 1 data bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: raw data 1 byte: 
    Debug:TuyaMCU:TuyaMCU_ApplyMapping: id 3 with value 0 is not mapped
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 07 00 05 01 01 00 01 00 11 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 7 (State) with 12 bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 1, dataType 1-DP_TYPE_BOOL and 1 data bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: raw data 1 byte: 
    Debug:TuyaMCU:TuyaMCU_ApplyMapping: id 1 with value 0 is not mapped
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    
  • #4 20464532
    p.kaczmarek2
    Moderator Smart Home
    Very good! As you can clearly see, the dpID 1 is a boolean that controls the power on/off state of the fan, and the dpID 3 is an enumeration that seem to control speed of the fan. With that dpID information, you can update your autoexec.bat:
    
    startDriver TuyaMCU
    tuyaMcu_setBaudRate 115200
    
    // fan on/off channel
    setChannelType 1 toggle
    //fan speed channel
    setChannelType 3 OffLowMidHigh
    // linkTuyaMCUOutputToChannel dpId varType channelID
    // link output 1 to channel 1
    linkTuyaMCUOutputToChannel 1 bool 1
    // linkTuyaMCUOutputToChannel dpId varType channelID
    // link output 3 to channel 3
    linkTuyaMCUOutputToChannel 3 enum 3
    

    Please try it out, if there is a problem, I'll help you fix it.

    The config above assumes that speed setting is using OffLowMidHigh enumeration, so it has following options:
    - off (0)
    - low (1)
    - mid (2)
    - high (3)
    If you need different enumeration, let me know.

    Please reboot your device after making autoexec changes.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #5 20464561
    rb2k
    Level 3  
    That worked!

    One slightly weird behavior:

    If I set the speed to "off", the fan stops spinning, but the 'toggle' still shows it as "ON"
  • #6 20464563
    p.kaczmarek2
    Moderator Smart Home
    This seem to be by Tuya design, but if you want, we can hack it to behave better.

    Maybe something like that could help:
    
    addChangeHandler Channel3 == 0 setChannel 1 0
    

    It basically says: when channel 3 becomes 0, then set channel 1 to 0.
    And it basically means: when speed is set to off, then also set power to off.

    Put that in autoexec and reboot, and let's see if it works.s I hope that I haven't done any syntax errors.
    Helpful post? Buy me a coffee.
  • #7 20464565
    rb2k
    Level 3  
    That also worked!
    It does a bit of a weird 'double click', but that's fine with me :)

    I guess I could do the other way around as well: If I set the speed to low/medium/high, it should turn on the toggle

    I tried

    addChangeHandler Channel3 != 0 setChannel 1 1


    and it works o/

    The only odd thing left:

    If I just trigger the toggle, it will resume at whatever the previous speed was, but the speed selector doesn't update. Not sure if that can be handled or if it doesn't matter because I'll just surface the speed selector to homeassistant anyway
  • ADVERTISEMENT
  • #8 20465812
    p.kaczmarek2
    Moderator Smart Home
    I am not sure if I understand. If you set speed to level 3, and then turn off and on the toggle, then the speed level should be remembered by OpenBeken itself, since it wasn't changed.

    Or am I making some kind of logical error here?

    One of the possible solutions would be to catch the toggle setting to 1 event (again change handler) and then default speed to lowest one...

    Or do you mean... after reboot?
    Helpful post? Buy me a coffee.
  • #9 20466185
    rb2k
    Level 3  
    I think this might clarify it:

    /
    / Make sure that speed set to off turns the toggle off too
    addChangeHandler Channel3 == 0 setChannel 1 0
    // Make sure that turning on as speed also triggers the toggle
    addChangeHandler Channel3 != 0 setChannel 1 1
    // Set speed to "off" when toggle is set to off
    addChangeHandler Channel1 == 0 setChannel 3 0
    // Set speed to lowest when turning on via toggle
    addChangeHandler Channel1 == 1 setChannel 3 1


    It bothered me that when I turned the fan 'off', it still showed a speed rather than the 'off' position.
    I guess that's just how tuya set this up. With the ChangeHandlers I set up, I lose the memory, but at least I can tell that it's off :)
  • Helpful post
    #10 20466188
    p.kaczmarek2
    Moderator Smart Home
    It should be possible to script it to have the memory, for example, you could just use another channel (let's say channel 10) as a memory slot.

    You could also use one of the special-flash channels which are kept after reboot, just in the same way, as a memory slot.
    Code: C / C++
    Log in, to see the code

    If you do setChannel 200 123 then value 123 will be still at $CH200 even after reboot.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #11 20470082
    mattj
    Level 9  
    p.kaczmarek2 wrote:

    The config above assumes that speed setting is using OffLowMidHigh enumeration, so it has following options:
    - off (0)
    - low (1)
    - mid (2)
    - high (3)
    If you need different enumeration, let me know.


    Hey there @p.kaczmarek2 - thanks for this. I have this same device, but I have a different understanding.

    This fan has 4 active speeds (5 if you include off). Think of it as OFF or ON-lowest, ON-low, ON-med, ON-high —> naming however you’d see fit. That said, I don’t seem to see any similar enumeration that would fit here.

    For example, Toggle 1 = “ON” Speed = “OFF” is actually the lowest speed. Toggle 1 is correctly overriding the speed setting to turn it on or off.

    Side note: My unit suddenly started showing a flashing red light on it - not sure why. The web UI still works, as do the physical controls.
  • #12 20470714
    rb2k
    Level 3  
    Mine flashed red too, but then it stopped.
    Works fine still.

    Very odd, I could swear that for me, it’s just 4 speeds. The 5th one didn't move the blades. Might be a side effect of the fan I use though
  • #13 20470742
    p.kaczmarek2
    Moderator Smart Home
    Maybe LED blinks when it thinks it's not paired?

    OBK tells MCU it's paired when you have both WiFi and MQTT on.

    You can override it with:
    
    tuyaMcu_defWiFiState 3
    

    Refer to Tuya docs to see what the 3 is. If you set it, then device will all the time think it's pairede and configured and that it has server connection.

    Is there anything else I may help you with?
    Helpful post? Buy me a coffee.
  • #14 20471532
    mattj
    Level 9  
    Is there another enumeration which might apply better here? More of an aesthetic thing vs. functional - in the web UI.

    [BK7231T] Setting Up TreatLife DS02F Ceiling Fan Controller - Non-ESP Flashing

    Speed = "OFF" is actually Speed 1 or "Lowest".

    Also: sharing my YAML in case anyone needs it (and or has corrections - though it seems to work)
    fan:
      - unique_id: "ceiling_fan"
        name: "Ceiling Fan"
        state_topic: "fan/1/get"
        command_topic: "fan/1/set"
        percentage_state_topic: "fan/2/get"
        percentage_command_topic: "fan/2/set"
        speed_range_min: 1
        speed_range_max: 3
        qos: 1
        payload_on: 1
        payload_off: 0
        retain: true
        optimistic: true
    
  • #15 20471724
    rb2k
    Level 3  
    Ok, I'm finally back home and I have confirmed: Speed 0 ("Off") does indeed still move the blades!
    It seemed like it wasn't but the slowdown does indeed stop at some point and still spins them ever so slightly!

    I guess the 'off' in the selection is a bit confusing

    Added after 24 [minutes]:

    Currently trying to beef up the homeassistant config. It's not perfect yet, but I can select all 4 speeds:


      fan:
        - name: "Kid's Room Ceiling Fan"
          unique_id: "obk089F14CA"
          icon: mdi:ceiling-fan
          availability:
            - topic: "obk089F14CA/connected"
          payload_on: 1
          payload_off: 0
          state_topic: "obk089F14CA/1/get"
          command_topic: "obk089F14CA/1/set"
          percentage_state_topic: "obk089F14CA/3/get"
          percentage_command_topic: "obk089F14CA/3/set"
          percentage_value_template: '{{ (value | int   1) * 25 }}'
          percentage_command_template: "{{ ((value | int - 1) / 25) | int }}"
          preset_modes:
            - "lowest"
            - "low"
            - "medium"
            - "high"
          preset_mode_command_topic: "obk089F14CA/3/set"
          preset_mode_command_template: '{{ value | replace("lowest", "0") | replace("low", "1") | replace("medium", "2") | replace("high", "3") }}'
          preset_mode_value_template: '{{ value | replace("0", "lowest") | replace("1", "low") | replace("2", "medium") | replace("3", "high") }}'
          qos: 1
          retain: true
  • #16 20471958
    p.kaczmarek2
    Moderator Smart Home
    mattj wrote:
    Is there another enumeration which might apply better here?

    Very good question! I can add anything you want, but today I also added FULL documentation, take a look here:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/channelTypes.md
    Also see here:
    https://github.com/openshwprojects/OpenBK7231T_App/tree/main/docs

    Soon we will also have a docs page.
    Helpful post? Buy me a coffee.
  • #17 20472523
    mattj
    Level 9  
    Thanks so much! Documentation is much appreciated, and has been one of the gaps, but now it'll be easier to reference in posts.

    On the enumeration, I think there is the potential to add a new one. Today we have essentially options for a 3-speed and 5-speed controller. But this is a 4-speed one.

    3-Speed:
    * LowMidHigh
    * OffLowMidHigh
    5-Speed:
    * LowestLowMidHighHighest
    * OffLowestLowMidHighHighest

    Proposed 4-Speed:
    * Low, Mid, High, Highest
    * Off, Low, Mid, High, Highest

    (Alternatively could be "Lowest, Low, Mid, High" or "Lowest, Low, High, Highest" - personally I have no preference.)

    Thanks for all the amazing work - the pace at which OpenBeken's been growing has been great.
  • #18 20472547
    p.kaczmarek2
    Moderator Smart Home
    Thanks, I have added those channel types as you requested. I also updated docs, now there is a small readme:
    https://github.com/openshwprojects/OpenBK7231T_App/tree/main/docs
    [BK7231T] Setting Up TreatLife DS02F Ceiling Fan Controller - Non-ESP Flashing

    Docs are also automatically generated into JSON, so I can also feed them into some other system or dedicated website in the future
    Helpful post? Buy me a coffee.
  • #19 20474902
    azsoccerpop
    Level 2  
    Hi @p.kaczmarek2 I upgraded to the latest firmware version 1.15.565 using OTA but I do not see the 2 new channel types. I have it defined in autoexec.bat as
    //fan speed channel
    setChannelType 3 OffLowMidHighHighest
    // map dpid3 to channel3, var type 4 (enum)
    linkTuyaMCUOutputToChannel 3 4 3

    And I have rebooted but still only see the original OffLowMidHigh which was originally configured. Thank you for any help and your work on this project. I was glad not to have to desolder and replace the Tuya chip with an ESP-12.
  • #20 20475035
    p.kaczmarek2
    Moderator Smart Home
    Thank you for reporting the issue. The string names were indeed not refreshed in the build. Please get the next release, I have made sure that they are present now. The automatic github build should be ready within 10 minutes.
    Helpful post? Buy me a coffee.

Topic summary

The discussion revolves around setting up the TreatLife DS02F Ceiling Fan Controller, which is identified as a TuyaMCU device. The user successfully flashed the device using Tuya Cloudcutter and a specific JSON template. They sought assistance with configuring the device for non-ESP flashing, particularly in identifying dpIDs for various functions. The community provided guidance on creating an autoexec.bat file to manage the device's settings, including power and speed controls. The user shared logs that revealed the dpIDs for fan control, leading to a configuration that allowed for toggling power and adjusting fan speed. Several change handlers were implemented to synchronize the toggle and speed settings, addressing issues with the device's behavior. The conversation also touched on the device's speed settings and the potential for adding new enumerations for better functionality. Documentation updates and firmware improvements were discussed to enhance user experience.
Summary generated by the language model.
ADVERTISEMENT