ollo69 / ha_tuya_custom

Tuya Custom Component for testing
Apache License 2.0
39 stars 18 forks source link

Cover Switchs Always Openning #7

Open JorgeMaTeixeira-zz opened 4 years ago

JorgeMaTeixeira-zz commented 4 years ago

I´m using custom component installed using hacs, and is working much better now, no delay when using HA.. The only issue i found is with cover switches, HA is always reporting that covers are oppening, when they aren´t oppening.

image

Maybe this happen because of the undefined state of the cover switch. When the covers are stopped, the switch should stay in undefined state, that way i can open or close. Right now they keep forcing the open state, that way if i want to open, i need to use the stop command first and only then i can use the open command. Other thing is that closing state is not showing up, i can close, but the state is not showed in HA.

nao-pon commented 4 years ago

@JorgeMaTeixeira I don't have a cover devices, so I can't verify it, but I tried fixing it.

You can either apply the following changes or replace it with https://github.com/ollo69/ha_tuya_custom and deploy and validate my repository https://github.com/nao-pon/ha_tuya_custom with HACS ..

Please let us know the result.

JorgeMaTeixeira-zz commented 4 years ago

I will try.. I'm a newbie in this, but i will read and try to do it.

JorgeMaTeixeira-zz commented 4 years ago

Should I copy the files to the custom component or there will be a update at repository?

ollo69 commented 4 years ago

Later today I will take some time to merge last PR and so you just will need to update version from HACS. Please be patient, I'm a little bit busy in my job on this days...

nao-pon commented 4 years ago

@ollo69 It's fine when you have time. I will proceed with the verification :-)

@JorgeMaTeixeira Overwrite the modified file under custom_components/tuya_custom/tuyaha/devices and restart HA.

JorgeMaTeixeira-zz commented 4 years ago

I´ve replaced base.py and cover.py (ha reboot) and the problem with cover is still present.

ollo69 commented 4 years ago

Please try update to last release (v0.0.3), should be fixed

JorgeMaTeixeira-zz commented 4 years ago

Updated.. I'm testing and I will report later. But it seams fine.

JorgeMaTeixeira-zz commented 4 years ago

It's not working fine, it takes a lot of time to update de status. There's anything I can do or provide to help?

JorgeMaTeixeira-zz commented 4 years ago

The "always open" problem is solved, but theres is a huge delay in HA status for cover switches.

ollo69 commented 4 years ago

Pls explain better what delay is related and expeted behaviour. I don't have a cover so is not clear to me how status transition should be.

JorgeMaTeixeira-zz commented 4 years ago

It seams that is with the same delay as switches before custom tuya.. I open and takes a lot of time to shouw oppening, and the same for closing.

ollo69 commented 4 years ago

Can you enumerate the possible expected state for cover device and when they should be? Eg:

Open -> The cover is open Opening -> The cover is opening Closing -> .... ... etc.

Thx

JorgeMaTeixeira-zz commented 4 years ago

There's no state Open or Close, only oppening (during the time the relay opening is on) and closing (during the time the relay close is on).

The switch as no way to know if the cover is open or close, only know if it's opening or closing, when no relay is on, should stay unknow.

ollo69 commented 4 years ago

This is really different from what I see on the code (also for original integration). In the past opening and closing was showed to you? What is the lovelace control that you are using to control your cover?

JorgeMaTeixeira-zz commented 4 years ago

Oppening and closing yes, was showing but not open or close. Maybe I'm not explaining well..

The switch as three buttons, open, close and stop You see oppening when oppening button is pressed and the oppening relay is energised, you see closing when closing button is pressed and the close relay is energised, and when you press stop the state is unknown (not oppening and not closing).

JorgeMaTeixeira-zz commented 4 years ago

And the states report are fine, just with huge delay. Ex. I press open and takes several seconds or more than 1 minute to show oppening.. And the same for closing operation.

ollo69 commented 4 years ago

Ok, it is clear, but let me explain my concern: looking at the code, seems that the HA part is only using the attribute "is_open" that should reflect the final state "open" or closed" and not the state "opening" and closing", so probably the mapping in HA component is not correct. I think that this should be fixed populating the right attribute, but to be sure about this I would like to see the code of your lovelace card used to control your cover. Can you post it here?

