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

loratap_garage_door incorrect state reporting #2099

Closed
hudcap opened this issue Jul 11, 2024 · 6 comments
Closed

loratap_garage_door incorrect state reporting #2099

hudcap opened this issue Jul 11, 2024 · 6 comments

Comments

@hudcap
Copy link

hudcap commented Jul 11, 2024

Thank you for this awesome integration!

I'm using loratap_garage_door and am getting consistent, but incorrect state reporting.
Commands work perfectly (I believe this is dp 1).
The opener has a contact sensor for the fully closed state (I believe this is dp 101).

  1. When I open/close the garage door outside of HA, the closed state is reported correctly, however the not closed state is always reported as "closing." It seems that the contact sensor open is interpreted as "closing." I can work around this with a template, but it seems to be a bug nonetheless. I tried deciphering cover.py, but couldn't fully follow what was going on with all the abstractions.
  2. When I close the garage door in HA, the state is immediately reported as closed, presumably based on the command. However, the more accurate behavior (at least in my mind), would be to either keep the state as "open" or "closing" until the contact sensor reports that it's closed. Otherwise if the garage door doesn't actually close for some reason, HA will still report it as closed (at least until it presumably updated at some point in the future).

Diagnostics:

"data": {
    "name": "Garage door",
    "type": "loratap_garage_door",
    "device_id": "**REDACTED**",
    "device_cid": "",
    "local_key": "**REDACTED**",
    "host": "**REDACTED**",
    "protocol_version": 3.3,
    "tinytuya_version": "1.14.0",
    "api_version_set": 3.3,
    "api_version_used": 3.3,
    "api_working": true,
    "status": {},
    "cached_state": {
      "updated_at": 1720660740.159877,
      "1": false,
      "7": 0,
      "101": false,
      "102": 20,
      "103": 0
    },
    "pending_state": {},
    "connected": true,
    "force_dps": [],
    "home_assistant": {
      "name": "Garage door",
      "name_by_user": null,
      "disabled": false,
      "disabled_by": null,
      "entities": [
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": null,
          "device_class": null,
          "original_device_class": "garage",
          "icon": null,
          "unit_of_measurement": null,
          "state": {
            "entity_id": "cover.garage_door",
            "state": "closed",
            "attributes": {
              "current_position": 0,
              "device_class": "garage",
              "friendly_name": "Garage door",
              "supported_features": 3
            },
            "last_changed": "2024-07-11T00:52:04.938509+00:00",
            "last_reported": "2024-07-11T00:52:36.429794+00:00",
            "last_updated": "2024-07-11T00:52:04.938509+00:00"
          }
        },
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": "config",
          "device_class": null,
          "original_device_class": null,
          "icon": null,
          "unit_of_measurement": "min",
          "state": {
            "entity_id": "number.garage_door_timer",
            "state": "0.0",
            "attributes": {
              "min": 0.0,
              "max": 1440.0,
              "step": 1.0,
              "mode": "auto",
              "unit_of_measurement": "min",
              "friendly_name": "Garage door Timer"
            },
            "last_changed": "2024-07-11T00:06:58.942309+00:00",
            "last_reported": "2024-07-11T00:06:58.942309+00:00",
            "last_updated": "2024-07-11T00:06:58.942309+00:00"
          }
        },
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": "config",
          "device_class": null,
          "original_device_class": null,
          "icon": null,
          "unit_of_measurement": "s",
          "state": {
            "entity_id": "number.garage_door_travel_time",
            "state": "20",
            "attributes": {
              "min": 10.0,
              "max": 120.0,
              "step": 1.0,
              "mode": "auto",
              "unit_of_measurement": "s",
              "icon": "mdi:timer",
              "friendly_name": "Garage door Travel time"
            },
            "last_changed": "2024-07-11T00:06:58.942618+00:00",
            "last_reported": "2024-07-11T00:06:58.942618+00:00",
            "last_updated": "2024-07-11T00:06:58.942618+00:00"
          }
        },
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": "config",
          "device_class": null,
          "original_device_class": null,
          "icon": null,
          "unit_of_measurement": "min",
          "state": {
            "entity_id": "number.garage_door_alarm_timer",
            "state": "0.0",
            "attributes": {
              "min": 0.0,
              "max": 1440.0,
              "step": 1.0,
              "mode": "auto",
              "unit_of_measurement": "min",
              "icon": "mdi:alarm",
              "friendly_name": "Garage door Alarm timer"
            },
            "last_changed": "2024-07-11T01:01:38.629364+00:00",
            "last_reported": "2024-07-11T01:01:38.629364+00:00",
            "last_updated": "2024-07-11T01:01:38.629364+00:00"
          }
        }
      ]
    }
  }
@hudcap hudcap added the bug Something isn't working label Jul 11, 2024
@make-all
Copy link
Owner

