PlusPlus-ua / ha_tuya_ble

Home Assistant support for Tuya BLE devices
MIT License
155 stars 98 forks source link

Devices supporting both WiFi and BLE #85

Open BillyNate opened 7 months ago

BillyNate commented 7 months ago

@PlusPlus-ua Thank you for your time and effort setting up ha_tuya_ble. I noticed you have no commits pushed to GitHub since July and stated you're working in Ukraine. I sincerely hope you and your family are safe.

I noticed that if a device has both WiFi and BLE integrated and it is connected to the Tuya Cloud, the WiFi mac address is used in the cloud. ha_tuya_ble uses the BLE mac address to identify the device, but since this differs from the mac stored in the cloud it won't be able to identify it correctly. I got two devices, here's the mac addresses:
10:5A:17:CF:99:DA (WiFi mac, stored in the cloud)
10:5A:17:CF:99:DB (BLE mac, used by ha_tuya_ble) and
1C:90:FF:8B:D5:C0 (WiFi mac, stored in the cloud)
1C:90:FF:8B:D5:C1 (BLE mac, used by ha_tuya_ble)

So the BLE mac is offset by one from the WiFi mac. That could be a good starting point for supporting these devices.
If anyone needs any additional information, feel free to ask.

BillyNate commented 7 months ago

I created a "quick fix" to test this by adding

if credentials is None:
  credentials = item.credentials.get(address[:-2] + "{:2X}".format(int(address[-2:], 16) - 1))

to cloud.py after line 268.
The BLE devices have now been added to HA.