python-miio icon indicating copy to clipboard operation
python-miio copied to clipboard

Dreame F9 Robot Vacuum |dreame.vacuum.p2008|

Open wilhelmphilipp94 opened this issue 3 years ago • 47 comments

Before submitting a new request, use the search to see if there is an existing issue for the device.

Device information:

  • Name(s) of the device: Dreame F9 Robot Vacuum
  • Link: https://www.dreame-technology.com/products/dreame-f9

Use miiocli dreamevacuum --ip <ip address> --token <token>.

dreame.vacuum.p1808 dreame.vacuum.p2008 return_home ---> Start Cleanup aiid 1 Start Charge: in: [] -> out: [] start_sweep ---> Return to Docking Station aiid 1 Start Sweep: in: [] -> out: []

  • Model: [dreame.vacuum.p2008]
  • Hardware version: Where can i look this up?
  • Firmware version: 3.5.8_1024

Additional context I used the dreame.vacuum.p2008 build. Tested some commands and found that i can start a cleanup with the "return_home" command and return the robot to the docking station with "start_sweep"

Additionally i listend with wireshark while using the Xiaomi Home App. Here is the log: https://textuploader.com/1f3wm There should be "Start Cleanups" and Return to docking station commands

wilhelmphilipp94 avatar Sep 08 '20 15:09 wilhelmphilipp94

Where did you find a p2008 build ? I only know of fork https://github.com/rytilahti/python-miio/pull/683 which implements basic functionnality for mc1808 (Xiaomi 1C). You can easily modify it by changing all IDs to the ones corresponding to the F9 using the devtools (use type urn:miot-spec-v2:device:vacuum:0000A006:dreame-p2008:1).

I managed to control most of the vacuum using this technique, however I am still looking for a way to upload custom voice packs. I did find a set-voice property (siid 7, piid 4) which is write only, but I have no idea how to use it.

What setup do you use to make Wireshark captures ? I can't seem to get anything using MEmu or Bluestacks

mickabrig7 avatar Sep 13 '20 17:09 mickabrig7

Sorry my mistake! I used the #683 fork with the basic functionality for mc1808. I use Bluestacks and install the Xiaomi App there. (PC on the same Network as the vaccum)

Than I'm capturing with Wireshark (Filter: UDP and your Robot IP). (My Pc is connected via Lan so I choose the LAN-Adapter) After that i export the Capture as a JSON file and use Miio from (https://github.com/aholstenson/miio/blob/master/docs/protocol.md) to look at the data.

If u want i can take some pictures. Just tell me which part of the setup u want to see.

You can easily modify it by changing all IDs to the ones corresponding to the F9 using the devtools (use type urn:miot-spec-v2:device:vacuum:0000A006:dreame-p2008:1).

I'm unfamiliar with this (Devtools) could u point me in the right direction?

wilhelmphilipp94 avatar Sep 13 '20 21:09 wilhelmphilipp94

Weird, I can't seem to be able to communicate with the vaccuum using Bluestacks... I was trying to see what is sent when applying a different voice pack through the app to understand how the set-voice property works (the 1C does this through an action, not a property, so I can't just mimick the code from the fork). My final goal is to be able to send over custom voice packs and get some Mario 64 sounds going on 😎 I'd be so glad if you could get a capture of that !

I'm unfamiliar with this (Devtools) could u point me in the right direction?

