esphome / feature-requests

ESPHome Feature Request Tracker
https://esphome.io/
411 stars 26 forks source link

Support for Zemismart BCM500DS-TYW curtain motor #1896

Open leoshusar opened 1 year ago

leoshusar commented 1 year ago

Describe the problem you have/What new integration you would like I would like to get support for my Zemismart curtain motor BCM500DS-TYW

Please describe your use case for this integration and alternatives you've tried: I've tried the current tuya/cover component but it doesn't work 100% for my motor

Additional context

I've got Zemismart curtain motor BCM500DS-TYW, it comes with TYWE1S and I was able to flash ESPHome to it. Then I tried to configure it using tuya/cover component, however it seems to communicate somehow differently than the already verified motor.

First thing is, it gets stuck on init_state 3:

[00:39:51][C][logger:275]: Logger:
[00:39:51][C][logger:276]:   Level: VERY_VERBOSE
[00:39:51][C][logger:277]:   Log Baud Rate: 0
[00:39:51][C][logger:278]:   Hardware UART: UART0
[00:39:51][C][uart.arduino_esp8266:102]: UART Bus:
[00:39:51][C][uart.arduino_esp8266:103]:   TX Pin: GPIO15
[00:39:51][C][uart.arduino_esp8266:104]:   RX Pin: GPIO13
[00:39:51][C][uart.arduino_esp8266:106]:   RX Buffer Size: 256
[00:39:51][C][uart.arduino_esp8266:108]:   Baud Rate: 9600 baud
[00:39:51][C][uart.arduino_esp8266:109]:   Data Bits: 8
[00:39:51][C][uart.arduino_esp8266:110]:   Parity: NONE
[00:39:51][C][uart.arduino_esp8266:111]:   Stop bits: 1
[00:39:51][C][uart.arduino_esp8266:113]:   Using hardware serial interface.
[00:39:51][C][tuya.cover:107]: Tuya Cover:
[00:39:51][C][tuya.cover:116]:    Control has datapoint ID 102
[00:39:51][C][tuya.cover:118]:    Direction has datapoint ID 103
[00:39:51][C][tuya.cover:120]:    Position has datapoint ID 101
[00:39:51][C][tuya:033]: Tuya:
[00:39:51][C][tuya:038]:   Configuration will be reported when setup is complete. Current init_state: 3
[00:39:51][C][tuya:041]:   If no further output is received, confirm that this is a supported Tuya device.
[00:40:02][V][tuya:383]: Sending Tuya: CMD=0x00 VERSION=0 DATA=[] INIT_STATE=3
[00:40:02][D][uart_debug:114]: >>> 55:AA:00:00:00:00:FF
[00:40:02][V][tuya:120]: Received Tuya: CMD=0x00 VERSION=0 DATA=[01] INIT_STATE=3
[00:40:02][V][tuya:148]: MCU Heartbeat (0x01)
[00:40:02][D][uart_debug:114]: <<< 55:AA:00:00:00:01:01:01
[00:40:17][V][tuya:383]: Sending Tuya: CMD=0x00 VERSION=0 DATA=[] INIT_STATE=3
[00:40:17][D][uart_debug:114]: >>> 55:AA:00:00:00:00:FF
[00:40:17][V][tuya:120]: Received Tuya: CMD=0x00 VERSION=0 DATA=[01] INIT_STATE=3
[00:40:17][V][tuya:148]: MCU Heartbeat (0x01)
[00:40:17][D][uart_debug:114]: <<< 55:AA:00:00:00:01:01:01

and the heartbeat response is 55:AA:00:00:00:01:01:01 - found in the docs here. It looks like they are for some reason using Bluetooth protocol for WiFi module?

But ESPHome seems to work even with incomplete init state. What could happen if I keep it running like this? Won't ESPHome complain after some time or something? Would it be possible to implement this too?

However the main problem is, my motor has swapped close and stop command completely swapped commands. It should be:

close: 0
open: 1
stop: 2

I was able to find this - it says legacy only, so maybe my TuyaMCU uses some kind of legacy protocol?

And here I was able to query my datapoints using Tuya API, which is great, after finding many posts about how people do it by trial / error:

{
  "result": {
    "category": "cl",
    "functions": [
      {
        "code": "mach_operate",
        "dp_id": 102,
        "type": "Enum",
        "values": "{\"range\":[\"ZZ\",\"FZ\",\"STOP\"]}"
      },
      {
        "code": "opposite",
        "dp_id": 103,
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "position",
        "dp_id": 101,
        "type": "Integer",
        "values": "{\"unit\":\"%\",\"min\":0,\"max\":100,\"scale\":0,\"step\":1}"
      }
    ],
    "status": [
      {
        "code": "opposite",
        "dp_id": 103,
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "mach_operate",
        "dp_id": 102,
        "type": "Enum",
        "values": "{\"range\":[\"ZZ\",\"FZ\",\"STOP\"]}"
      },
      {
        "code": "position",
        "dp_id": 101,
        "type": "Integer",
        "values": "{\"unit\":\"%\",\"min\":0,\"max\":100,\"scale\":0,\"step\":1}"
      }
    ]
  },
  "success": true,
  "t": 1664316569647
}

Let me know if you need anything else. Thank you!

dancwilliams commented 1 year ago

@leoshusar Did you ever get the BCM500DS-TYW flashed?

leoshusar commented 1 year ago

@dancwilliams Yes, I made a messy workaround, but it works!

You can download my custom component and extract it to esphome/custom_components (the path will look like esphome/custom_components/tuya_cover_fix). It's just the official Tuya component and I hardcoded correct codes for this model. tuya_cover_fix.zip

Then your YAML will look like this:

cover:
  - platform: tuya_cover_fix
    device_class: curtain
    name: "curtain"
    control_datapoint: 102
    position_datapoint: 101
    direction_datapoint: 103

The log still complains about the init_state: image

but it doesn't block anything.

dancwilliams commented 1 year ago

@leoshusar Awesome! Thanks! What method did you use to flash ESPHome onto the device?

leoshusar commented 1 year ago

@dancwilliams no problem!

Do you actually have an ESP chip in there? Tuya started swapping ESPs for chinese Beken chips several months ago, incompatible with ESPHome and Tasmota.

If you have TYWE1S with ESP, you can follow this guide, solder few wires to it and it should just work.

If you have non-ESP module (just google its model number), you have two options: 1) Solder ESP instead of it 2) Try OpenBK7231T_App - it's a Tasmota "clone" (built from scratch I believe) for those chinese chips, but I won't tell you if and how it would work with this motor.

dancwilliams commented 1 year ago

@leoshusar I have the TYWE1S so I am good to go! Thanks for the links.

IMG_2622