JorgeMaTeixeira-zz commented 4 years ago

Maybe i´m wrong i don´t know, i´m really a newby with HA. My explanation is from what i see in the UI.

image This is when the cover is stopped, not doing nothing. (none of the relays are on)

image This is when i press open button, and HA is taking a delay to reflect the state. (the open relay on the switch is on).

image This is when HA reflects the oppen command i gave.

Cover Lovelace card (nothing really fancy, just the entity id. "entities:

And to be clear, all cover commands are working perfect, the only thing is the delay between the command and HA reflects the new state. The original problem, the one that let me create this issue is gone after the custom tuya update in hacs.

Open button pressed - Oppening Stop button pressed - no state (unknow) Close button pressed - Closing

ollo69 commented 4 years ago

What about SmartLive App? You have the same information? What is the physical device model that you use to control your cover?

ollo69 commented 4 years ago

Can you check with last release (v0.0.4). I changed a little bit the logic in HA integration.

acs-lux commented 4 years ago

For me I'm about to change from HA Tuya to the custom tuya but this thread concerns me. I had to use custom covers with template icons so that an open blind shows open and a closed blind shows closed icon. The unknown state breaks it always showing closed so I got rid of it using is_open state as per HA docs. If the custom tuya gives always up down controls but can show open/closed icons it would be perfect. Icon is selected based on previous state before unknown state due to is_open.

ollo69 commented 4 years ago

I understood that Tuya devices cannot provide the info that cover is closed, but you are stated different. Can you clarify the possible state that you expect to be managed? Cover entity in HA can be:

I need to remap each state base on information provided by Tuya, so please provide me this information to fix the component. Eventualy, if you are able, enable the component debug log adding this rows in configuration.yaml:

logger:
  default: info
  logs:
    custom_components.tuya_custom: debug

Than operate for some times the cover and attach here log file so that I can see provided states.

Thx

JorgeMaTeixeira-zz commented 4 years ago

@stjones-dev but how your cover switch know if the cover is open or close? Just by the last command? Becausse there's no any limit switch or other way to know.

@ollo69 my cover switchs in smart life tuya only say if is oppening or closing or nothing (when is stopped). The cover switch normally only have two relays, on for open and one for closing, the stop button only turn off both relays.

I'm testing latest version, it seams that have delay.. I send a close command and HA take a wile to show its closing. But I can live with this :p

acs-lux commented 4 years ago

Its because of is_open state ignoring unknown state so it's based on previous state.

Although icons revert to closed during unknown state the active colour is retained so I know more or less if covers are open or not.

Best I could do with no feedback. Using timers seemed likely to get out of sink with SmartLife but haven't tried it TBH.

JorgeMaTeixeira-zz commented 4 years ago

None - this state should be when none of other operations is on.. Its the same in smart life.

Opening - this should be when open command is on (open relay is on)

Closing - when closing command is on (closing the relay is on)

Close - this only can be used by guessing, because the cover wall switch i have (and all I know about) don't have way to know.

Open - same above.

There are some switchs with more electronic that use current and time to calculate the position, they have some way of learning the time it takes to full open or full close by measuring the current passing on the relay and they can calculate, but mine don't do that, they just open or close, nothing more.

JorgeMaTeixeira-zz commented 4 years ago

@ollo69 the log is in the home-assistant.log file at config folder?

The only problem I have now is the delay, the rest is fine.

ollo69 commented 4 years ago

Just released a new version where I try yo "deduct" is_closed state, please try it.

@ollo69 the log is in the home-assistant.log file at config folder?

Yes, it is. You have to reboot HA after changing configuration.yams

The only problem I have now is the delay, the rest is fine.

But you still have delay problem with last release? is_opening and is_closing should reflect immediatly.

JorgeMaTeixeira-zz commented 4 years ago

@ollo69 with the latest is always opening..

The last one was faster, but with some delay I think..

I need to get back home to send you the file, I'm doing everything with my phone, but i can't download the log file.

See this screen recorder. https://photos.app.goo.gl/eYnKCjMYLJtJ88yc9

That video is with 0.0.5,because 0.0.6 is always opening regardless the command.

ollo69 commented 4 years ago

Ok, I wait for your log because probably I'm not properly mapping the states...

acs-lux commented 4 years ago

I can report that after changing to custom tuya switch states are reported much quicker for almost all switches. One of my covers has a name starting with 2, all others start with 1. The 2 has a different state to those with 1. When I get home I can provide better info as I only have my phone.

JorgeMaTeixeira-zz commented 4 years ago

Ok, I wait for your log because probably I'm not properly mapping the states...

home-assistant.log

ollo69 commented 4 years ago

If I well understand status change in log:

1 = opening 2 = closing 3 = stopped

Please try again with version 0.0.7 and let me know

JorgeMaTeixeira-zz commented 4 years ago

With 007 is always opening.

When I press close or stop is super fast to update the new state, but after the stop command is showing always opening.

ollo69 commented 4 years ago

Yes, try again (v0.0.8) :)