No problem, you just have to navigate to the devtools folder and do the following :

  • Find the type for the device you want to implement on here (for the F9, it's urn:miot-spec-v2:device:vacuum:0000A006:dreame-p2008:1)
  • python3 miottemplate.py download [device type], this will download a .json file containing all the definition for the F9's services, actions, properties, etc. You can either format it with a Notepad++ plugin and explore it, or do the next step to generate some pseudo-Python code
  • python3 miottemplate.py generate [downloaded file name] >> [whatever].py

Personally, I find going through the .json file much easier to understand how the vacuum works, rather than reading the generated Python code.

mickabrig7 avatar Sep 13 '20 21:09 mickabrig7

Here you go: https://textuploader.com/1p09d I captured the change from German to English and reverse. But I'm unsure. It seems it has to download it first...

Tell me if it's Ok or if i should capture a second one

wilhelmphilipp94 avatar Sep 13 '20 22:09 wilhelmphilipp94

Oh my god yes that's perfect, I could extract the exact string that's needed to make the robot download the voice pack using set-voice ! Here it is : "{\"id\":\"DE\",\"url\":\"https:\/\/awsde0.fds.api.xiaomi.com\/dreame-product\/dreame.vacuum.p2008\/voices\/package\/deyu.tar.gz\",\"md5\":\"96ab843008bb4d19480ac8a07d648aa7\",\"size\":1391385}"

Looks like it requires the language ID ("DE", "EN", etc), the voice pack URL (this is for the German pack), MD5 hash and size in bytes. The .tar.gz file just contains .ogg audio files with numbers as names. So in theory, anyone can just make their custom pack, host it somewhere and have the vacuum download and apply it !

Thanks for your help 😄 If that's okay, do you think you could do another capture when switching to French just so that I can get the pack URL please ?

mickabrig7 avatar Sep 13 '20 22:09 mickabrig7

Oh and also, I'm still trying to figure some things out with the F9 implementation but don't hesitate to ask me questions ! If I go far enough, I might make a PR to resolve this issue, but no promises

mickabrig7 avatar Sep 14 '20 06:09 mickabrig7

https://awsde0.fds.api.xiaomi.com/dreame-product/dreame.vacuum.p2008/voices/soundpackage.json

rezmus avatar Sep 14 '20 11:09 rezmus

Sorry for the late reply (Work + Master thesis). This should be it? -> 192.168.1.135 data= {"id":6691,"method":"set_properties","params":[{"did":"<myID>","siid":7,"piid":4,"value":"{"id":"FR","url":"https://awsde0.fds.api.xiaomi.com/dreame-product/dreame.vacuum.p2008/voices/package/fayu.tar.gz","md5":"25a2cd27bfef5ad786e2716c7d04d15c","size":1317003}"}]}

Oh and also, I'm still trying to figure some things out with the F9 implementation but don't hesitate to ask me questions ! If I go far enough, I might make a PR to resolve this issue, but no promises

Oh thank you :) Will do!

Do you think it's possible to get the map data? I want to display it at my Home automation hub (Openhab2)

If I have time tonight i will try your example with the Devtools!

wilhelmphilipp94 avatar Sep 14 '20 15:09 wilhelmphilipp94

It's all good, thanks ! I have all the voice pack URLs thanks to the .json file posted by @rezmus.

Well, it seems to be stored on the vacuum and the app loads it from it so I guess so. I do see a map-data property (siid 6, piid 1), so maybe this is it ? I'll try to do some digging when I have the time !

mickabrig7 avatar Sep 18 '20 21:09 mickabrig7

I'm noticing something weird with the EN voice, the URL clearly indicates that it's downloading from the 1C's packs, and it doesn't sound like the English voice that comes pre-installed with the vacuum. Does anyone know the URL to the "real" F9 English voice pack ? I'm really not liking the 1C voice

mickabrig7 avatar Sep 18 '20 21:09 mickabrig7

https://ufile.io/oc7yh4u1

rezmus avatar Sep 18 '20 21:09 rezmus

...well thanks 😆 How did you find that one ?

mickabrig7 avatar Sep 18 '20 21:09 mickabrig7

Hey, sooo I finally got around to making a simple implementation with just enough functionnality to use in Home Assistant using this integration and this card.

I even modified the install_voice_pack function to upload a custom file ! You just need to specify the URL, MD5 hash and size in bytes and you're good to go. You may also need to change the did to match your robot's.

And one last thing, I couldn't find any equivalent action for the find function (and I don't even know what it's supposed to do tbh), so for now I just play audio.

Enjoy ! dreamevacuum.zip

mickabrig7 avatar Sep 26 '20 21:09 mickabrig7

https://ufile.io/oc7yh4u1

How can we integrate the p2008 device ?

titidnh avatar Oct 04 '20 13:10 titidnh

Hey @mickabrig7 @wilhelmphilipp94 ;-) So you have now most functions of your Dreame F9 working with Home Assistant? Without changing the firmware, right? Im totally new to this, but do you still need the Xiaomi App and a Internet-Connection to controll the robot or can you "lock" the cloud access?

bigdx avatar Nov 25 '20 11:11 bigdx

Hey @mickabrig7 @wilhelmphilipp94 ;-) So you have now most functions of your Dreame F9 working with Home Assistant? Without changing the firmware, right? Im totally new to this, but do you still need the Xiaomi App and a Internet-Connection to controll the robot or can you "lock" the cloud access?

Sadly, no locking-out of the Xiaomi cloud yet as the stock firmware is still running on the robot, we're just using the same protocol as Xiaomi's app to send actions through Home Assistant.

This would be possible when the device becomes rootable and Valetudo is updated to support it, but not for now...

mickabrig7 avatar Nov 25 '20 11:11 mickabrig7

Hey @mickabrig7 @wilhelmphilipp94 ;-) So you have now most functions of your Dreame F9 working with Home Assistant? Without changing the firmware, right? Im totally new to this, but do you still need the Xiaomi App and a Internet-Connection to controll the robot or can you "lock" the cloud access?

