DeebotUniverse / client.py

Deebot client library in python
https://deebot.readthedocs.io
GNU General Public License v3.0
27 stars 41 forks source link

Full support for Deebot T20 Omni #441

Open NEVdataDyne opened 11 months ago

NEVdataDyne commented 11 months ago

Is there an existing issue for this?

Is your feature request related to a problem?

No

Suggested solution

I'd like for the HA integration to support the "cleaning mode" option of the T20. (this is what is important for me)

However I extracted all options into files with corresponding jsons so it is possible to implement support for all the T20 options and actions.

All files contain options to define how all future cleanings will be performed. One exception is the "Station start action" file where these jsons are command for the station to perform an action.

Update 2023-10-25 : Added action "Wash station sink" in file "Ecovacs T20 Station start action.txt" Update 2023-11-03 : Added "Ecovacs T20 Reset dust bag life span.txt" Update 2023-11-14 : Added get commands

NEVdataDyne commented 11 months ago

Screenshots

Carpet cleaning strategy ![T20 Carpet cleaning strategy](https://github.com/DeebotUniverse/Deebot-4-Home-Assistant/assets/82730421/e9596d9a-c4fd-415c-9aa6-ed9bd67f0a19)
Station option and actions ![T20 Station option and actions](https://github.com/DeebotUniverse/Deebot-4-Home-Assistant/assets/82730421/98778191-88aa-4c67-8dcd-3992dc9e32af)
Cleaning preferences, cleaning mode, cleaning times, suction power ![T20 Cleaning preferences, cleaning mode, cleaning times, suction power](https://github.com/DeebotUniverse/Deebot-4-Home-Assistant/assets/82730421/3f605db1-fe95-47b3-8d61-1de1207e2b23)
Cleaning efficiency - Edge deep cleaning ![T20 Cleaning efficiency - Edge deep cleaning](https://github.com/DeebotUniverse/Deebot-4-Home-Assistant/assets/82730421/a17951b1-7544-4195-aa39-ad813710cb4c)
Do not disturb, child lock ![T20 Do not disturb, child lock](https://github.com/DeebotUniverse/Deebot-4-Home-Assistant/assets/82730421/f351815d-b49b-49b6-854d-878422c50729)
Smart cleaning 1, mopping pad wetness, cleaning interval, hot air drying time, auto empty ![T20 Smart cleaning 1, mopping pad wetness, cleaning interval, hot air drying time, auto empty](https://github.com/DeebotUniverse/Deebot-4-Home-Assistant/assets/82730421/e0254f8a-03ef-4394-8eb3-a29b6b6ea381)
Smart cleaning 2, continuous cleaning, TrueDetect 3D ![T20 Smart cleaning 2, continuous cleaning, TrueDetect 3D](https://github.com/DeebotUniverse/Deebot-4-Home-Assistant/assets/82730421/64374d19-a52a-4c73-baf7-64ad39871036)
edenhaus commented 11 months ago

Thanks a lot :heart_eyes:. It will take some time to implement them all :)

As the cleaning mode is important for you, I gave it a quick look and have some questions:

Ecovacs T20 cleaning mode.txt

What is the bdTaskID? Looks like it can be a unix time as it is similar to the value of ts but it a lot longer

NEVdataDyne commented 11 months ago

I don't know about bdTaskID but I performed the follwing tests. They all worked bdTaskID = 1696155367474117; ts=1696155367471 (new request, no modifications) bdTaskID = 1695925609322691; ts=1696155367471 (took the bdTaskID from a request in the file provided three days ago and kept new timestamp) bdTaskID = 1695925609322691; ts=1695925609319 (changed both bdTaskID and ts to the values from the file provided three days ago) bdTaskID = HAisAwesome; ts=HAisAwesome (put a string where there should be an integer)

I think that if you put the same value as in ts, it'll work fine 😄

edenhaus commented 11 months ago

Can you test what happens if we omit bdTaskID? If we don't need it, we should not send it to have bigger backward compatibility.

NEVdataDyne commented 11 months ago

Yes, I tested and bdTaskID is not needed at all

NEVdataDyne commented 11 months ago

I realized that I'd need two other functionalities. The first one is the "cleaning pads interval" with the possibility to put a higher number in "interval" than 15 (I'll make some tests but I'd say 30 and 60 (min) ). This is because some weeks ago there seems to have been an update and since then, when the robot cleans a floor where the station is not present, after the "cleaning pad interval" has been reached, it will search endlessly for its station...

The second one would be the washing moping pads (in "station start action" file) because of course, before putting the robot on another floor where there is no station, one need to ask the robot to wet and clean the pads. In the "station start action" file, I put one entry for washing moping pads with hot water and one for washing moping pads without hot water but they are the same. The fact that it uses hot water or not comes from the command in the file "station hot water washing option" (I do not need this option in HA since I always use the same (hot water)).

NEVdataDyne commented 11 months ago

I confirm that bdTaskID is not necessary for both commands above.

I put 6000 (min) for the "cleaning pads interval" and the robot seemed to accept it. I think adding 30 and 60 min would be perfect (or allowing any input as a parameter). I'll make some tests to confirm that if I put 60, the robot do clean using the mops for >15min without returning to the station (I don't have a house big enough for the robot to clean 60 min straight so if it cleans for >15min I'll consider the test to be a success 😆 )

indzan commented 10 months ago

Thank you so much to both of you for working on this. Not sure how I can help but let me know where to tip :)

NEVdataDyne commented 10 months ago

I confirm that putting 60min (or any value) for the cleaning pads interval works fine to avoid deebot to return cleaning the mopping pads while cleaning a floor where there is no station. Btw I could fulfill all my requirements by using the restful command integration to send each missing command from the deebot integration that I needed.

edenhaus commented 10 months ago

I will add the commands after I have changed the whole lib and integration to use device capabilities as not all devices support all features/commands.

For example my bot does not support V2 commands and newer support only support V2 commands

NEVdataDyne commented 10 months ago

I understand, no problem.

I thought I could simply use hard coded restful commands to perform the actions and change settings I wanted but unfortunately the token changes with time. Is there a variable where I can get it from your integration somehow?

edenhaus commented 10 months ago

There is no easy way to get it as the token is refreshed automatically in the authenticator.

But I think it would be easier if you add the missing commands to this integration and add support for the T20. For the work mode command, I have created two PRs one with the command logic in the library (https://github.com/DeebotUniverse/client.py/pull/330/files) and one to add an entity to this component (https://github.com/DeebotUniverse/Deebot-4-Home-Assistant/pull/449)

Could you please review the PR's and maybe also test it? I have added "blind" the partly capabilities of the T20 Omni here. It would be very helpful if you could review/test it. I don't have your model so I can't do it. Note the capabilities are only partly with the new work_mode command. When a new command is added the capabilities will be extended.

As I'm currently a little bit short on time, could you add the remaining commands to the library following the example above? One PR per command please as this helps reviewing it. Please feel free to comment, if you need any help.

NEVdataDyne commented 10 months ago

I want to test your code however could you please provide me some hints or guidance as to how to install the version including the pull requests into my HA?

If I understand correctly, I need somehow to take your project into my github, then I need to merge your pull requests and then install that into my HA? If yes that's a lot of steps where I need to figure out how to do it (I know I can do it but with my current knowledge that'll take me some time). I see that in your pull request DeebotUniverse/Deebot-4-Home-Assistant#449 it says that there are some unsuccessful merges, can this be ignored?

edenhaus commented 10 months ago

Currently it is not possible to install a PR directly with HACS. For each PR, the bot will create a zip file, which must be downloaded and extract in [config folder]/custom_components/deebot. Can you test it like this?

NEVdataDyne commented 10 months ago

I downloaded the zip file from this link https://github.com/DeebotUniverse/Deebot-4-Home-Assistant/pull/449

Then I went to HA through samba share and replaced the content from config\custom_components\deebot with the content of the zip file.

I restarted the Home assistant virtual machine.

I don't see a "work mode" anywhere

Did I do something wrong?

No option to set work mode in device Action device

No Vacuum: service related to a work mode (not complete list in screenshot) Call service

No config or diagnostic related to a working mode Config and diagnostic

schmoogol commented 10 months ago

It looks the same for me when I tried. I get this error in the logs:

Logger: [homeassistant.components.select](http://homeassistant.components.select/)
Source: helpers/entity_platform.py:359
Integration: Select (documentation, issues)
First occurred: 12:20:20 (3 occurrences)
Last logged: 13:11:57

Error while setting up deebot platform for select
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 359, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/deebot/select.py", line 67, in async_setup_entry
    controller.register_platform_add_entities(
  File "/config/custom_components/deebot/controller.py", line 109, in register_platform_add_entities
    new_entites.append(entity_class(device, capability, description))
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/deebot/select.py", line 88, in __init__
    self._attr_options = self.entity_description.options_fn(capability)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/deebot/select.py", line 50, in <lambda>
    options_fn=lambda cap: [mode.display_name for mode in cap.types],
                                                          ^^^^^^^^^
AttributeError: 'CapabilitySet' object has no attribute 'types'
edenhaus commented 10 months ago

It is fixed in the library. A restart of HA should be enough to install the new library version. If the error still exists, please login to the HA container (or where HA is running) and run pip uninstall deebot-client and restart. This forces a new installation of the library.

Otherwise comment here :) Thanks for testing. Please always attach the logs as I need them to identify the problem

schmoogol commented 10 months ago

That has resolved the issue. I can confirm that the work mode selection is now available and changes are correctly reflected in the Ecovacs app. IMG_6064

edenhaus commented 10 months ago

Perfect to hear, so I can merge it the next days.

@schmoogol Can I ask you to test if the T20 supports the getNetInfo command? You can easily test it with the developers tools.

If the command is supported, you should get something similar to

event_type: deebot_custom_command
data:
  name: getNetInfo
  response:
    header:
      [REMOVED as not relevant]
    body:
      code: 0
      msg: ok
      data:
        IP: [REMOVED]
        ssid:  [REMOVED]
        rssi: "-68"
        wkVer: 0.1.2
        mac:  [REMOVED]

The only interesting part is located under data->response->body->data. It would be nice to share all field names with their value type (int, float, string,...)

Could you please repeat the above steps with the command getWifiList

Thanks in advance :) With these commands, I can retrieve the mac address which allow to link the vacuum with other device entires like unifi and co

NEVdataDyne commented 10 months ago

Could you tell me where to find the updated files to be installed?

schmoogol commented 10 months ago

The getNetInfo and getWifiList commands both work. I've anonymised my IP, SSID and MAC for the readouts below - is there a way for me to get it to tell me the value types or we just have to infer them?

event_type: deebot_custom_command
data:
  name: getNetInfo
  response:
    header:
      [REMOVED]
    body:
      code: 0
      msg: ok
      data:
        ip: 192.168.123.456
        ssid: MySSID
        rssi: "-53"
        wkVer: 0.1.2
        mac: 12:A3:B4:56:78:91
event_type: deebot_custom_command
data:
  name: getWifiList
  response:
    header:
      [REMOVED]
    body:
      code: 0
      msg: OK
      data:
        mac: 12:A3:B4:56:78:91
        list:
          - ssid: MySSID
            rssi: 67
            ip: 192.168.123.456
            mask: 255.255.255.0
        state: ok

Could you tell me where to find the updated files to be installed?

@NEVdataDyne, you shouldn't have to manually add any additional files. I ran the pip uninstall command suggested above from within the HA container then restarted HA and the updated version of deebot-client was automatically installed.

edenhaus commented 10 months ago

@schmoogol Thanks for testing :)

As the PR is merged, the branch doesn't exist anymore, but the feature is already on dev, so you can easily install via hacs the "dev" version

NEVdataDyne commented 10 months ago

Hello,

Because I want to understand everything, I have (too many?) questions...

I tried to execute the "pip uninstall deebot-client" command. I am running HA in a VM on ESXi and on the virtual screen I get the HA CLI, not the ssh one. I made some researches and I am still confused between HA installations where some people can run ssh commands and some people can't. Also I didn't find a clear answer as to how I need to force the uninstall without using "pip uninstall deebot-client". Do you know how I can either run ssh commands or uninstall without using pip uninstall?

Anyway, I did install the dev version using HACS, rebooted HA and I get the same error schmoogol had before you fixed it. I suppose I really need to either find a way to run pip uninstall or find an alternative?

image

NEVdataDyne commented 10 months ago

Unsing web terminal add on, I get this message when trying to uninstall deebot-client

image

schmoogol commented 10 months ago

I think the HA CLI should be the same as using ssh but keeping in mind that HA OS runs everything in docker containers. As the uninstall command needs to be run inside the HA container you could try docker exec -it homeassistant bash then run the pip uninstall deebot-client command within the container.

I'm not exactly sure how VM installs work but on my Pi install I have to use the 'Advanced SSH & Web Terminal' add-on with protection mode off to run commands within containers.

edenhaus commented 10 months ago

Unsing web terminal add on, I get this message when trying to uninstall deebot-client

image

You need to access the terminal where HA is running. I'm not familiar with ESXi and therefore I cannot give you hints there... As already described by @schmoogol, you need to access the container

NEVdataDyne commented 10 months ago

Got it working, thanks for the explainations! I thought all this docker discussions were due to people running HomeAssistant unsing a docker container and since I am using a VM I didn't think it applied to me...

NEVdataDyne commented 10 months ago

As I'm currently a little bit short on time, could you add the remaining commands to the library following the example above? One PR per command please as this helps reviewing it. Please feel free to comment, if you need any help.

I created PR https://github.com/DeebotUniverse/client.py/pull/339, as you will probably notice... I had close to no clue of what I was doing so I don't know if my work is helpful or not.

I wanted the cleaning pads interval to be a integer that could be freely set between 1 and 60, I tried to do something like that combining what you did with the work mode and the volume setting but... it was probably so wrong that wouldn't have helped at all. Then I decided to copy the work mode and went for four predifined values, the three provided by ecovacs and one with 60 min interval so the robot basically never go to the station to clean the pads.

If what I did did help, the next one I'd like to do is the clean mop action and empty dust bin action but these are very different from work mode so I'd need some guidance

edenhaus commented 9 months ago

Each PR will help as I cannot implement all custom on my own :) I left some comments directly in the PR :)

NEVdataDyne commented 9 months ago

@edenhaus Could you please implement the base station "Washing moping pads" action so I have an example? I really don't know where to start with this one.

edenhaus commented 9 months ago

Yes but not within the next two weeks as I have no time.

jdmevo123 commented 9 months ago

I tried installing the beta version to see if I could get the map and other functions working for the T20, however I’m throwing this error in the logs, any idea?

`Logger: deebot_client.commands.json.common Source: runner.py:188 First occurred: 9:29:51 PM (12 occurrences) Last logged: 9:30:52 PM

No response received for command "getCachedMapInfo". This can happen if the device has network issues or does not support the command No response received for command "getMapTrace". This can happen if the device has network issues or does not support the command No response received for command "getMajorMap". This can happen if the device has network issues or does not support the command No response received for command "getBattery". This can happen if the device has network issues or does not support the command No response received for command "getSpeed". This can happen if the device has network issues or does not support the command `

DieterKoblenz commented 9 months ago

I tried installing the beta version to see if I could get the map and other functions working for the T20, however I’m throwing this error in the logs, any idea?

`Logger: deebot_client.commands.json.common Source: runner.py:188 First occurred: 9:29:51 PM (12 occurrences) Last logged: 9:30:52 PM

No response received for command "getCachedMapInfo". This can happen if the device has network issues or does not support the command No response received for command "getMapTrace". This can happen if the device has network issues or does not support the command No response received for command "getMajorMap". This can happen if the device has network issues or does not support the command No response received for command "getBattery". This can happen if the device has network issues or does not support the command No response received for command "getSpeed". This can happen if the device has network issues or does not support the command `

Have you read the thread above and the other issues? There is still a lot missing, including the map, I think this is the same issue as DeebotUniverse/Deebot-4-Home-Assistant#268

NEVdataDyne commented 8 months ago

Could someone who has some time implement the "Washing moping pads (with hot water)" in "Ecovacs T20 Station start action.txt" so I have an example of a "press button" action?

js4jiang5 commented 7 months ago

Got it working, thanks for the explainations! I thought all this docker discussions were due to people running HomeAssistant unsing a docker container and since I am using a VM I didn't think it applied to me...

Could you share with me how you resolved it? My HA is also installed in VM, and my host is MacOS. When I enter the command in terminal, it always shows "pip command not found". Do I need to install more add-on for pip to work?

js4jiang5 commented 7 months ago

Got it working, thanks for the explainations! I thought all this docker discussions were due to people running HomeAssistant unsing a docker container and since I am using a VM I didn't think it applied to me...

Could you share with me how you resolved it? My HA is also installed in VM, and my host is MacOS. When I enter the command in terminal, it always shows "pip command not found". Do I need to install more add-on for pip to work?

Never mind. I've figured it out.

edenhaus commented 7 months ago

Could someone who has some time implement the "Washing moping pads (with hot water)" in "Ecovacs T20 Station start action.txt" so I have an example of a "press button" action?

https://github.com/home-assistant/core/blob/dev/homeassistant/components/ecovacs/button.py

NEVdataDyne commented 7 months ago

@edenhaus I can see some implementation of buttons but my level in coding is so low, the only way I can develop something is to see exactly what someone had to add in every file of the project and do something similar.

applegeeks commented 6 months ago

@edenhaus I can see some implementation of buttons but my level in coding is so low, the only way I can develop something is to see exactly what someone had to add in every file of the project and do something similar.

wash pad and hot air drying button/option would be good. or even a send command function that we can trigger would be appreciated :)

love everyone's work on this btw, as so far, its proving to be a better alternative than having to use the deebot app in terms of flexibility. :)