Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Device Request: Avatto Curtain switch #292

Closed
engusz opened this issue Nov 28, 2022 · 18 comments
Closed

New Device Request: Avatto Curtain switch #292

engusz opened this issue Nov 28, 2022 · 18 comments

Comments

@engusz
Copy link

engusz commented Nov 28, 2022

Hi,

The integration didn't recognize the device, the log shows:

Device matches None with quality of 0%. DPS: {'1': 'stop', '101': True, 'updated_at': 1669631896.6501718}

Link: https://www.aliexpress.com/item/4000206502719.html

Response

{
  "result": {
    "category": "clkg",
    "functions": [
      {
        "code": "control",
        "lang_config": {
          "close": "Close",
          "open": "Open",
          "stop": "Paused"
        },
        "name": "Curtain",
        "type": "Enum",
        "values": "{\"range\":[\"open\",\"stop\",\"close\"]}"
      },
      {
        "code": "switch_backlight",
        "lang_config": {
          "false": "",
          "true": ""
        },
        "name": "背光开关",
        "type": "Boolean",
        "values": "{}"
      }
    ],
    "status": [
      {
        "code": "control",
        "lang_config": {
          "close": "Close",
          "open": "Open",
          "stop": "Paused"
        },
        "name": "Curtain",
        "type": "Enum",
        "values": "{\"range\":[\"open\",\"stop\",\"close\"]}"
      },
      {
        "code": "switch_backlight",
        "lang_config": {
          "false": "",
          "true": ""
        },
        "name": "背光开关",
        "type": "Boolean",
        "values": "{}"
      }
    ]
  },
  "success": true,
  "t": 1669633118166,
  "tid": "9c8c8f646f0b11ed8ac2164a0a4aa718"
}

Thanks,

@make-all make-all added the new device Unsupported device label Nov 29, 2022
@engusz
Copy link
Author

engusz commented Dec 1, 2022

These additional data:

Device matches None with quality of 0%. DPS: {'1': 'stop', '101': True, 'updated_at': 1669922066.2737293}

