Tasshack / dreame-vacuum

Home Assistant integration for Dreame robot vacuums with map support
https://community.home-assistant.io/t/custom-component-dreame-vacuum
MIT License
879 stars 110 forks source link

Fails to start integration when "Prefer cloud connection" is unchecked #342

Closed MacDada closed 11 months ago

MacDada commented 11 months ago

When the Prefer cloud connection configuration option is unchecked, the integration fails to start. It's working when I do check this option (I'd prefer to get rid of the cloud entirely, BTW).

Logs:

2023-12-13 03:45:39.917 WARNING (MainThread) [custom_components.dreame_vacuum] Integration start failed: Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/miio/miioprotocol.py", line 193, in send
    data, addr = s.recvfrom(4096)
                 ^^^^^^^^^^^^^^^^
TimeoutError: timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/miio/miioprotocol.py", line 193, in send
    data, addr = s.recvfrom(4096)
                 ^^^^^^^^^^^^^^^^
TimeoutError: timed out
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/config/custom_components/dreame_vacuum/coordinator.py", line 326, in _async_update_data
    await self.hass.async_add_executor_job(self.device.update)
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/dreame_vacuum/dreame/device.py", line 996, in update
    self.connect_device()
  File "/config/custom_components/dreame_vacuum/dreame/device.py", line 733, in connect_device
    self._request_properties()
  File "/config/custom_components/dreame_vacuum/dreame/device.py", line 262, in _request_properties
    result = self._protocol.get_properties(props[:15])
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/dreame_vacuum/dreame/protocol.py", line 543, in get_properties
    return self.send("get_properties", parameters=parameters, retry_count=retry_count)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/dreame_vacuum/dreame/protocol.py", line 536, in send
    return self.device.send(method, parameters=parameters, retry_count=retry_count)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/miio/miioprotocol.py", line 233, in send
    return self.send(
           ^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/miio/miioprotocol.py", line 241, in send
    raise DeviceException("No response from the device") from ex
miio.exceptions.DeviceException: No response from the device
Tasshack commented 11 months ago

Please check the vacuum and HA is at the same network subnet and if already is, probably you have previously installed your device to the Dreamehome App for getting the firmware updates and then you have switched to the Mi Home app without hard resetting the device. Device disables the local api when it is installed to the Dreamehome App and it does not re-enabled when reinstalled to the Mi Home app again. Only way to re-enable the local api is hard resetting the device.

MacDada commented 11 months ago

check the vacuum and HA is at the same network subnet

they are

probably you have previously installed your device to the Dreamehome App for getting the firmware updates and then you have switched to the Mi Home app without hard resetting the device

yeah, i did just that. i mean, i did switch apps, resetted the vacuum with the pin - but i'm not sure if this is a "hard" reset (it erased maps for example)

Device disables the local api when it is installed to the Dreamehome App and it does not re-enabled when reinstalled to the Mi Home app again. Only way to re-enable the local api is hard resetting the device.

👍 I will google hard resetting and try again, thanks!

closed this as completed 5 hours ago

I'd argue this is still a bug -> as there is no information for the user. If this situation can be somehow detected, it would be great to propose the user the solution. If not, than at least a warning next to the checkbox would be nice. Or at least some kind info in the README.md ;)

Tasshack commented 11 months ago

as there is no information for the user. If this situation can be somehow detected, it would be great to propose the user the solution.

This issue can happen with multiple resons so there is no way to tell why the integration cannot reach to the device, it is same as like the device turned of completely. Not all vacuums can be installed to the Dreamehome app also switching between apps back and forth is not a normal user behaviour and not forseen even by Dreame engineers so they did not test this and has forgotten to add to code for re-enabling the local api from the device firmware.

If not, than at least a warning next to the checkbox would be nice. Or at least some kind info in the README.md ;)

Please do not forget that the warning you wanted to see must be short enough to fit to the mobile phone screen and should be translated to every availabile language just for covering this case. Most of the people just enable the checkbox and does not matter the rest even if I try to warn them to use this option only when vacuum and server are not in the same network. Miot does this automatically when it cannot be reached over local network.

