milo526 / homebridge-tuya-web

Hoobs and Homebridge plugin for Tuya devices using Home Assistant Tuya Web Api
MIT License
219 stars 95 forks source link

[Accessory Request] Cover accessory #18

Open Fannangir opened 4 years ago

Fannangir commented 4 years ago

Hi, After moving from vitramirs fork to this one, I receive the following messages:

[TuyaWebPlatform] Could not init class for device type [cover]

My cover devices do not work

sybrendotinga commented 3 years ago

Yeah what I suspect to be the best way would be - allow users to define how many seconds it takes to open or close. And based on the percentage (or difference in percentage) perform the open (or close) action for a certain amount of time.

Which is freaking ugly

I haven't really looked into the API (can't find any documentation), but I know that I had to update the 'schedule time', because my cover wasn't opening all the way.

image

Maybe you can use this value to determine how far 50% is? I don't think you can fetch the current percentage from the API, right?

If you have any documentation, can you share it? Maybe I can help you looking in to it.

milo526 commented 3 years ago

I see that there is some unclarity here and that is partly on me for not being clear myself.

I will not add support for opening a window a certain percentage anytime soon.

This is mainly because it is very hard for me to actually test this since I do not own any of these Tuya-based window coverings. This is partly because I have strong reason to suspect that this feature will be less than elegant at best and will trigger a lot of extra issues. I do not wish these upon me right now.

If somebody else wishes to work on this (@sybrendotinga ?) please feel welcome. This would probably require changes to currentPosition.ts and to targetPosition.ts.

The closest thing to "documentation" is the PaulAnnekov/tuyaha repository. It has a python implementation for this API. It is also used by the Home Assistant integration. From there you should take a look at the cover.py class.

sybrendotinga commented 3 years ago

I tried to fork your repo this summer and tried to implement it myself, but I got stuck at the same things as you: bad documentation and I expected a lot of (external influenced) issues/side-effects based on the "time to open" solution.

milo526 commented 3 years ago

there might be a way to get percentage based open and close to work since somebody might be willing to sponsor me a curtain device.

For the ones of you that see support_stop: True in their output above, could you please let me know the make and model (and preferably a direct link to where you purchased it)

This way I can hopefully buy such a device that has the required characteristics.

sybrendotinga commented 3 years ago

there might be a way to get percentage based open and close to work since somebody might be willing to sponsor me a curtain device.

For the ones of you that see support_stop: True in their output above, could you please let me know the make and model (and preferably a direct link to where you purchased it)

This way I can hopefully buy such a device that has the required characteristics.

How/where can I receive this information?

Is it this script? https://github.com/milo526/homebridge-tuya-web

milo526 commented 3 years ago

You can use the steps under "How to check whether the api this library uses can control your device".

sybrendotinga commented 3 years ago

Thanks @milo526, hopefully this helps:

{
   "header":{
      "code":"SUCCESS",
      "payloadVersion":1
   },
   "payload":{
      "devices":[
         {
            "data":{
               "brightness":"255",
               "color_temp":5482,
               "online":True,
               "state":"false"
            },
            "dev_type":"light",
            "ha_type":"light",
            "icon":"https://images.tuyaeu.com/smart/icon/ay1541056239985fDGjj/15620320506d600f63b54.png",
            "id":"15680460c44f33a60b25",
            "name":"LED SMART Schutting"
         },
         {
            "data":{
               "brightness":"255",
               "color_temp":5482,
               "online":True,
               "state":"false"
            },
            "dev_type":"light",
            "ha_type":"light",
            "icon":"https://images.tuyaeu.com/smart/icon/ay1541056239985fDGjj/15620320506d600f63b54.png",
            "id":"15680460c44f33a5d2f8",
            "name":"LED SMART Poort"
         },
         {
            "data":{
               "online":True,
               "state":3,
               "support_stop":True
            },
            "dev_type":"cover",
            "ha_type":"cover",
            "icon":"https://images.tuyaeu.com/smart/icon/ay1509430484182dhmed/158372064901fba692f5f.png",
            "id":"bfb7e198ec8aa592e4xqyr",
            "name":"Zonnescherm"
         },
         {
            "data":{
               "brightness":"255",
               "color_temp":5482,
               "online":False,
               "state":"false"
            },
            "dev_type":"light",
            "ha_type":"light",
            "icon":"https://images.tuyaeu.com/smart/icon/ay1541056239985fDGjj/15620320506d600f63b54.png",
            "id":"15680460c44f33a7018e",
            "name":"LED SMART Achterin"
         }
      ],
      "scenes":[

      ]
   }
}