{
  "result": {
    "category": "clkg",
    "functions": [
      {
        "code": "control",
        "dp_id": 1,
        "type": "Enum",
        "values": "{\"range\":[\"open\",\"stop\",\"close\"]}"
      },
      {
        "code": "switch_backlight",
        "dp_id": 101,
        "type": "Boolean",
        "values": "{}"
      }
    ],
    "status": [
      {
        "code": "control",
        "dp_id": 1,
        "type": "Enum",
        "values": "{\"range\":[\"open\",\"stop\",\"close\"]}"
      },
      {
        "code": "switch_backlight",
        "dp_id": 101,
        "type": "Boolean",
        "values": "{}"
      }
    ]
  },
  "success": true,
  "t": 1669922128510,
  "tid": "8433b83a71ac11edb328265ef7a90a71"

make-all added a commit that referenced this issue Dec 10, 2022
@make-all make-all added awaiting confirmation Wating for confirmation the issue is solved unreleased Will be in next release and removed new device Unsupported device unreleased Will be in next release labels Dec 10, 2022
@engusz
Copy link
Author

engusz commented Dec 11, 2022

Hi @make-all,

image

The opening and closing buttons do not control the wall switch. Only the STOP button works properly.
When the backlight is turned on and off, the STOP button on the wall switch lights up. (It didn't do that before.)

@make-all make-all added partially working Needs more work to complete and removed awaiting confirmation Wating for confirmation the issue is solved labels Dec 11, 2022
@make-all
Copy link
Owner

This device doesn't seem to report enough info to reliably track its state. I see from the screenshot that the open button is disabled. But if the curtain is not fully open, then that is incorrect. Also, the info on the Tuya portal may not be correct - if you can capture the device diagnostics while the curtain is in different states, it might help figure out how exactly it is behaving and what it expects

I'm not sure about the meaning of your statement about the backlight. Do you mean the backlight is now working, while it didn't previously?

@engusz
Copy link
Author

engusz commented Dec 11, 2022

How to capture the device diagnostic?

Normal operation: if I turn off the backlight, only the LEDs turn off. Nothing else happens.
With your solution: if I turn off the backlight, the LEDs turn off and (!) the stop button flashes once.

@make-all
Copy link
Owner

The stop button flashing is probably indicating an error, or a sign that the device is crashing due to its poor error handling.
Does it mention anything in the manual about flashing to indicate error conditions?

Device diagnostics are available under Settings / Devices and Services / Tuya local - your device / 1 device / inside the Device Info panel.

@engusz
Copy link
Author

engusz commented Dec 11, 2022

It's here too!

{
  "home_assistant": {
    "installation_type": "Home Assistant OS",
    "version": "2022.12.1",
    "dev": false,
    "hassio": true,
    "virtualenv": false,
    "python_version": "3.10.7",
    "docker": true,
    "arch": "x86_64",
    "timezone": "Europe/Budapest",
    "os_name": "Linux",
    "os_version": "5.15.74",
    "supervisor": "2022.11.2",
    "host_os": "Home Assistant OS 9.3",
    "docker_version": "20.10.18",
    "chassis": "embedded",
    "run_as_root": true
  },
  "custom_components": {
    "thermal_comfort": {
      "version": "1.5.3",
      "requirements": []
    },
    "xiaomi_miot": {
      "version": "0.7.2",
      "requirements": [
        "construct==2.10.56",
        "python-miio>=0.5.6",
        "micloud>=0.3"
      ]
    },
    "tuya_local": {
      "version": "0.21.0",
      "requirements": [
        "pycryptodome~=3.16.0",
        "tinytuya==1.9.1"
      ]
    },
    "sonoff": {
      "version": "3.3.1",
      "requirements": [
        "pycryptodome>=3.6.6"
      ]
    },
    "saj_esolar": {
      "version": "1.2.9",
      "requirements": []
    },
    "watchman": {
      "version": "0.5.1",
      "requirements": [
        "prettytable==3.0.0"
      ]
    },
    "hacs": {
      "version": "1.28.4",
      "requirements": [
        "aiogithubapi>=22.2.4"
      ]
    }
  },
  "integration_manifest": {
    "domain": "tuya_local",
    "iot_class": "local_polling",
    "integration_type": "device",
    "name": "Tuya Local",
    "version": "0.21.0",
    "documentation": "https://github.com/make-all/tuya-local",
    "issue_tracker": "https://github.com/make-all/tuya-local/issues",
    "dependencies": [],
    "codeowners": [
      "@make-all"
    ],
    "requirements": [
      "pycryptodome~=3.16.0",
      "tinytuya==1.9.1"
    ],
    "config_flow": true,
    "is_built_in": false
  },
  "data": {
    "name": "Avatto curtain switch",
    "type": "avatto_curtain_switch",
    "device_id": "**REDACTED**",
    "local_key": "**REDACTED**",
    "host": "**REDACTED**",
    "api_version": 3.3,
    "status": {},
    "cached_state": {
      "updated_at": 1670758551.0678492,
      "1": "stop",
      "101": true
    },
    "pending_state": {
      "1": {
        "value": "stop",
        "updated_at": 1670758547.87472
      },
      "101": {
        "value": true,
        "updated_at": 1670758547.87472
      }
    },
    "home_assistant": {
      "name": "Avatto curtain switch",
      "name_by_user": null,
      "disabled": false,
      "disabled_by": null,
      "entities": [
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": "config",
          "device_class": null,
          "original_device_class": null,
          "icon": null,
          "unit_of_measurement": null,
          "state": {
            "entity_id": "light.avatto_curtain_switch_backlight",
            "state": "on",
            "attributes": {
              "supported_color_modes": [
                "onoff"
              ],
              "color_mode": "onoff",
              "friendly_name": "Avatto curtain switch Backlight",
              "supported_features": 0
            },
            "last_changed": "2022-12-11T11:35:47.681233+00:00",
            "last_updated": "2022-12-11T11:35:47.681233+00:00"
          }
        },
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": null,
          "device_class": null,
          "original_device_class": "curtain",
          "icon": null,
          "unit_of_measurement": null,
          "state": {
            "entity_id": "cover.avatto_curtain_switch",
            "state": "open",
            "attributes": {
              "device_class": "curtain",
              "friendly_name": "Avatto curtain switch",
              "supported_features": 11
            },
            "last_changed": "2022-12-11T11:35:36.034465+00:00",
            "last_updated": "2022-12-11T11:35:36.034465+00:00"
          }
        }
      ]
    }
  }
}

make-all added a commit that referenced this issue Dec 11, 2022
The same as previous commit for is_closed - as these three are used in
combination to determine whether the state is open, we should only return
any of them when the state can be determined.

Issue #292
@make-all
Copy link
Owner

