Elektroda.com
Elektroda.com
X
Elektroda.com

OpenBeken on MOES/Andeli TuyaMCU switch

Tow96 2481 4
  • OpenBeken on MOES/Andeli TuyaMCU switch
    In this thread I'll explain how to re-flash this TuyaMCU smartswitch with OpenBeken and connect it to HomeAssistant. OpenBeken is an alternative, open source software for IoT devices, offering, among others independence from the manufacturer's cloud, compatibility with many ecosystems, configurability and support for various platforms, including BK7231T, BK7231N, XR809 and BL602.
    For more information about OpenBK, please see: [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant
    For more information about BL602 support: Tasmota replacement for BL602, programming, pairing with Home Assistant.

    Where to purchase the switch
    The switch was bought from AliExpress by searching: ANDELI Tuya Smart Life Wifi Light Switch with Glass Panel US Standard Touch Sensor Wall Switches Voice Control Alexa Google Home However, other people refer to this switch as a MOES Switch so it's very likely that this is a dropship product and multiple brands will have the same internal components.
    OpenBeken on MOES/Andeli TuyaMCU switch

    The voltage range of the device is 100-250V 50/60Hz and a max current of 10A. It connects to WiFi using a 2.4GHz signal.

    The interior of the switch
    Since it is designed to be mounted on a wall, the glass plate can be easily removed, allowing us to dissasemble it without any tools. The switch is composed of two boards, the main board: Where the TuyaMCU and the WB2S chips are located, and a daughter board, where the relays and power are located.
    OpenBeken on MOES/Andeli TuyaMCU switch
    OpenBeken on MOES/Andeli TuyaMCU switch

    We are only interested on the main board.

    Flashing the WB2S
    The main board comes with some pads that link directly to VCC, GND, TX and RX. Here is an example of which ones where on my board. Verify that they are correct in your board, as I've seen other revisions on the internet.

    OpenBeken on MOES/Andeli TuyaMCU switch

    I did some tests and it seems that it is not necessary to remove the TuyaMCU chip from the board for the WB2S however, in case that you're having troubles, desolder pin 1 to disconnect it

    OpenBeken on MOES/Andeli TuyaMCU switch

    Flash the chip following the instructions from OpenBeken in my case, I was only able to do it using python. The flash tool needs to be at 3.3V



    Once the chip is flash it, remove the soldered cables, reconnect the TuyaMCU if you had desoldered it and reassemble the box, as it seems that the TuyaMCU does not fully boot unless it is plugged to the daugtherboard (probably the reason we can flash it without desoldering).
    OpenBeken on MOES/Andeli TuyaMCU switch

    OpenBeken configuration
    After basic configuration is done (see OpenBeken), a startup file named autoexec.bat with the following contents.
    Code:

    startDriver TuyaMCU
    setChannelType 1 toggle
    linkTuyaMCUOutputToChannel 1 1 1

    setChannelType 2 toggle
    linkTuyaMCUOutputToChannel 2 1 2

    setChannelType 3 toggle
    linkTuyaMCUOutputToChannel 3 1 3


    In the App panel, drag the file to the OBK file system:
    OpenBeken on MOES/Andeli TuyaMCU switch
    This file will be automatically executed after every reboot. It needs to be restarted manually the first time

    Meaning of individual commands:
    - startDriver TuyaMCU - runs the TuyaMCU driver
    - setChannelType n toggle - set the type of channel number n to On / Off
    - linkTuyaMCUOutputToChannel n bool 1 - connects TuyaMCU dpID number 1 with bool type channel number 1

    The dpID values can be different for different kinds of devices. If we want to add support for something new, we need to get to know it, e.g. by listening for packages. The dpID values can also be taken from the descriptions of devices intended for Tasmota, because Tuya often only changes the WiFi module and the rest remains the same.

    In the case of this switch there are 4 dpID values (dpID1 trough dpID4) that set the state of each relay, there are four as this chip is used for al versions of switch (from 1 to 4 gang), so only the dpID's for the switches that are physically present are needed.

    There is another set of 4 dpID (dpID7 to dpID10) which are of type val which toggle the relay after a number of seconds have passed (the user input's the number) I didn't link them as I don't have any use for them, however I'll document it in case they are needed for your application.

    After restarting, the buttons are now visible:
    OpenBeken on MOES/Andeli TuyaMCU switch

    Home Assistant Support
    Pairing with Home Assistant is very simple, all thanks to the automatic mapping of OpenBeken channels to TuyaMCU variables. The TuyaMCU switch is operated from the HA level in the same way as an ordinary switch. Here is a sample Yaml code:
    Code:

    switch:
      - platform: mqtt
        #   state_color: true
        name: "Test A Switch (1)"
        unique_id: "TestB_1"
        availability:
          - topic: "TestB/connected"
        state_topic: "TestB/1/get"
        state_on: 1
        state_off: 0
        command_topic: "TestB/1/set"
        payload_on: 1
        payload_off: 0
        qos: 1
      - platform: mqtt
        #   state_color: true
        name: "Test A Switch (2)"
        unique_id: "TestB_2"
        availability:
          - topic: "TestB/connected"
        state_topic: "TestB/2/get"
        state_on: 1
        state_off: 0
        command_topic: "TestB/2/set"
        payload_on: 1
        payload_off: 0
        qos: 1
      - platform: mqtt
        #   state_color: true
        name: "Test A Switch (3)"
        unique_id: "TestB_3"
        availability:
          - topic: "TestB/connected"
        state_topic: "TestB/3/get"
        state_on: 1
        state_off: 0
        command_topic: "TestB/3/set"
        payload_on: 1
        payload_off: 0
        qos: 1


    Final test



    Cool? Ranking DIY
    Can you write similar article? Send message to me and you will get SD card 64GB.
    About Author
    Tow96
    Level 3  
    Offline 
    Tow96 wrote 5 posts with rating 7, helped 0 times. Been with us since 2022 year.
  • #2
    khoam
    Level 41  
    In this video ("Final test") you can not see what is happening when controlling from a smartphone. Unless my browser is hiding it.
  • #3
    p.kaczmarek2
    Level 28  
    Thank you for inserting the test and I'm glad that TuyaMCU works for you. Basically, I tested TuyaMCU only on the basis of the Moes dimmer, but I can see that the well-implemented protocol also works in other use cases.

    If I find a moment, I will improve the Polish translation, because so far it is only machine-made and there are incomprehensible fragments in it. As if what, wait.

    @khoam I have the impression that it is about the backlight of the buttons, it lights up when the user changes the relay status on the phone. But you are right, the contrast is weak and you can barely see it.


    PS: Such a curiosity - I found a new chip that I will probably start to support:
    OpenBeken on MOES/Andeli TuyaMCU switch
    There is an SDK for it, some IDE, and a dev board for aliexpress and it looks like the demo is compiling correctly. But about that in a different topic ...
  • #4
    krisRaba
    Level 31  
    There is probably a white backlight of the circle and at least on the second and third individually switched on, you can see that the backlight turns on gently ... But you actually have to strain your eyesight ;)
  • #5
    khoam
    Level 41  
    krisRaba wrote:
    There is probably a white backlight of the circle and at least on the second and third individually switched on, you can see that the backlight turns on gently ... But you actually have to strain your eyesight

    The author should frame the video to the smartphone itself and this gadget from Tuya. It does not matter that it has four T12 bits :)