athombv / com.tuya

Tuya app for Homey
https://homey.app/a/com.tuya
3 stars 4 forks source link

Request Device: Ceiling Fan #8

Open givemelove opened 4 weeks ago

givemelove commented 4 weeks ago

Looking to get Ceiling Fans added as a supported device. I have 4 devices (same make / model). They are a combo ceiling fan and lamp. Here's an Amazon link for the item

The core functionality would be to be able to operate the fan (speeds) and the light (color and dimmer).

There are some features that could be a plus but may be overkill for a v1.

Here's the info for one device, with the key and PII info removed:

{"active_time":1717640325,"biz_type":0,"category":"fs","create_time":1715646363,"icon":"smart/icon/ay1540882177261iTAUO/55bba57fc88d7744bcdc8f541384b126.jpg","id":"string","ip":"ip_address","lat":"numeric","local_key":"string","lon":"numeric","model":"SF-52","name":"One","online":true,"owner_id":"196613604","product_id":"t0qzrmur7pyzjuco","product_name":"","status":[{"code":"switch","value":false},{"code":"fan_speed_percent","value":6},{"code":"light","value":true},{"code":"bright_value","value":100},{"code":"temp_value","value":0}],"sub":false,"time_zone":"-05:00","uid":"string","update_time":1717676232,"uuid":"string"}

---- Instructions ----

To request a new device, please run the Tuya app locally using Homey CLI.

$ git@github.com:athombv/com.tuya.git
$ cd com.tuya
$ homey app run 

Then pair a 'Light', even if your device is not a light. Watch the logging closely for Device: and copy-paste the JSON in this issue.

Without this information, we cannot add support for your device, and the issue will be closed.

For example:

2024-06-06T14:11:59.852Z [log] [Homey:xxxxxx] [ManagerDrivers] [Driver:light] Device: {"active_time":1717491339,"biz_type":0,"category":"dj","create_time":1717491339,"icon":"smart/icon/bay1582725542891RIK5/42feb5d93f5e13800cf2ade23ea49459.png","id":"xxxxxx","ip":"xxxxxx","lat":"52.25","local_key":"xxxxx","lon":"6.3","model":"SH.63.204","name":"G95 Gold","online":true,"owner_id":"xxxxx","product_id":"xxxxxx","product_name":"G95 Gold","status":[{"code":"switch_led","value":true},{"code":"work_mode","value":"white"},{"code":"bright_value_v2","value":223},{"code":"temp_value_v2","value":0},{"code":"scene_data_v2","value":"{\"scene_num\":1,\"scene_units\":[{\"bright\":200,\"h\":0,\"s\":0,\"temperature\":0,\"unit_change_mode\":\"static\",\"unit_gradient_duration\":13,\"unit_switch_duration\":14,\"v\":0}]}"},{"code":"countdown_1","value":0},{"code":"control_data","value":""},{"code":"remote_switch","value":true}],"sub":false,"time_zone":"+02:00","uid":"xxxxxx","update_time":1717671377,"uuid":"xxxxxx"}

Finally, please link to more information about the device, e.g. the manufacturer's website.

gslender commented 4 weeks ago

Here is my info for one of my 4 fans...

{
  "active_time": 1717647195,
  "biz_type": 0,
  "category": "fs",
  "create_time": 1717647195,
  "icon": "smart/icon/ay1535601660405KA72f/50bfec90efcce440ec075e664d894f76.png",
  "id": "bf6fb59e48cf4a6ccckunc",
  "ip": "########",
  "lat": "-26.41",
  "local_key": "###########",
  "lon": "153.11",
  "model": "MZ-DCFAN",
  "name": "Lounge Fan",
  "online": true,
  "owner_id": "34319071",
  "product_id": "agyqzsfpafsvkrl9",
  "product_name": "DC吊扇",
  "status": [
    {
      "code": "switch",
      "value": false
    },
    {
      "code": "fan_speed_percent",
      "value": 2
    },
    {
      "code": "light",
      "value": false
    },
    {
      "code": "bright_value",
      "value": 1000
    },
    {
      "code": "temp_value",
      "value": 550
    }
  ],
  "sub": false,
  "time_zone": "+10:00",
  "uid": "eu1626678725509Ny23z",
  "update_time": 1717647235,
  "uuid": "b0c10c799234a73e"
}
gslender commented 4 weeks ago

Have added a driver for Fan and got onOff Capability working in a fork for anyone who is interested.

https://github.com/gslender/com.tuya

I will probably add speed control, but recognise there is no inbuilt capability for Homey for fan speed. My Tuya fans support 6 speeds but report them (oddly) as a % between 0 and 100, but only respond to 0,1,2,3,4,5,6 as the functional values that work !?

EDIT: Looks like the HA guys ran into this issue too and the Tuya code isn't actually reporting 0-100% for speed but between 0-6% which is bonkers. https://github.com/home-assistant/core/issues/65100

givemelove commented 4 weeks ago

@gslender I can confirm I can see my 4 fans as well. The fan on/off seems to work great

gslender commented 4 weeks ago