Another option is installing the device to the Dreamehome app again and swiching to the Beta version of the integration that supports Dreamehome account login. Dreamehome cloud does not have local communication support but instead it has an mqtt server for supporting push messages so the integration does not need to send requests to the cloud constantly for getting updates. Don't forget that integration also constantly sends requests to the cloud for getting the map data even you disable Prefer Cloud option so using Dreamehome app will also prevent that too even it requires constant cloud communication.

MacDada commented 11 months ago

This issue can happen with multiple resons so there is no way to tell why the integration cannot reach to the device, it is same as like the device turned of completely.

ok, i was hoping that there could be some kind of artefact to detect -> like there would be a connection to the device, but with access revoked or sth -> so it would be distinguishable from a simple lack of connection (offline, etc).

Not all vacuums can be installed to the Dreamehome app also switching between apps back and forth is not a normal user behaviour and not forseen even by Dreame engineers

That's actually a surprise to me o.O If the device can be used by both apps, then one must assume that ppl will be switching to check which one is better. I mean, they have to put some effort to develop it for 2 apps/envs anyway, then why bother, if nobody is supposed to be choosing between them :P

Dreame being bought by Xiaomi, etc. - history I guess.

Anyway, in my case it was like this:

  1. bought device
  2. installed the official Dreame app
  3. decided to integrate with HomeAssistant
  4. wtf that I need Xiaomi cloud for that :P
  5. reseting device to Xiaomi app

they did not test this and has forgotten to add to code for re-enabling the local api from the device firmware

"forgotten" xd i'm starting to create a conspiracy theory in my mind… xd

Please do not forget that the warning you wanted to see must be short enough to fit to the mobile phone screen

I can only feel pity for people wanting to do anything more complicated than turning on a light using a smartphone :D Configuring integrations, automations, checking up the logs -> I do it on desktop. But, ok, I will keep them poor bastards in mind ;)

Don't forget that integration also constantly sends requests to the cloud for getting the map data even you disable Prefer Cloud option so using Dreamehome app will also prevent that too even it requires constant cloud communication.

That's one of the reasons I'm planning on switching to Valetudo in the future ;)

Anyway, big thanks for your amazing work with this integration! Every time I see OSS like that I cannot believe how other programmers find courage and time to make a working project, and fight obstacles put by companies in the way!

Shm1ks commented 7 months ago

Please check the vacuum and HA is at the same network subnet and if already is, probably you have previously installed your device to the Dreamehome App for getting the firmware updates and then you have switched to the Mi Home app without hard resetting the device. Device disables the local api when it is installed to the Dreamehome App and it does not re-enabled when reinstalled to the Mi Home app again. Only way to re-enable the local api is hard resetting the device.

Hello, how to hard resetting the device? (Dreamebot X10 pro)

RobinVanCauter commented 7 months ago

I'm wondering this too. When I search Google for hard reset procedures all I can find is pressing the reset button (under cover) for 3 seconds. Which is what I did before I added it to the Mi app. It's on the same subnet, so the fact it isn't working probably means I'm not correctly resetting?

Shm1ks commented 7 months ago

Hell

I'm wondering this too. When I search Google for hard reset procedures all I can find is pressing the reset button (under cover) for 3 seconds. Which is what I did before I added it to the Mi app. It's on the same subnet, so the fact it isn't working probably means I'm not correctly resetting?

Hello, did you succeed?

Tasshack commented 7 months ago

I cannot confirm this but Dreame may have actually disabled the local Api from some devices. If that was the case, you wont be able to use this integration without Prefer cloud connection so I suggest switching to the Dreamehome App which works better with the integration instead of enabling cloud connection to Miio Api.

ghmeister commented 7 months ago

I cannot confirm this but Dreame may have actually disabled the local Api from some devices. If that was the case, you wont be able to use this integration without Prefer cloud connection so I suggest switching to the Dreamehome App which works better with the integration instead of enabling cloud connection to Miio Api.

It seems that my latest firmware update (I was using the Xiomi Miio App before) indeed removed the local API. Is there anything I can do to reactivagte it (different firmware?)? I guess, switching to the Dreamehome App now won't make a difference anymore

Tasshack commented 7 months ago

It seems that my latest firmware update (I was using the Xiomi Miio App before) indeed removed the local API. Is there anything I can do to reactivagte it (different firmware?)?

You can try to downgrade it and try to hard reset again but I am not sure downgrading is possible or how?

I guess, switching to the Dreamehome App now won't make a difference anymore