Sadly, no locking-out of the Xiaomi cloud yet as the stock firmware is still running on the robot, we're just using the same protocol as Xiaomi's app to send actions through Home Assistant.

This would be possible when the device becomes rootable and Valetudo is updated to support it, but not for now...

Thx for the fast answer! Really sad :-( ... and when the robot looses internet connection (i.e. blocked by router) i guess it stops working currently, right?

bigdx avatar Nov 25 '20 11:11 bigdx

Hey @mickabrig7 @wilhelmphilipp94 ;-) So you have now most functions of your Dreame F9 working with Home Assistant? Without changing the firmware, right? Im totally new to this, but do you still need the Xiaomi App and a Internet-Connection to controll the robot or can you "lock" the cloud access?

Sadly, no locking-out of the Xiaomi cloud yet as the stock firmware is still running on the robot, we're just using the same protocol as Xiaomi's app to send actions through Home Assistant.

This would be possible when the device becomes rootable and Valetudo is updated to support it, but not for now...

Thx for the fast answer! Really sad :-( ... and when the robot looses internet connection (i.e. blocked by router) i guess it stops working currently, righ ?

I'm not sure, it may work actually ! I couldn't try it because my router doesn't allow me to filter Internet access of certain MAC addresses, but please keep me informed

mickabrig7 avatar Nov 25 '20 11:11 mickabrig7

Thx for the fast answer! Really sad :-( ... and when the robot looses internet connection (i.e. blocked by router) i guess it stops working currently, righ ?

I'm not sure, it may work actually ! I couldn't try it because my router doesn't allow me to filter Internet access of certain MAC addresses, but please keep me informed

I would love to, but I havent bought the F9 yet as I first wanted to be sure to be able to kill the cloud-connection (until valetudo is available). Maybe you can use the child-protection to test it? Or a guest-feature? If you tell me which router you have ill try to find out if it is somehow possible ;-) Edit: Or simply pull the cable/turn off internet completely for a while? If possible ...

@wilhelmphilipp94 or maybe you can try that?

bigdx avatar Nov 25 '20 11:11 bigdx

thx for your work, I just modified your code in dreamevacuum.py so that "find my robot" in HASS performs an voice file upload an it worked like a charm. i had to genere .oog files in mono with 16000 Sample Rate an 56000 bitrate and vorbis encoding, so my F9 can play individual sounds.

fototeddy avatar Feb 26 '21 05:02 fototeddy

Hi everyone. Thx for you work. I'm trying to figure out how I can move the F9 to a specific zone. But I didn't achieve to get the command work with the miottemplate.py. Did someone know what are the siid and the aiid values to perform this action?

pedro2d10 avatar Mar 14 '21 12:03 pedro2d10

Yeah I managed to work out that command and it works pretty well. You can see how I implemented it in my repo.

    def zone_cleanup(self, coords) -> None:
        """Start zone cleaning."""
        payload = [{"piid": 1, "value": 19},{"piid": 10, "value": coords}]
        return self.call_action(4, 1, payload)   

microfrost1 avatar Mar 14 '21 17:03 microfrost1

I already check and integrated your work in my HA. Great job by the way. And Yes the zone cleanup is working great but what I'm trying to do is to tell the robot to just move forward and stop. My charging station is under a cabinet and I want to add a button to HA to move the robot forward so I can clean it.

I tried to get the informations needed but I don't manage to retrieve the Json file like describe

  • Find the type for the device you want to implement on here (for the F9, it's urn:miot-spec-v2:device:vacuum:0000A006:dreame-p2008:1)
  • python3 miottemplate.py download [device type], this will download a .json file containing all the definition for the F9's services, actions, properties, etc. You can either format it with a Notepad++ plugin and explore it, or do the next step to generate some pseudo-Python code
  • python3 miottemplate.py generate [downloaded file name] >> [whatever].py

pedro2d10 avatar Mar 14 '21 21:03 pedro2d10

@microfrost1 in this repo https://github.com/Concentricc/xiaomi_vacuum the dev manage to add a remote function

pedro2d10 avatar Mar 15 '21 06:03 pedro2d10

Hi @pedro2d10, I can only see the zone cleaning service in that repo. Am I missing it?

I actually have the same use case as mine charges under the bottom step of the stairs out of view. I've planned to incoporate the forward command in the remote. From the app it triggers the vacuum to reverse about 50cm and turn around which I hope would work for you. It should be quite simple to implement when I can find the time.

microfrost1 avatar Mar 16 '21 09:03 microfrost1

In the file custom_components/xiaomi_vacuum/miio/dreamevacuum.py line 348

`# siid 21: (remote): 2 props, 3 actions # aiid 1 start-remote: in: [1, 2] -> out: [] @command() def start_remote(self) -> None: """aiid 1 start-remote: in: [1, 2] -> out: []""" return self.call_action(21, 1)

# aiid 2 stop-remote: in: [] -> out: []
@command()
def stop_remote(self) -> None:
    """aiid 2 stop-remote: in: [] -> out: []"""
    return self.call_action(21, 2)

# aiid 3 exit-remote: in: [] -> out: []
@command()
def exit_remote(self) -> None:
    """aiid 3 exit-remote: in: [] -> out: []"""
    return self.call_action(21, 3)`

pedro2d10 avatar Mar 16 '21 09:03 pedro2d10

@pedro2d10 I see. I think those definitions were auto generated when using the miot spec converter. The complete calls would still need to be identified. In the case of our p2008 (https://miot-spec.org/miot-spec-v2/instance?type=urn:miot-spec-v2:device:vacuum:0000A006:dreame-p2008:1) the start-remote, stop-remote, exit-remote definitions aren't there so assuming local execution is fine, they need to be sniffed. It's something I've been meaning to spend some time on for a while.

microfrost1 avatar Mar 16 '21 18:03 microfrost1

remote for p2008 (set_properties to 4/15).

      _this.sendRemoteCtrl = function (touchId) {
        var v = 0;
        var wv = 0;

        if (touchId == 1) {
          v = 300;
          wv = 0;
        } else if (touchId == 2) {
          v = 0;
          wv = 120;
        } else if (touchId == 3) {
          v = 0;
          wv = -120;
        } else if (touchId == 0) {
          v = 0;
          wv = 0;
        } else {
          return;
        }

        var random = Math.floor(Math.random() * 1000);
        var params = {
          spdv: v,
          spdw: wv,
          audio: _this.audio,
          random: random
        };
        _this.audio = "false";

        if (!_this.isLocalNet) {
          _miot.Device.getDeviceWifi().callMethod("set_properties", [{
            "did": _miot.Device.deviceID,
            "siid": VacuumExtend.SIID,
            "piid": VacuumExtend.PIID.remoteState,
            "value": JSON.stringify(params)
          }]).then(function (res) {}).catch(function (err) {});
        } else {
          _miot.Device.getDeviceWifi().callMethodFromLocal("set_properties", [{
            "did": _miot.Device.deviceID,
            "siid": VacuumExtend.SIID,
            "piid": VacuumExtend.PIID.remoteState,
            "value": JSON.stringify(params)
          }]).then(function (res) {}).catch(function (err) {
            _this.isLocalNet = false;
          });
        }
      };

rezmus avatar Mar 16 '21 19:03 rezmus

@rezmus my understanting of this is we need to set the robot to propertie 4/15 so we can write the remote-state.

Did you know how this can be implemeted in the microfrost1's custom intergration?

pedro2d10 avatar Mar 17 '21 08:03 pedro2d10

@pedro2d10, I have commited what I'm testing locally which appears to work well although my robot has a different idea what 90 degrees is. I'll test further when I have more time.

@rezmus thanks for the info, saved me a fair bit of time! Is that code from a public integration that we can reference?

microfrost1 avatar Mar 17 '21 14:03 microfrost1

@microfrost1 You're the best! How did you call the service? I tried this but without any luck:

service: xiaomi_vacuum.vacuum_remote_control_move_step
data:
  entity_id: vacuum.thor
  velocity: 100
  rotation: 0

pedro2d10 avatar Mar 17 '21 14:03 pedro2d10

@microfrost1 code is from original f9 rn plugin from mi home ;)

rezmus avatar Mar 17 '21 14:03 rezmus

@microfrost1 You're the best! How did you call the service? I tried this but without any luck:

service: xiaomi_vacuum.vacuum_remote_control_move_step
data:
  entity_id: vacuum.thor
  velocity: 100
  rotation: 0

My fault, I rushed the commit. Confident it should work know however I haven't tested much.

microfrost1 avatar Mar 17 '21 16:03 microfrost1

guys, with a Dreame F9 here? i have issues that he sometimes starts 45° rotated, you guys seeing it too? making the cleanup taking 20 min longers, and sometimes he then needs to recharge :

image

Good start = https://www.dropbox.com/s/ctyoo25jzzry7ar/xiaomi.mp4?dl=0 Bad start = https://www.dropbox.com/s/zzp60vl69w83qya/xiaomi2.mp4?dl=0

On a good start, when I start cleaning, it goes back from the charging station, then rotates like 180° todo some calibration You can clearly see on the second video, it doesn’t rotate the full 180° , more like 135° instead, so that’s why he starts cleaning wrong, like 45° shifted

pergolafabio avatar Apr 07 '21 12:04 pergolafabio

guys, with a Dreame F9 here? i have issues that he sometimes starts 45° rotated, you guys seeing it too? making the cleanup taking 20 min longers, and sometimes he then needs to recharge :

image

Good start = https://www.dropbox.com/s/ctyoo25jzzry7ar/xiaomi.mp4?dl=0 Bad start = https://www.dropbox.com/s/zzp60vl69w83qya/xiaomi2.mp4?dl=0

On a good start, when I start cleaning, it goes back from the charging station, then rotates like 180° todo some calibration You can clearly see on the second video, it doesn’t rotate the full 180° , more like 135° instead, so that’s why he starts cleaning wrong, like 45° shifted

Hello! Actually my Dreame F9 cleanes at 45°, but I think it is because I put the base on a wall which is at 45°/135° with the other walls of my home... This doesn't seem your case. Anyway, I see that your map has the single rooms divided by colors (and letters). How did you manage to do so? The map of my whole apartment is identified as a single zone (A), with a single color and I don't know how to separate the single zones (kitchen, living room, bedroom, bathroom, ...). Thank you!

emaravi94 avatar Apr 18 '21 20:04 emaravi94

you need to turn on "map saving beta" feature, afterwards if you let it make a full clean for 3 times, it saves a map that you can edit then

pergolafabio avatar Apr 19 '21 06:04 pergolafabio

you need to turn on "map saving beta" feature, afterwards if you let it make a full clean for 3 times, it saves a map that you can edit then

Thank you. Yes, I activated the Map Saving feature. But I did only one full clean. This is my current situation: Screenshot_20210419-103611_Mi Home Anyway, when you say

it saves a map that you can edit then

you mean that afterwards, I will be able to see some funcionalities that let me separate rooms and adjust walls that the robot hasn't recognised? Thank you!

emaravi94 avatar Apr 19 '21 08:04 emaravi94

you need to click on ths button, then you can edit the map, it will also recogniez the rooms automaticly

image

pergolafabio avatar Apr 19 '21 09:04 pergolafabio

@pergolafabio Thank you. Actually, from that button I cannot separate rooms, but only:

  • add virtual walls or no-go zones
  • rename automatically recognized zones
  • reset the map Screenshot_20210419-111436_Mi Home I'd like to separate my big blue zone, into kitchen, living room, bathroom, ... My question is: will the AI of the robot recognize and separate the rooms after 3 full cleanings? If it fails, can I manually separate the rooms? Thank you again!

emaravi94 avatar Apr 19 '21 09:04 emaravi94

i cant seperate either, the app did it for me, i think it just recognized it for me automaticly :

image

pergolafabio avatar Apr 19 '21 09:04 pergolafabio

Maybe is a most stupid question but how to use a install_voice_pack? I have ready file en.tar.gz and modified dreamevacuum in my coustom component directory. But I don't know how to fire install_voice_pack command ? [edited] Ok did it. Manually added dreamevacuum.py to init.py and use miiocli dreamevacuum --ip 192.168.22.177 --token install_voice_pack. It works like a charm with Dreame bot L10 Pro

xury77 avatar May 16 '21 23:05 xury77

@microfrost1 and @pedro2d10 did you manage to move the robot from under the cabinet? I tried to call

service: xiaomi_vacuum.vacuum_remote_control_move_step
data:
  entity_id: vacuum.dreame_f9
  velocity: 100
  rotation: 90

but the robot doesn't move from the dock at all. normal commands work. (I'm using the microfrost1 repo in HACS)

PulsarFX avatar Feb 11 '22 11:02 PulsarFX

@PulsarFX Yes, it works from my side. Here the script I use

- service: xiaomi_vacuum.vacuum_remote_control_move_step data: entity_id: vacuum.thor velocity: 0 rotation: 0

pedro2d10 avatar Feb 11 '22 11:02 pedro2d10

Hm, that's the same I use. May it be because of this warning?

 [homeassistant.helpers.service] Unable to find services.yaml for the xiaomi_vacuum integration

edit: https://github.com/microfrost1/xiaomi_vacuum/issues/11

PulsarFX avatar Feb 11 '22 11:02 PulsarFX

I don't think so, I also have this error in my home assistance.

Did you tried with velocity and rotation at 0?

pedro2d10 avatar Feb 11 '22 11:02 pedro2d10

yes, doesn't move. What model is thor? with the services.yaml this is what I see: grafik

PulsarFX avatar Feb 11 '22 12:02 PulsarFX

with the latest firmware 3.5.8_1050 it actually does respond :)

note: for me 90° is 63.75 (64) which is 4 * 63.75 = 255 which is 1111 1111 for velocity 100 = 15cm slow (-100 reverse) 200 = 30cm fast 300 = 45cm max

PulsarFX avatar Feb 20 '22 12:02 PulsarFX