Maybe you can share your thoughts so we can discuss your solution.

milo526 commented 3 years ago

So @sybrendotinga your device does support the stop functionality (The "Zonnescherm" device), could you post a link to the device that you use? So I can also buy it and ensure that I have a device with the proper functionality.

sybrendotinga commented 3 years ago

So @sybrendotinga your device does support the stop functionality (The "Zonnescherm" device), could you post a link to the device that you use? So I can also buy it and ensure that I have a device with the proper functionality.

I would not recommend that ;-) It is to control my sunscreen ;-) https://nl.aliexpress.com/item/32963064005.html

Maybe @Pelagious, @taaa22 or @Aekung can share theirs?

milo526 commented 3 years ago

Stop functionality is now tracked in #145 Percentage based open is now tracked in #148

If you are interested in either, please subscribe to the relevant issues.

For some users there is a bug in which the curtains are in a opening or closing state. This is a bug and is tracked in #143

taaa22 commented 3 years ago

So @sybrendotinga your device does support the stop functionality (The "Zonnescherm" device), could you post a link to the device that you use? So I can also buy it and ensure that I have a device with the proper functionality.

I would not recommend that ;-) It is to control my sunscreen ;-) https://nl.aliexpress.com/item/32963064005.html

Maybe @Pelagious, @taaa22 or @Aekung can share theirs?

Smart Automatic Curtain Motor Track System Smart Motorized Chain Roller Blinds

bSr43 commented 3 years ago

Hello,

Thank you for the plugin. I'm new to HomeBridge, so please forgive me if I've done anything wrong. I have a bunch of cover accessories from Konyks.

I've successfully installed HomeBridge and your plugin, the accessories have been discovered and they appear in HomeKit on my iDevices.

The problem I have is that the status shown in the Home application is not always correct.