JorgeMaTeixeira-zz commented 4 years ago

Now it seams perfect.. Thank you.

ollo69 commented 4 years ago

That's fine. Now Open or Closed status should be keeped, but keep in mind that in case you control your cover from phone app (eg start moving and than stopping in the middle) the component can detect wrong opened or closed state. As alternative solution I can remove this part of code used to determinate the state and leave only states opening and closing, that basically is as was original component. Please let me know prererred solution.

acs-lux commented 4 years ago

For me now all is perfect. Just one question. Why does HA give a window icon to covers? I have to create custom covers just to use the window-shutter icon.

Not a big deal really I suppose. I also see now the opening and closing states so can modify the custom covers to include those.

Great work and much appreciated.

ollo69 commented 4 years ago

For me now all is perfect. Just one question. Why does HA give a window icon to covers? I have to create custom covers just to use the window-shutter icon.

Default icon used is related to HA core and not to the componenet.

JorgeMaTeixeira-zz commented 4 years ago

I don´t see open or close state, can you show me the log book for cover ?

image

How can i see open and close ?? If a send a open command i shoud see opening or opened ? Now i´m confused.

acs-lux commented 4 years ago

That's strange, I see open, opening, closing and closed states in my custom cover templates but in the original covers I see only opening, closing and unknown. So i recommend making custom covers like this:

  - platform: template
    covers:
      office_blind2:
        device_class: shutter
        optimistic: true
        friendly_name: "Office Blind"
        open_cover:
          service: cover.open_cover
          data:
            entity_id: cover.20770531bcddc2608c33
        close_cover:
          service: cover.close_cover
          data:
            entity_id: cover.20770531bcddc2608c33
        stop_cover:
          service: cover.stop_cover
          data:
            entity_id: cover.20770531bcddc2608c33
        icon_template: >-
            {% if is_state('cover.20770531bcddc2608c33', 'open') %}
              mdi:window-shutter-open
            {% elif is_state('cover.20770531bcddc2608c33', 'opening') %}
              mdi:arrow-up-bold-box
            {% elif is_state('cover.20770531bcddc2608c33', 'closing') %}
              mdi:arrow-down-bold-box
            {% else %}
              mdi:window-shutter
            {% endif %}
acs-lux commented 4 years ago

Strangely my logbook only shows open and closed even though I get opening and closing states which I use in lovelace.

July 5, 2020 2:55:37 PM Office Blind changed to open 2:12:50 PM Office Blind changed to closed 2:12:43 PM Office Blind changed to open 2:12:27 PM Office Blind changed to closed 2:12:21 PM Office Blind changed to open 2:12:19 PM Office Blind changed to closed 2:12:15 PM Office Blind changed to open 2:12:07 PM Office Blind changed to closed

ollo69 commented 4 years ago

Logbook not always show all event. Look at History

acs-lux commented 4 years ago

Same thing, the original only has opening, closing and unknown and the custom template has only open and closed. But for me the visual lovelace of the custom template has also opening and closing states so I'm very happy.

JorgeMaTeixeira-zz commented 4 years ago

@stjones-dev the custom template should be in the configuration file? I shoud make a custom template for each cover?

acs-lux commented 4 years ago

Yes in the config file. Start a covers: section as in the above create all the custom covers and then after restart you can replace in lovelace. Each new cover should have the entity_id of the original cover its replacing.

acs-lux commented 4 years ago

I still have a delay of upto 10 seconds or so between clicking on the HA gui and the switch switching. However, status update is pretty much instant when it switches. Covers are instant weirdly. Just light switches that have the delay.