home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.09k stars 29.75k forks source link

Motionblinds bluetooth "end positions" missing #119886

Closed fevo21 closed 2 months ago

fevo21 commented 2 months ago

The problem

Background Recently I started using the Motionblinds Bluetooth integration with roller blinds and CMD-03 motor. The initial setup of the CMD-03 motor was done with the Motionblinds IOS app, this includes the configuration of start and end position. After the initial setup the blinds were discovered by home assistant and I added them by using the "Motionblinds Bluetooth" integration.

ISSUE Since the installation of the "Motionblinds Bluetooth" integration I have been experiencing the following error message from time to time when I try to control the blinds with service calls (cover close / cover stop / cover open / cover set position):

"Failed to call service cover/close_cover. Motionblind EAED's end positions need to be set before usage of this command."

Most of the times the controls work as expected but sometimes the above error message pops up. Connecting the blinds just works fine in above case, but controlling is impossible due to the lack of these "end positions". Please note these "end positions" are configured just fine from the start and still are in the IOS app. Typically the issue can be resolved by briefly controlling the blinds with the IOS app.

Debug logging enabled and output attached below.

What version of Home Assistant Core has the issue?

core 2024.6.2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

Motionblinds Bluetooth

Link to integration documentation on our website

https://www.home-assistant.io/integrations/motionblinds_ble/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: homeassistant.components.websocket_api.http.connection
Source: components/websocket_api/commands.py:241
integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 12:31:04 (8 occurrences)
Last logged: 13:19:02