Have updated the app on my fork to include dim/level capability restricted to 1-6 with 1 value steps. Note sure how Athom will attempt to address this as there is no real way to know how many values the fan will support. Doesn't look like Tuya provide that information or maybe it is a bug in their API. It works, but if your fan only support 4 speeds (or has more than 6) then what I've coded won't work for you.

EDIT: You will need to delete and recreate the devices in Homey for the fan to have the new dim/speed control.

WeeJeWel commented 3 weeks ago

Fixed by https://github.com/athombv/com.tuya/pull/14.

givemelove commented 3 weeks ago

Hey folks,

While the fan portion works, I was wondering if we have the ability to address the light piece.

In the original request, the status key is an array that contains multiple capabilities (Switch, Brightness, Fan Switch, Fan Speed). While the latter two were added, is there a way to add the light switch component as well?

gslender commented 3 weeks ago

@givemelove if you send the status console output, I would be willing to look at adding it to my fork, you test and confirm it works, and then I can submit another PR if @WeeJeWel is happy with that approach

WeeJeWel commented 3 weeks ago

Sounds good!

givemelove commented 3 weeks ago

Thanks, I appreciate it. Happy to help in any way.

@gslender what do you need exactly? You need to to run the latest integration locally and give you some logs once I trigger a device, is that it?

gslender commented 3 weeks ago

@givemelove is the detail in the OP as per the missing features of the fan/light?

gslender commented 3 weeks ago

@givemelove I would also need you to switch to my fork at https://github.com/gslender/com.tuya/ to test and confirm that the changes are correct - so whilst I have a Tuya fan, mine don't have the light features

gslender commented 3 weeks ago

Actually, @WeeJeWel would you mind thinking about how you wish a combo fan-light would be respresented in Homey? I have had this same issue with a wall switch that was a combo fan and light switch (zigbee) and I personally prefer having a single device that is able to (via an enum have fan off, low, medium, high) leaving the on/off for the light. In this specific Tuya case it also has a dimmer so that's adding another dimmer capabilty assuming the fan is pushed into an enum. I think it would be worthwhile thinking about a specific fan capability and maybe even a specific UI control that allows for on/off and levels (number or text labelled) that can be a slider etc.

@givemelove what's your thoughts ??

gslender commented 3 weeks ago

@WeeJeWel can you reopen this please too?

givemelove commented 2 weeks ago

@gslender Yeah, I can switch to your fork, that's not a problem. Yes, the missing features should be in my OP. The device I listed there has both capabilities.

With regards to your latter post re: how it would be represented in Homey, personally I may have a slight preference towards the multiple devices. While a single device could be "easier" for understanding that it's a single unit in the GUI, having a device per feature could also be beneficial for someone who uses the gui to trigger devices. I personally plan on using the fan with some flow rules so it doesn't really matter to me.

with that being said, I'm not familiar with other Tuya devices that may have multiple capabilities. If there's a device with 4 or so capabilities, it may become cumbersome to render all of that on the same card.

gslender commented 2 weeks ago

Sorry @givemelove I'm waiting on @WeeJeWel to provide some guidance on how to attack a device that has combo light and fan. Also, having a fan specific capability and UI would also help to ensure we can turn the fan on/off/low/med/high along with custom levels if the fan speed can be 1 to 6 or similar. I think adding the fan UI so that you can have a combo onOff, dim, fan capability would be ideal

WeeJeWel commented 2 weeks ago

Hey! Yeah this is a challenge 😅 The way I see it there are two options forward:

  1. Add multiple capabilities to the same device, e.g. onoff.light.
  2. Return two devices, one with the fan class and one with the light class, and let the user add two devices separately during pairing.

I would prefer option 2, because it works better with the 'Lights' control in the mobile app, and also speech commands such as 'Turn off all lights'.

We do need to change a bit in the Webhooks mechanism to allow two devices with the same ID receive those events though.

gslender commented 2 weeks ago

What about adding a specific Capability and UI for fan ??

WeeJeWel commented 2 weeks ago

That's something on the roadmap, but not really relevant if we want to have this working in the next few days :)

gslender commented 2 weeks ago

Fair point. Leave with me to have a play

@givemelove I will reach out again when I've got a commit in my fork that you can try and provide feedback

@WeeJeWel any chance to reopen the issue?

gslender commented 2 weeks ago

@givemelove jump over to my fork at https://github.com/gslender/com.tuya/ and run the app as homey app run -r and report any issues or problems along with the output in the console.

You will need to delete and create a new device (a Fan Light Combo) and this should work if my guess about what's required is correct. Note that I've used the volume_mute and volume_set controls to hopefully mimic something that will allow you to control the fan, leaving the onoff and dim for the light.

givemelove commented 1 week ago

@gslender Apologies for the delayed response. The capabilities you implemented work. I can control both lighting and the fan on my devices. Thank you

gslender commented 1 week ago

@WeeJeWel the new PR I've raised would be sufficient (initially) for the multi-fan-light device to operate, though I'd recommend you consider adding a specific UI and fan-capabilities in the long term