rospogrigio / localtuya

local handling for Tuya devices
GNU General Public License v3.0
2.91k stars 557 forks source link

Cover Fake Position not working. Value stuck at 50 #175

Closed TheDukeSr closed 3 years ago

TheDukeSr commented 3 years ago

Hi,

Configured a Cover with position "Fake" and time 30 secs. Cover is responding with open/close/stop correctly.

But slider and position value is allways 50 ?! When releasing slider below 50 does nothing, releasing slider above 50 does move the cover, but stops not at correct position.

Example when releasing slider at 20 (Cover does NOT move at all, but I notice a STOP command to switch after x secs): And after this move/log, the position is set at 50 automaticly !

2020-11-20 21:37:16 DEBUG (MainThread) [custom_components.localtuya.cover] Setting cover position: 20 2020-11-20 21:37:16 DEBUG (MainThread) [custom_components.localtuya.cover] Closing to 20.000000: delay 18.000000 2020-11-20 21:37:16 DEBUG (MainThread) [custom_components.localtuya.cover] Launching command off to cover 2020-11-20 21:37:16 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf877d152b17a7b24etdos] Sending command set (device type: type_0d) 2020-11-20 21:37:16 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf877d152b17a7b24etdos] Send payload: b'{"devId":"bf877d152b17a7b24etdos","uid":"bf877d152b17a7b24etdos","t":"1605904636","dps":{"1":"off"}}' 2020-11-20 21:37:16 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf877d152b17a7b24etdos] Waiting for sequence number 30 2020-11-20 21:37:16 DEBUG (MainThread) [custom_components.localtuya.pytuya] Dispatching message TuyaMessage(seqno=0, cmd=8, retcode=0, payload=b'3.3\x00\x00\x00\x00\x00\x00\x07y\x00\x00\x00\x01w>\x00\x05\x923\x85(q\xbbu;\x0eQn\xb8?\xea \xa3y\xc3\x9b@\xdc-\xdf\x1d\x1c\n0AH\x11\xa7\xb3\xd3\xed\xd0L\x18\xd7\x8a\x0c\xe3\xcf\xf6\xc3', crc=784762959) 2020-11-20 21:37:16 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf877d152b17a7b24etdos] Got status update 2020-11-20 21:37:16 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf877d152b17a7b24etdos] Decrypted payload: {"dps":{"1":"off"},"t":1605904635} 2020-11-20 21:37:16 DEBUG (MainThread) [custom_components.localtuya.pytuya] Dispatching message TuyaMessage(seqno=30, cmd=7, retcode=0, payload=b'', crc=913496827) 2020-11-20 21:37:16 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf877d152b17a7b24etdos] Dispatching sequence number 30 2020-11-20 21:37:16 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf877d152b17a7b24etdos] Decrypted payload: {}

Cover is fully closed, and slider at 50... Releasing slider at 60 (Cover does open 6 seconds and then a STOP command. But cover never moved to 60%, because timing is set at 30 secs... So 6 secs opening is way to short. And again... after this move/log, the position sets itself at 50 again!

2020-11-20 21:41:44 DEBUG (MainThread) [custom_components.localtuya.cover] Setting cover position: 60 2020-11-20 21:41:44 DEBUG (MainThread) [custom_components.localtuya.cover] Opening to 60.000000: delay 6.000000 2020-11-20 21:41:44 DEBUG (MainThread) [custom_components.localtuya.cover] Launching command on to cover 2020-11-20 21:41:44 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf877d152b17a7b24etdos] Sending command set (device type: type_0d) 2020-11-20 21:41:44 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf877d152b17a7b24etdos] Send payload: b'{"devId":"bf877d152b17a7b24etdos","uid":"bf877d152b17a7b24etdos","t":"1605904904","dps":{"1":"on"}}' 2020-11-20 21:41:44 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf877d152b17a7b24etdos] Waiting for sequence number 50 2020-11-20 21:41:44 DEBUG (MainThread) [custom_components.localtuya.pytuya] Dispatching message TuyaMessage(seqno=0, cmd=8, retcode=0, payload=b"3.3\x00\x00\x00\x00\x00\x00\x07\x80\x00\x00\x00\x01m\x8aO\x1d\x80\xba\x7f\xa9\xbb\x1bg\xa6\x18\xd7*M\xcc\xe6\x80\x8d4\xa8w\x90\xf5\x80\x19'\xcb\x1a|\xd5i\xa8wL\xca2\x14\xe3\xb7f\xdb\x07\x92\x93y\x1e", crc=514772235) 2020-11-20 21:41:44 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf877d152b17a7b24etdos] Got status update 2020-11-20 21:41:44 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf877d152b17a7b24etdos] Decrypted payload: {"dps":{"1":"on"},"t":1605904903} 2020-11-20 21:41:44 DEBUG (MainThread) [custom_components.localtuya.pytuya] Dispatching message TuyaMessage(seqno=50, cmd=7, retcode=0, payload=b'', crc=532031733) 2020-11-20 21:41:44 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf877d152b17a7b24etdos] Dispatching sequence number 50 2020-11-20 21:41:44 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf877d152b17a7b24etdos] Decrypted payload: {}