[139902150126624] Unexpected exception
[139901300223296] Unexpected exception
[139901300221280] Unexpected exception
[139901298216384] Unexpected exception
[139901160218992] Unexpected exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 241, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2741, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2784, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 977, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1049, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/motionblinds_ble/cover.py", line 156, in async_close_cover
    await self.device.close()
  File "/usr/local/lib/python3.12/site-packages/motionblindsble/device.py", line 79, in wrapper
    return await func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/motionblindsble/device.py", line 138, in wrapper
    raise NoEndPositionsException(
motionblindsble.device.NoEndPositionsException: Motionblind EAED's end positions need to be set before usage of this command.

Additional information

Motionblinds CMD-03 firmware version: 1.0.6 24020601

home-assistant[bot] commented 2 months ago

Hey there @lennp, @jerrybboy, mind taking a look at this issue as it has been labeled with an integration (motionblinds_ble) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `motionblinds_ble` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign motionblinds_ble` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


motionblinds_ble documentation motionblinds_ble source (message by IssueLinks)

LennP commented 2 months ago

Hi fevo21!

Thanks for reporting this issue. The error you are seeing is built in to show the user the end positions of the motor have not been set. However, this error should of course not happen when the motor does have end positions.

Could you generate debug logs when the problem occurs again? The debug logs show the exact message that was received from the motor which may help figure out why you are receiving this error https://www.home-assistant.io/docs/configuration/troubleshooting/#enabling-debug-logging

fevo21 commented 2 months ago

Thanks for your quick reply! It occurs multiple times a week, so I expect to investigate your questions somewhere in the coming days. I just stopped the debug logging and have attached the file to this post. Earlier this afternoon there as an issue, but now it's rock solid again.

home-assistant_motionblinds_ble_2024-06-18T14-19-54.931Z.log

Just connecting to the motor will not solve the problem, the issue simply does not become apparent because there is no motion command involved. From the logging it shows that the connecting command will retrieve the "end position: UNKNOWN" status, but only leads to an error in HA when a motion command is involved.

EDIT: Some additional information: The blind is connected via ESP32-POE-ISO (ethernet cable) running ESPHome proxy with the following settings:

esp32_ble_tracker: scan_parameters: interval: 1100ms window: 1100ms active: true

bluetooth_proxy: active: true

LennP commented 2 months ago

Thanks! I found the issue. As you can see the motor sends back a message starting with 12040f02, where the next byte can either be 02 (no end positions) or 0e (it has end positions). However, it turns out you are getting 4e which I did not account for, as in my testing I never got back 4e but only 02 or 0e (that's why it says end positions UNKNOWN).

Do you know what you are doing differently to cause this, as you are saying it does not always happen? I will make sure to fix it, but it would be beneficial to know what the 4 in 4e means

fevo21 commented 2 months ago

Great, that all makes sense. I messed around a bit more and it seems I can reproduce the issue. Some further background: my roller blind is not free hanging, it is installed in the ceiling and might experience some slight resistance when opening and closing. Further, there is a window which can block the opening of the blind when it's open (I want to prevent that in HA with a window sensor).

I'm not sure how the position measurement and control of the blind works, but it seems the above can result in a small mismatch between configured end positions and actual end positions. To further confirm this hypothesis I unrolled/opened the blind whilst holding the bottom of the blind still (as if it was blocked) and let it run for just a couple of seconds. In this way the blind unrolls around its own axis. Accordingly I rolled up/closed the blind again via HA controls. At the point the blind stopped, it got into the '4e' state and I was not able to control it anymore via HA.

At this point the Motionblinds app was required to get things moving again. Although the position in the app says zero, I was still able to move de slider slighty further up, which gave a small rotation on the blind. From there on the blinds could be controlled again via HA.

The above was repeated a couple of times. Logging can be found here:

home-assistant_motionblinds_ble_2024-06-18T18-58-02.001Z.log

Looking at the logs I was wondering why the "Tilt" parameter has different values? To my knowledge a roller blind cannot tilt.

LennP commented 2 months ago

Interesting! So if I understand correctly you consistently get it to report 4e when you add resistance, but when you don’t you get 0e?

Would you be able to share a short video showing the resistance the blind is getting from opening and closing from within the ceiling, and of you holding the bottom of the blind still as you mentioned which results in 4e?

Looking at the logs I was wondering why the "Tilt" parameter has different values? To my knowledge a roller blind cannot tilt.

A roller blind can tilt if it is used as a double roller blind. Essentially, tilting is just moving the blind up and down in small increments. The motor always reports these values but if your blind is not a double roller blind you don’t use them. You can actually configure your roller blind as a double roller blind in home assistant and you will see that tilting moves the blind up and down within a small range. https://motionblinds.com/products/double-roller/

fevo21 commented 2 months ago

Interesting! So if I understand correctly you consistently get it to report 4e when you add resistance, but when you don’t you get 0e?

I cannot relate it directly to resistance, but this could be a factor resulting in some slight positional offset over time. Hence I don't get the error very often. However, I can consistently get it to report 4e when holding the blind during unrolling/closing. Maybe this forces an positional offset.

Would you be able to share a short video showing the resistance the blind is getting from opening and closing from within the ceiling, and of you holding the bottom of the blind still as you mentioned which results in 4e?

Normal operation: https://github.com/home-assistant/core/assets/96230951/6aeed272-547c-4814-9762-7526689b97bb

Holding the blind to force 4e: https://github.com/home-assistant/core/assets/96230951/cc4069b9-731e-4dff-a1e3-c1a96ff6d48f

As I explained above. After holding the blind it can be rolled up again via HA, but accordingly 4e occurs. From that point it is required to make a positional change via the motionblinds app. Accordingly the 4e is gone.

Another logfile added matching the situation on the second video. I included some comments in the logfile for explanation. home-assistant_motionblinds_ble_2024-06-19T10-04-23.545Z.log

LennP commented 2 months ago

Thanks! I am not sure whether setting the behavior of 4e to be the same as 0e (end positions are set) will fix the problem, or if it requires some extra command to be sent to fix the issue.

I created a version where 4e no longer results in the error. If you know how to get access to your Python instance, then you can use this command to install it: python -m pip install --force-reinstall --no-cache-dir --no-deps git+https://github.com/LennP/PyPi-MotionBlinds_BLE@test_endpositions_fix

If not no worries, then I will have to test it using a CMD-03 motor and try to reproduce the problem to see if that fixes the problem.

fevo21 commented 2 months ago

Great! I installed the package successfully in the HA docker container and will perform some testing tomorrow. Just for my info, will the package be overwritten when I install an update of Home Assistant?

LennP commented 2 months ago

If you installed it in the Python environment that is used by home assistant it should not overwrite it, as the version is unchanged. However, I am not very familiar with the many different ways of running home assistant, and the corresponding directory structures and locations of the Python environment.

For example, for a dev container I usually use the script/run-in-env.sh file to access the Python environment that is used by home assistant, but for the installation with HA OS I think you need access to the host to install something manually into Python environment.

script/run-in-env.sh python -m pip install --force-reinstall --no-cache-dir --no-deps git+https://github.com/LennP/PyPi-MotionBlinds_BLE@test_endpositions_fix

image

fevo21 commented 2 months ago

I just went into the HA docker container by using the docker exec -it <container name> bash command. I will check if the fix is still there after an update of HA.

Anyway, this morning I tested the updated package and everything is/remains working great now. I blocked the blind multiple times and in the logging the 4e is showing up, but recognized as a valid end position. The controls in HA continue to work as expected and after using an open/close command the 4e is magically transformed into 0e again, like it was the case with the official motionblinds app.

Some logging: home-assistant_motionblinds_ble_2024-06-21T07-44-12.430Z.log

I will keep on using the fix for a longer period of time, but I expect it won't give issues anymore. Big thanks to your quick response and fix!! Do you want me to test anything else at this point?

LennP commented 2 months ago

Awesome, good to hear! I have created a new release that fixes the issue and I will create a PR to bump to the new version in home assistant (but I don't think home assistant will overwrite it either way since the version is unchanged).

Thank you too for reporting the issue and providing the necessary logs for me to fix it! Other than the above issue the integration works as expected? There is still an open PR that adds sensors so hopefully that will be approved soon to give even more insights into your blinds!

fevo21 commented 2 months ago

Thank you too for reporting the issue and providing the necessary logs for me to fix it! Other than the above issue the integration works as expected? There is still an open PR that adds sensors so hopefully that will be approved soon to give even more insights into your blinds!

Yes it would be great to have the connection state and battery status as mentioned on above pull request!

Further, the position reporting could be improved in my opinion. I would like to have a position sensor which reports the actual or the latest known position. Currently the position is reported as an attribute of the cover entity, but only when the device is connected. I made a sensor which retrieves the position from that attribute and maintains value unless there is a change. This works fine, but there is an issue: the connection window is rather short, so the blinds can still be moving while the connection is dropped. In this case the position attribute will not be updated and remains at initial value.

I would like to limit the amount of update entity calls to preserve battery of the blinds. Therefore it would make more sense to disconnect the blinds after a minimum time (e.g. 15s) or when the blinds are not moving anymore + 5s margin whichever is longer.

Maybe I am missing something or there is a better way, just let me know. If required we can continue more in depth discussion in a separate improvement issue.

LennP commented 2 months ago

The default disconnect time is currently set to 15 seconds. I have previously worked on an options branch that includes the option to either:

Feel free to create another issue if you are interested in these features explaining how you would like it to work, then we can discuss it there!

fevo21 commented 2 months ago

Done: https://github.com/home-assistant/core/issues/120105