In fact, after looking at the logs and the code (I'm not Typescript fluent, sorry about that…) it appears that the status of the accessories is updated by requesting their state from the cloud. The state can be either 1, 2 or 3 on this accessory. But if I understand the code of targetPosition.ts correctly, you assume that the state 1 means "opened", state 2 is "half opened" and state 3 is "closed". But from my experience, the state variable returned by the cloud server reflects the cover motor state, if it is currently active or not, and its direction; the states are 1 for "motor is active, and cover is opening", 2 for "motor is active, and cover is closing" and 3 for "motor is stopped". The state of the cover itself is not returned by the accessory, only the state of the motor is.

This is why, even if my covers are open, their states turn to "closed" after a few minutes, because the motor is stopped (state 3) and the plugin thinks that the cover is closed.

milo526 commented 3 years ago

Thanks for that update @bSr43, this is exactly the issue with me not yet owning one of these devices 😛. The previous api output suggested that the state was used to indicate if a window is opened or not. Your explanation seems to fit in with the bug described in #143. Could you confirm that the API output is identical on all accounts when your cover accessories are fully opened and fully closed.

bSr43 commented 3 years ago

I have used the debug_discovery.py tool and the JSON looks like that:

{
    "header": {
        "code": "SUCCESS",
        "payloadVersion": 1
    },
    "payload": {
        "devices": [
            {
                "data": {
                    "online": true,
                    "state": 3,
                    "support_stop": true
                },
                "dev_type": "cover",
                "ha_type": "cover",
                "icon": "https://images.tuyaeu.com/smart/icon/ay1518345874298thrlS/157594986436cfb8dfee1.jpg",
                "id": "xxxxxxxxxxxxxxxxxxxx",
                "name": "Volet baie vitrée 1"
            },
            {
                "data": {
                    "online": true,
                    "state": 3,
                    "support_stop": true
                },
                "dev_type": "cover",
                "ha_type": "cover",
                "icon": "https://images.tuyaeu.com/smart/icon/ay1518345874298thrlS/157594986436cfb8dfee1.jpg",
                "id": "xxxxxxxxxxxxxxxxxxxx",
                "name": "Volet cellier"
            },
            {
                "data": {
                    "online": true,
                    "state": 3,
                    "support_stop": true
                },
                "dev_type": "cover",
                "ha_type": "cover",
                "icon": "https://images.tuyaeu.com/smart/icon/ay1518345874298thrlS/157594986436cfb8dfee1.jpg",
                "id": "xxxxxxxxxxxxxxxxxxxx",
                "name": "Volet salon 2"
            },
            {
                "data": {
                    "online": true,
                    "state": 3,
                    "support_stop": true
                },
                "dev_type": "cover",
                "ha_type": "cover",
                "icon": "https://images.tuyaeu.com/smart/icon/ay1518345874298thrlS/157594986436cfb8dfee1.jpg",
                "id": "xxxxxxxxxxxxxxxxxxxx",
                "name": "Volet cuisine"
            },
            {
                "data": {
                    "online": true,
                    "state": 3,
                    "support_stop": true
                },
                "dev_type": "cover",
                "ha_type": "cover",
                "icon": "https://images.tuyaeu.com/smart/icon/ay1518345874298thrlS/157594986436cfb8dfee1.jpg",
                "id": "xxxxxxxxxxxxxxxxxxxx",
                "name": "Volet salon 1"
            },
            {
                "data": {
                    "online": true,
                    "state": 3,
                    "support_stop": true
                },
                "dev_type": "cover",
                "ha_type": "cover",
                "icon": "https://images.tuyaeu.com/smart/icon/ay1518345874298thrlS/157594986436cfb8dfee1.jpg",
                "id": "xxxxxxxxxxxxxxxxxxxx",
                "name": "Volet baie vitrée 2"
            },
            {
                "data": {
                    "online": true,
                    "state": 3,
                    "support_stop": true
                },
                "dev_type": "cover",
                "ha_type": "cover",
                "icon": "https://images.tuyaeu.com/smart/icon/ay1518345874298thrlS/157594986436cfb8dfee1.jpg",
                "id": "xxxxxxxxxxxxxxxxxxxx",
                "name": "Volet bureau"
            }
        ],
        "scenes": []
    }
}

When I have generated the JSON, some covers were opened, others were closed. But every cover has the state "3" because the motor was not running. When I start the motor by using the physical switch, the state is updated accordingly to my previous explanation, ie when the cover is opening (until the motor stops), the state is "1", and when the cover is closing, the state is "2". As soon as I hear the click which indicated that the cover switch has finished its work, the state is "3".

I really appreciate the time you are spending on this project, and cannot even imagine how hard it could be to write support for something you don't even own! Thank you for that!

milo526 commented 3 years ago

I just release a pre-release with some improvements for cover devices. You can now also overwrite your window covering to a window. This will enable some extra security features (I believe your phone needs to be unlocked in order to open a window), it will give you notifications on open/close and it gives you some shiny new icons.

How to install a pre-release version. Logically do this for the @milo526/homebridge-tuya-web or TuyaWebPlatform plugin. You should be able to install version v0.8.0-0. Please let me know how that works for you!

taaa22 commented 3 years ago

I just release a pre-release with some improvements for cover devices.

You can now also overwrite your window covering to a window.

This will enable some extra security features (I believe your phone needs to be unlocked in order to open a window), it will give you notifications on open/close and it gives you some shiny new icons.

How to install a pre-release version.

Logically do this for the @milo526/homebridge-tuya-web or TuyaWebPlatform plugin.

You should be able to install version v0.8.0-0.

Please let me know how that works for you!

Thank you for this update.

milo526 commented 3 years ago

@taaa22 please see my response in #145 with regards to the stop option. In short, the Home.app has no support for this functionality, third party apps might. I have confirmed it working using the Eve app.