make-all commented Jul 11, 2024

The DPs reported by this device are very limited, so the integration needs to basically guess at the actual state. The guesses are as follows;

DP1 DP101 State
false false closed
false true closing
true false opening
true true open
  1. When you control the device from outside HA, the command (DP1) may not be updated by the device, leading to the wrong state in that table, and therefore a wrong state reported.
  2. The sensor DP101 is marked in the tuya info as detecting "open" state. It is therefore not surprising that it changes immediately when the door starts closing.

There is too much inconsistency between different Tuya cover devices for me to start making code changes to let your device work perfectly, as it will adversely affect many other devices. To fix 1, it may be possible to avoid looking at command (DP1) completely when determining state, but that will mean the closing and opening states will never show for this device, and it will show closed when opening until the device indicates that it is opening, and the behaviour in 2 of immediately showing closed will remain.

@illuzn
Copy link
Contributor

illuzn commented Jul 11, 2024

I address this issue in my discussion: #1419

DP1 DP101 State
false false closed
false true closing
true false opening
true true open

One issue that can result from that state table is if the device is closing (but this is prevented by one of those reflective sensors or if it closes on something and stops), the cover can get stuck in the closing state. In this state, neither the open nor close controls work and you need to manually open/ close it on the device.

Tuya itself attempts to address this issue by implementing a "time of flight" configuration. As usual, their documentation of this is completely shoddy (and this is probably why it isn't discussed more). However, it works as follows:

  1. Use a stopwatch to time how long your device takes to open/ close (usually it will take longer to open due to working against gravity).
  2. Set that as the "time of flight".
  3. The logic works as follows:
DP101 Time of Flight State
false Elapsed Time > Time of Flight closed
true (DP1 toggled) Elapsed Time < Time of Flight closing
false->true (DP1 toggled) Elapsed Time < Time of Flight opening
true Elapsed Time > Time of Flight open

Note that:

  • The state of DP1 becomes irrelevant (as it truly should). These devices operate effectively as a one button remote anyway (each push cycles between run/ stop and which way it runs is dependent on the existing state of DP1 and there is no reliable way to predict which way it will run realistically from the information exposed).
  • One benefit of this this logic is that the device will "fail safe" i.e. it can be safely assumed that if DP101 is false then the garage door is definitely closed and based on this logic the device will default to open after the time of flight has expired.
  • A stop function can also be implemented for "emergencies".

I've read the documentation and from what I understand implementing something like this would require a significant backend update to how tuya-local works.

@hudcap
Copy link
Author

hudcap commented Jul 11, 2024

Thank you both!
Sorry, when I searched, I didn't think to search in discussions.

make-all added a commit that referenced this issue Jul 21, 2024
Only take control dp into account when we have enough other info to
determine that the curtain is moving between states.

Issue #2099
make-all added a commit that referenced this issue Jul 21, 2024
@make-all make-all added awaiting confirmation Wating for confirmation the issue is solved unreleased Will be in next release labels Jul 21, 2024
@make-all
Copy link
Owner

On reflection, the use of the command dp to try to distinguish opening and closing is unreliable, and it was a mistake to give in to previous users demands to support opening and closing states on devices where it cannot be reliably determined. I have modified
the logic to limit the use of command to only cases where there is reliable current position info to determine that the cover is not fully opened or closed, and not stopped at the position that was set to go to (in that case it can be reliably determined that the state is one of either opening or closing, so it does not matter so much if we guess wrong based on the last command which does not take into account interaction outside of HA).

@make-all
Copy link
Owner

The outcome should be that when your garage door is fully closed, it will show closed, other times it will show opened, since that is the only information your door is giving.

make-all added a commit that referenced this issue Jul 21, 2024
Garage door, QS01 curtain, simple blind cannot reliably determine
opening and closing states, so update the tests for this.

Issue #2099
@hudcap
Copy link
Author

hudcap commented Jul 22, 2024

Just updated it and it's behaving exactly as expected.
Thank you!!

@hudcap hudcap closed this as completed Jul 22, 2024
@make-all make-all reopened this Jul 22, 2024
@make-all make-all removed awaiting confirmation Wating for confirmation the issue is solved bug Something isn't working unreleased Will be in next release labels Jul 22, 2024
timlaing pushed a commit to timlaing/tuya-local that referenced this issue Aug 8, 2024
Only take control dp into account when we have enough other info to
determine that the curtain is moving between states.

Issue make-all#2099
timlaing pushed a commit to timlaing/tuya-local that referenced this issue Aug 8, 2024
timlaing pushed a commit to timlaing/tuya-local that referenced this issue Aug 8, 2024
Garage door, QS01 curtain, simple blind cannot reliably determine
opening and closing states, so update the tests for this.

Issue make-all#2099
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

3 participants