I think I understand what is going on. The HA cover API includes is_closed, is_opening and is_closing. If all three of these return False, then it assumes it is open. But in case of this device, the state cannot be determined, so we need to return None instead of False from these three functions to let Home Assistant know that it can't use that process of elimination to work out the state.

@make-all make-all added bug Something isn't working awaiting confirmation Wating for confirmation the issue is solved unreleased Will be in next release and removed partially working Needs more work to complete labels Dec 11, 2022
@engusz
Copy link
Author

engusz commented Dec 11, 2022

The switch doesn't know what position the shutter is in or what the last action was. The up and down button is active for 30-45 seconds from the moment you press it. The shutter motor knows the end positions, so it can't overrun.

@make-all
Copy link
Owner

I made some changes to the cover implementation so that Home Assistant should not disable the open button now. It is not in the release, but you can try it out by using "Redownload" in HACS and selecting "main" as the version to install.

@engusz
Copy link
Author

engusz commented Dec 11, 2022

I downloaded it again, added the switch again, but it still doesn't work. How else can I help?

@make-all make-all removed awaiting confirmation Wating for confirmation the issue is solved unreleased Will be in next release labels Dec 12, 2022
@make-all
Copy link
Owner

Reviewing the comments in devices/README.md about cover devices, I think it is not possible to support a curtain switch without any feedback as a cover device in Home Assistant. Instead, I think it will need to be changed to a select entity with the three command values. That is probably not the best representation in the UI though, so I suggest putting buttons with an action to call the select.select_option service with appropriate parameters.

make-all added a commit that referenced this issue Dec 12, 2022
cover entity requires some feedback about curtain position.  Without it, Home
Assistant considers the whole entity to be unavailable.  Instead, implement
as a select entity.

Issue #292
@engusz
Copy link
Author

engusz commented Dec 12, 2022

Another Local Tuya app managed this device properly. Its type was a shutter instead of a curtain.

@make-all make-all added unreleased Will be in next release and removed bug Something isn't working labels Dec 18, 2022
@make-all make-all added awaiting confirmation Wating for confirmation the issue is solved and removed unreleased Will be in next release labels Dec 22, 2022
@engusz
Copy link
Author

engusz commented Dec 23, 2022

Hi @make-all,

It doesn't work with the new method. After a few tries, the switch became inaccessible. (The backlight switch doesn't work either.)

image

How can I help your work?

@make-all
Copy link
Owner

I see from the log messages that you are bombarding the device with commands every 3 seconds. Tuya devices are very low powered and cannot handle much network load at all. It looks like the device is getting overloaded and shutting down the network for a while (either deliberately to cope or some internal crash/watchdog).

@make-all make-all removed the awaiting confirmation Wating for confirmation the issue is solved label Dec 24, 2022
@make-all
Copy link
Owner

Closing, as the device appears to be working as well as Tuya devices ever do.

@make-all make-all reopened this Dec 26, 2022
@make-all
Copy link
Owner

Reopening as I think this device may be a good test candidate for the button entity type requested in #244. This would provide a better UI than the current select entity.

make-all added a commit that referenced this issue Dec 26, 2022
- Add a button entity #244, #318
- Use it to improve Avatto Curtain Switch #292
@make-all make-all added awaiting confirmation Wating for confirmation the issue is solved unreleased Will be in next release device improvement Improvement to an existing device config labels Dec 26, 2022
@engusz
Copy link
Author

engusz commented Dec 26, 2022

OK thank you.

I didn't describe the error exactly in the previous post. The shutter movement did not work, no matter how many times I clicked the buttons. Then they became unavailable.

@make-all
Copy link
Owner

make-all commented Dec 26, 2022

I suspect there may be an issue with using select in that it will not send any command if you select the same option as previously selected, maybe even if done through a service call rather than the UI. I'm also not sure whether it reads the current option from the device, or maybe it is intended as a purely write only UI control. Using separate button entities for each command should avoid this, as the buttons are stateless, so should send the corresponding command each time they are pressed.

Beware though that Tuya devices are low powered and easily overrun if you send multiple commands in quick succession. I am not sure that the protections against this will work across multiple entities, but they are anyway not 100% effective, as there is a trade-off between protecting against the worst case and having a reasonably responsive average case.

@make-all make-all removed unreleased Will be in next release device improvement Improvement to an existing device config labels Jan 8, 2023
@make-all make-all removed the awaiting confirmation Wating for confirmation the issue is solved label Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants