humbertogontijo / homeassistant-roborock

Roborock integration for Home Assistant. This integration uses your devices from the Roborock App
GNU General Public License v3.0
660 stars 69 forks source link

Feature Request: Routines #169

Open StaleLoafOfBread opened 1 year ago

StaleLoafOfBread commented 1 year ago

Although we can replicate the routine functionality via scripts / node red / automations, I would personally prefer to "load up" the routines onto the robot and start them via home assistant. I think this would also make it a bit more beginner friendly as well.

If anyone who knows how one might go about figuring out how to accomplish this wants to comment, I'll give it a shot. My current idea is to try to capture the traffic when using the native app. Though my previous efforts doing so to figure out local control did not go as planned so any insight is appreciated.

Xyaren commented 1 year ago

Sounds like a job for a HomeAssistant Script that can be called by multiple sources. Check out the docs: https://www.home-assistant.io/integrations/script/ On your Instance: https://my.home-assistant.io/redirect/scripts/

StaleLoafOfBread commented 1 year ago

I appreciate the info @Xyaren! That's how I am doing it today but I would prefer to be able to use the routines as there are slight differences:

  1. The pattern used when running multiple times in a row is different. Its cross hatch when a routine (well just any native way of telling it how many times)
  2. Allows me to use the native app or HA to tell it to do the same thing and its kept in sync
  3. When I use scripts it sometimes errors and although Im sure I could make it more robust, it would be more convient to just call a service like roborock.routine.
Lash-L commented 1 year ago

Hi @StaleLoafOfBread This would be possible - however, Routines are only available on some Roborocks. Unfortunately I don't have the functionality on mine, so this is not something I can reverse engineer.

if you are willing to go through the work of logging your network packets (relatively easy if you have a mac and iphone) - I can attempt to add this functionality. Otherwise, I have applied the help wanted label for now.

Brewery-GIT commented 1 year ago

Hi @StaleLoafOfBread This would be possible - however, Routines are only available on some Roborocks. Unfortunately I don't have the functionality on mine, so this is not something I can reverse engineer.

if you are willing to go through the work of logging your network packets (relatively easy if you have a mac and iphone) - I can attempt to add this functionality. Otherwise, I have applied the help wanted label for now.

Hi @Lash-L , I have a robo with routines, and can capture whatever you like. Let me know what I can provide.

Regressor commented 1 year ago

@Lash-L I have robo with routines and wish to help to implement this future. I'm a programmer and have an expierence with HA integrations.

humbertogontijo commented 1 year ago

Weird enough the robot only have a command to retrieve routine ids. The app stores the information about the scheduled time. Meaning that even if the integration creates one, when the app is opened and it doesn't recognize this new routine it will clear it. We could store the routine in HA, but this means that HA is the source of true, overriding anything done in the app. The command to create routines receives a cron, the fan speed and a command to execute (So far I only seem "start_clean"). I can't even relate this to HA entities (calendar could be the closest one, but it would require the description to be well formatted to receive the fan speed)

Regressor commented 1 year ago

I need an ability to load routines and execute them. Example: I created a routine to make 2 pass - first to clean and second to mop with special options for rooms. I want to be able to get list with ids and to start them via HA service.

humbertogontijo commented 1 year ago

@Regressor Correct if I'm wrong, but there is no such thing in the app. Just schedules. You can set it to clean predefined rooms, but not the number of cleanings and not immediately (it's scheduled). It is achievable with HA automations though

Regressor commented 1 year ago

No. Routines is a sequence of operations/jobs. Every job can be set to clean or mop with separate settings (like number of cleanings, intensivity and other). Jobs are running one by one. Routine can be set to run by timer.

The main problem with HA automations is a need to setup all clean/mop parameters and rooms by hands and to run multiple jobs I need to write some code/config to detect each job ending time. With routines I can setup all parameters in application and then just run routine from HA using voice assistant ("please clean kitchen" or "do full clean").

humbertogontijo commented 1 year ago

@Regressor I managed to intercept some commands from my app, but I think those are only for creating a task. Maybe this created task is linked to a routine using mqtt

Regressor commented 1 year ago

@Regressor I managed to intercept some commands from my app, but I think those are only for creating a task. Maybe this created task is linked to a routine using mqtt

How do you intercept commands ? I can try to inspect my application

humbertogontijo commented 1 year ago

You'll need a mac and an iPhone Using cli from https://github.com/humbertogontijo/python-roborock with parameters parser --device_ip <device_ip> --local_key <local_key> You can get the local key from the logs or from /config/.storage/core.config_entries file Then run "rvictl -s XXXXXXXX-XXXXXXXXXXXXXXXX" with your phone connected with a USB cable to your mac, replacing XXX...XXX with your phone ID

Lash-L commented 1 year ago

Someone was able to get it to work for them on Windows, but I can't remember who or for what issue. If you don't have a mac/iphone, let us know and I can try to find the comment from them

Regressor commented 1 year ago

Someone was able to get it to work for them on Windows, but I can't remember who or for what issue. If you don't have a mac/iphone, let us know and I can try to find the comment from them

Yes. I don't have iphone && mac.

Lash-L commented 1 year ago

Check here https://github.com/humbertogontijo/homeassistant-roborock/issues/298

And/or @PyRowMan can give some insight into what he did

Regressor commented 1 year ago

Check here #298 Thank you. I'll try to use this.

PyRowMan commented 1 year ago

Hi There, sorry for the long time to reply,

@Regressor You can block roborock dns with adblock dns and then use PCAPDroid to intercept the outgoing PCAP from roborock app :)

StaleLoafOfBread commented 1 year ago

@PyRowMan Did you need to use the rooted version? I tried that method at first and was not able to get it to communicate to the robot. I assume its because the VPN forces it to be another subnet.

StaleLoafOfBread commented 1 year ago

@PyRowMan @humbertogontijo I finally rooted my phone but now when I block the DNS or unplug my modem, the app doesn't work at all. Can you confirm that you are still able to get the app working in local mode?

StaleLoafOfBread commented 1 year ago

I changed my DNS blocking from

*.roborock.com
*.xiaomi.com

to just mqtt-us-2.roborock.com

but I suspect this is not working as expected. Here is what the parser shows image

Regressor commented 1 year ago

Hi There, sorry for the long time to reply,

@Regressor You can block roborock dns with adblock dns and then use PCAPDroid to intercept the outgoing PCAP from roborock app :)

Sorry for long delay. I was in business trip :( I created an emulator android device (android studio native one) and installed roborock app, pcapdroid and adblock. But. roborock app use TLS connections and don't trust external CA certificates, so pcapdroid can't decode tls.

StaleLoafOfBread commented 1 year ago

Sorry for long delay. I was in business trip :( I created an emulator android device (android studio native one) and installed roborock app, pcapdroid and adblock. But. roborock app use TLS connections and don't trust external CA certificates, so pcapdroid can't decode tls.

No worries. With pcapandroid you can use a MITM cert to decode it though, can't you? I know it has the feature but this is the first I've tried using this app or doing this sort of work with android apps.

What did you block with adbock?

Regressor commented 1 year ago

MITM doesn't work with roborock app. I can use MITM with Chrome - and it work and TLS session dumped decoded, but roborock just don't trust pcapdroid CA:

image

About adblock. I didn't use it. I just can't find "adblock dns" app that can block dns. Play market on "adblock dns" shows many apps: ADGuard, Purple DNS, Wize Adblock VPN, FAB Adblocker browser, Adblock browser, Adguard vpn and there is no "adblock dns" app.

But why blocking dns can solve tls problem ?

I'm using android 14 emulator image. It has some issues with CA certs. I'll try to install android 10 to check mitm

StaleLoafOfBread commented 1 year ago

@Regressor My goal here is to capture the local traffic when the app starts a routine. It was my understanding the way to get it to start talking local was to block certain dns queries. I see now from rereading the thread that it was @PyRowMan who got it to work on Android.

Regressor commented 1 year ago

I think pcap droid installs vpn with non-local address and this can prevent roborock app send local traffic. But I'll try this when find adblock app.

Can I disable internet for roborock app and capture app <-> robot traffic on mikrotik router ?

StaleLoafOfBread commented 1 year ago

I think pcap droid installs vpn with non-local address and this can prevent roborock app send local traffic. But I'll try this when find adblock app.

It does unless you are using the rooted version.

Can I disable internet for roborock app and capture app <-> robot traffic on mikrotik router ?

I am unfamiliar with that router brand but thats the general idea. However, I was having issues with that, which is why I was asking what dns blocking help worked.

Regressor commented 1 year ago

It does unless you are using the rooted version.

Oh. It does matter.

I am unfamiliar with that router brand but thats the general idea. However, I was having issues with that, which is why I was asking what dns blocking help worked.

First try failed. I was able to setup local robot traffic capture (mikrotik TZSP streaming to pc with wireshark). Also I added firewall rule to block internet for roborock app phone. And there is no any local traffic at all (app loaded, shows saved routines and shows error when I try to start one of them). I can see only udp broadcast traffic from robot's ip

StaleLoafOfBread commented 1 year ago

That's roughly the results I saw. I can't remember the exact details anymore. I was hoping someone who successfully captured the data could share their technique.

Regressor commented 1 year ago

Ok. Second try was successfull, but it looks like this technique will not help:

  1. I opened roborock application and touched "Enter" button.
  2. After loading map I disabled internet for phone on router
  3. Then I setup a packet sniffer streaming on wifi router to computer with wireshark running
  4. Then I can start/stop cleaning, changing options and local traffic is captured

But there is a problem - Routines are placed under "Enter" button and they don't work without internet. I think routines are cloud only option and only way to intercept and decode traffic is to decompile and change roborock app.

StaleLoafOfBread commented 1 year ago

Looks like @humbertogontijo had some sort of success with the routines though he was creating routines where my (our?) goal is to just start the routines we made in app.

I'll have to test if I can get routines working offline later as I can't remember. I thought I did but based off what you just said, I must be misremembering. I don't have a good way to do that right now without killing internet for all devices which just isn't an option right now.

Regressor commented 1 year ago

Looks like @humbertogontijo had some sort of success with the routines though he was creating routines where my (our?) goal is to just start the routines we made in app.

Yes. My goal is to be able to run routines. I like the way I can create them from app and want to run routines with voice assistant.

P. S. I'll try to check if multitask routine can be started with internet enabled and finished with internet disabled after start. If this is cloud only future robot will stop after first task

Regressor commented 12 months ago

It's a shame, but apparently the routines function is completely cloud-based. I ran a routine consisting of two tasks (vacuum and then wash) and immediately after that I turned off the Internet for the robot. The vacuum cleaner completed the first task, docked and did not complete the second part even after turning on the Internet.

I'll try to make an automation for this in HA without routines...