If you cannot enable the local api again switching to the Dreamehome will make difference because Dreamehome uses a socket api that would eliminate the requirement of sending periodic requests to cloud from integration. Also you can use the camera streaming feature with the Dreamehome (not with the integration yet).

Using Dreamehome is better for the integration than using Mi Home with Prefer Cloud Connection. Option is just there for the vacuums cannot be added to the Dreamehome cloud.

ghmeister commented 7 months ago

If you cannot enable the local api again switching to the Dreamehome will make difference because Dreamehome uses a socket api that would eliminate the requirement of sending periodic requests to cloud from integration. Also you can use the camera streaming feature with the Dreamehome (not with the integration yet).

Using Dreamehome is better for the integration than using Mi Home with Prefer Cloud Connection. Option is just there for the vacuums cannot be added to the Dreamehome cloud.

Thanks for the explanation. I switched to the Dreamehome app, but the Integration still does not work. I removed the old Dreame device and tried to set up a new one in HA. After the first screen (asking for my Xiami Cloud credentials), a second screen comes up, asking for the device's IP address and Token. It's already filled correctly (obviously stored by HA somewhere), but it won't let me connect ("Connection failed"). Any ideas?

Tasshack commented 7 months ago

@ghmeister Dreamehome account support is available on Beta. You need to also install the Beta version of the integration from HACS.

ghmeister commented 7 months ago

Ahh, got it. Just installed it, and it works, thanks!

StayPirate commented 7 months ago

My L10s Ultra has always been connected to the Mi Home app (Xiaomi) and I've been using it with this integration (non-Beta) since the beginning. Last week I updated the firmware (the upgrade was provided within the Mi Home iOS app), after that the integration stopped to work. My best guess is that Xiaomi really killed local APIs with this update.

I now followed @Tasshack suggestion and connected the robot to the Dreame infrastructure, I updated the HA integration to the latest beta and everything started to work again :).

I do have a question, you mentioned that by using the Dreame login there would be an mqtt server support:

Dreamehome cloud does not have local communication support but instead it has an mqtt server for supporting push messages so the integration does not need to send requests to the cloud constantly for getting updates.

Do I need to apply any manual configuration in order to get it work? Or would the beta version make use of it automatically?

Tasshack commented 7 months ago

My best guess is that Xiaomi really killed local APIs with this update.

If integration stopped working after the firmware update that means they have definitely disabled it and no more local connection to anyone.

Do I need to apply any manual configuration in order to get it work? Or would the beta version make use of it automatically?

Integration will handle the mqtt connection automatically. Mqtt server is just a bridge between robot and the server for only getting the updates. Other requests like updating a setting or starting a cleaning job still requires https requests similar on the Mi cloud. Works like this;

So normally you dont need mqtt connection to make integration work but this is all for just eliminating the periodic https requests to the cloud for getting the updates also this has an advantage of getting the updates instantly including the map data.

You can experience this yourself by changing a setting from Dreamehome app and observing it reflects to HA instantly instead you need to wait up to 15 seconds when you are using Mi Home app.

StayPirate commented 7 months ago

Even though we all agree that fully local management is the holy grail... this mqtt quick update is interesting and a very good thing to have.

When you say

When cloud gets a write request from vacuum it broadcasts it over mqtt

do you mean that when the vacuum sends a write request to the cloud, it also broadcasts it over mqtt in the LAN. Am I correct?

Thanks for all your support and the kind clarification 🙏🏼

Tasshack commented 7 months ago

Vacuum does everything same as the Mi Home cloud. Mqtt server is installed on the Dreame cloud machine and it relays vacuum update property requests internally. Integration justs subscribes it and listens the updates from cloud instead of requesting them periodically.

Tasshack commented 7 months ago

Also you would be able to use the camera streaming feature (not within the integration yet) when you switched to the Dreamehome app.

Nafania commented 3 months ago

Did anyone manage to turn on local mode back? It seems like it was forcefully turned off on 3204 firmware for dreame l10s pro. And I wouldn't say I like devices that depend on some 3rd party cloud :)

Tasshack commented 3 months ago

Did anyone manage to turn on local mode back? It seems like it was forcefully turned off on 3204 firmware for dreame l10s pro. And I wouldn't say I like devices that depend on some 3rd party cloud :)

Downgrade (if you can) or install Valetudo.