Settings in Hass: On-Off-Stop Fake 30

Hope this can be fixed.

rospogrigio commented 3 years ago

This is the old behavior. Update to 3.1.0 and it will work as expected, please confirm...

postlund commented 3 years ago

@rospogrigio We should create issue templates, e.g. add version when creating a bug issue.

TheDukeSr commented 3 years ago

It's better now, but still 2 problems.

1. Default value after restart: After restarting HA the current_position is 50 (should be 0).

2. A timing problem: My cover opening time is 30 secs, and it also needs 30 secs to close. In the config I have to put 15 to get it working correctly. Somehow the opening/closing time in config needs to be halved?! and therefore not working as precise as it should be.

ps. I used "Config Flow" to configure the device.

rospogrigio commented 3 years ago

I get what you are saying but... this is not how it was thought. In detail:

  1. After restarting HA the current_position is 50 (should be 0).

Actually: no. HA cannot know the status of the device when you restart HA. You might need to reboot the device or restart after an update or have a power cut and HA cannot know in advance whether your cover is closed, open, or half way. And this comes to

  1. In the config I have to put 15 to get it working correctly.

This is why the timing has been doubled. HA doesn't know the position of your device at the startup, you can know it by just watching at it. But starting from 50 and doubling the movements allows you to have a full opening or full closing from whichever situation you are into. Then, you know that if you want to have a partial movement you have to behalf it when you operate the slider; so, if you have just restarted and the device is closed, the initial position is at 50 and setting it to 75 will open it half-way. Hope this is clearer now, it is arguable but it is how it's meant to be without knowing the initial position. If you have other ideas or proposals in order to improve the behavior, feel free to express them, but you cannot base it on the assumption that the initial position is 0 because it's a wrong assumption.

TheDukeSr commented 3 years ago

Ok I get it.

I understand why and how you're doing it this way, but it's confusing because after a reboot the cover is not moving at all when moving the slider below 50. And I have to move it manually to 0 after every reboot (because I want to use the slider on 0% as fully closed).

I do have an idea that might improve the position behaviour. Please consider my suggestion below.

Slider at 0 the cover is totaly closed and at 100 is fully open. In the config the user inputs 30 secs if it takes 30 secs to open. When config value is "Fake", then store the "current_position" somewhere (database or file?) after every movement and restore that current_position value after a HA restart.

This should take care of all situations except the one where HA reboots at exactly the same time while moving (but that's allmost never happening).

The above suggestion uses the slider as people expect (0 is fully closed, 100 fully open). And this also uses the correct position after a HA reboot for 99,999% of the time. It also removes the default 50% slider after a reboot, what is a bit confusing (at least it was to me ;-)).

I'm very happy with the local tuya integration, and use it a lot for many switches/dimmers. Thnx for your time.

rospogrigio commented 3 years ago

I also had thought of something like this. Actually where it doesn't work is in the case that: 1) you switch off your HA 2) you manually move the cover to another position using physical buttons, or the Tuya app 3) you switch on again your HA In this case you have the HA status unaligned with the actual cover status. I do admit that this is quite a corner case, and it can be easily fixed with a full opening/closure. So, it might be worth to store the position somewhere and get rid of the "double range" thing, which I agree might be confusing.

So let's ask @postlund : where is the most convenient place to store this information, in your opinion? Using a file? The database? Or is there an internal structure of HA that can be used for the purpose?

Thank you for your suggestion, let's see what I can do and when (I am being quarantined again and handling work and daughter is a bit of a mess...). 😉

rospogrigio commented 3 years ago

@TheDukeSr I implemented this in PR #213 , please give it a go and tell me how it works, thank you!

rospogrigio commented 3 years ago

Should be fixed by #213 . Closing.