Python plugin: Xiaomi Mi Robot Vacuum Topic is solved

Python and python framework

Moderator: leecollings

snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by snellejellep »

Well i run a beta version and did everything sudo, i will try your steps this evening

Verstuurd vanaf mijn SM-G935F met Tapatalk

raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
Andyf66
Posts: 44
Joined: Wednesday 13 June 2018 12:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by Andyf66 »

As other people have asked previously.. Will the plugin ever work with multiple devices? I have two of these, one upstairs and one down. Would be ideal to be able to control both.

In theory, is it as simple as running multiple copies of miio_server.py, configured for different ports, pidfile, and different vacuum token/IP address?
Andyf66
Posts: 44
Joined: Wednesday 13 June 2018 12:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by Andyf66 »

In answer to my own question... It appears to work if you run multiple copies of miio_server.py on different ports, something like this

sudo ./miio_server.py 192.168.200.240 abcd677338476464436459486a6a4e6f --host 127.0.0.1 --port 22222
sudo ./miio_server.py 192.168.200.241 1234677338476464436459486a6aabcd --host 127.0.0.1 --port 22223

You can then add two separate hardware devices to Domoticz

All I need to do now is wrap it up into the services startup script.

[Edit]

And that turns out to be quite easy if you ignore the supplied startup script and use a templated 'systemd' startup instead. If anybody is interested please let me know.

Two Miio Vacs working inside Domoticz now, V1 and a V2.
Quax1507
Posts: 101
Joined: Tuesday 07 April 2015 21:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by Quax1507 »

@Andyf66: I am interested in Your script! Would be happy if You share it with me!
Andyf66
Posts: 44
Joined: Wednesday 13 June 2018 12:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by Andyf66 »

OK, so here goes. This is a very high level description of what I did, feel free to ask questions. Its running on a Pi, but may well be applicable to other systems.

I'm not using miio_server.sh at all, I replaced it with a templated systemd unit. This file lives in /etc/systemd/system and should be chmod 664 It is called [email protected] and contains

Code: Select all

[Unit]
Description=Xiaomi Mi Robovac service - %i
After=network.target

[Service]
PrivateTmp=true
Type=service
EnvironmentFile=/etc/systemd/user/%i
ExecStart=/home/pi/domoticz/plugins/xiaomi-mirobot/miio_server.py $RUN_OPTS

[Install]
WantedBy=multi-user.target
For each vacuum you want to control you will so need a config file. These live in /etc/systemd/user. I have two, xiaomi-downstairs-vac and xiaomi-upstairs-vac

they contain the following - You will need to alter the IP addresses and tokens of the vacuums as appropriate.

xiaomi-upstairs-vac contains

Code: Select all

RUN_OPTS=192.168.200.241 64323768344f3041234a7254784d6145 --host 127.0.0.1 --port 22222
xiaomi-downstairs-vac contains

Code: Select all

RUN_OPTS=192.168.200.240 4764677338476464578459486a6a4e6f --host 127.0.0.1 --port 22223
Note the increasing port numbers. If you want a 3rd vacuum it would be at port 22224
Last edited by Andyf66 on Tuesday 19 June 2018 15:53, edited 1 time in total.
Andyf66
Posts: 44
Joined: Wednesday 13 June 2018 12:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by Andyf66 »

You now need to instantiate your services...

Code: Select all

sudo systemctl daemon-reload

Code: Select all

sudo systemctl start [email protected]
sudo systemctl start [email protected]
This will create and start two services, for two vacuums. Note the text between the '@' and '.service' must match the configuration file names created in /etc/systemd/user

To check if your services have started correctly, use the systemctl status cmd

Code: Select all

systemctl status [email protected]
Using the service names as created previously.

Good luck!
Last edited by Andyf66 on Sunday 01 July 2018 15:58, edited 1 time in total.
Andyf66
Posts: 44
Joined: Wednesday 13 June 2018 12:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by Andyf66 »

You can then add the Xiaomi Hardware into Domoticz. You create a single device per vacuum, making sure to use the correct incrementing port numbers as defined by your service unit configs.
Quax1507
Posts: 101
Joined: Tuesday 07 April 2015 21:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by Quax1507 »

Thank You very much!
I just changed my first vacuum to Your method successfully.
Second one will be here in a few days...
Andyf66
Posts: 44
Joined: Wednesday 13 June 2018 12:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by Andyf66 »

Glad to help and that my instructions were clear enough.

Andy.
satanasinc
Posts: 41
Joined: Monday 19 October 2015 12:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Location: Spain
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by satanasinc »

Hi!

First of all excuse my bad english.

Great python plugin it works like a charm! Thank you dude.

Someone can control the vacuum from the telegram bot with dtgmenu?

I get this error in telegram:
M-O_-_Control -
command <M-O_-_Control> not found

I find no way to use the "Control selector" from telegram. Please someone can help me.

Thanks in advance and regards.
Quax1507
Posts: 101
Joined: Tuesday 07 April 2015 21:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by Quax1507 »

Second robot arrived and integrated successfully!

Thank You again!
dlefol
Posts: 35
Joined: Monday 21 December 2015 16:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by dlefol »

Hello,

I've been trying to install this plugin for a while now and cannot make it work. I've tried to install and reinstall several times in case it was the problem but I always have the same problems.

First during the install process I have a problem building the "cryptography" dependency. I manage to solve that using google and this link (I'm on raspberry pi).

Once installed, I then have an error when running the miio_server:

Code: Select all

  File "./miio_server.py", line 17, in <module>
    from miio import Vacuum, DeviceException
  File "././.env/lib/python3.4/site-packages/miio/__init__.py", line 2, in <module>
    from miio.protocol import Message, Utils
  File "././.env/lib/python3.4/site-packages/miio/protocol.py", line 155, in <module>
    Const(Int16ub, 0x2131),
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 2619, in __init__
    super(Const, self).__init__(subcon)
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 666, in __init__
    raise TypeError("subcon should be a Construct field")
TypeError: subcon should be a Construct field
I manage to solve that again by editing the file protocol.py as detailed in a post from the homeassistant forum (link)

After that the server is running fine, but when I launch test.py I have the following error:

Code: Select all

sudo ./test.py
test: python modules path: ././.env/lib/python3.4/site-packages
test: trying connect to 127.0.0.1:22222
server: connected ('127.0.0.1', 58282)
server: got socket msg: ['status']
test: sent request to server [status]
test: reading response...
error while reading discover results: _decode() takes 3 positional arguments but 4 were given
Unable to discover a device at address xxx.xxx.xx.xxx (adresse IP edited out for the forum)
server: vac result {'cmd': 'status', 'exception': 'python-miio: Unable to discover the device xxx.xxx.xx.xx'}
server: send reply ('127.0.0.1', 58282)
test: got server reply {'exception': 'python-miio: Unable to discover the device xxx.xxx.xx.xx', 'cmd': 'status'}
server: closed connection ('127.0.0.1', 58282)
And then I don't know what to do.

I know the token and communication with the vacuum cleaner works fine because if I use the "mirobo" command directly I can get the status of the robot, start it, stop it and so on. The problem therefore seems to be with the wrapper from the plugin.

If anyone has an idea, I'm all ears. I've been pulling my hairs on this one for a while!

Cheers
nizaga
Posts: 69
Joined: Monday 30 November 2015 11:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by nizaga »

Hi,

I have integrated the Xiaomi Mi Robot Vacuum 2 (the Roborock) into Domoticz via Jeedom.

This is the tutorial: https://vdays.net/en/2017/09/28/tuto-je ... ot-vacuum/

You need to install jeedom in RPI and pay 6€ for the xiaomi plugin.

Some might think it is not necessary, but in my case i have several items integrated in domoticz performing https calls to jeedom (some plugins are really good, like the broadlink ecosystem). My main HA System is of course omoticz, but some integration is much easier via jeedom plugins.

Regards,

Nim
Gytis
Posts: 2
Joined: Friday 20 July 2018 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by Gytis »

What is the port that miio_server uses to connect to the roborock vacuum cleaner?

In my case Domoticz and Roborock vacuum are on different subnets therefore I need to do port forward for Domoticz to access vacuum :roll:
Stimpy68
Posts: 40
Joined: Wednesday 09 May 2018 16:37
Target OS: Linux
Domoticz version:
Location: The Hague, The Netherlands
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by Stimpy68 »

Is there anyway to use the "spot" function? There is a button in Domoticz, but when I push it, the vacuum says that I have to place the vacuum in the target area. Usually you draw the target area in the map with the app and start the zoned cleanup.
The protocol had the command for it: https://github.com/marcelrv/XiaomiRobot ... d_clean.md

Would be nice to incorperate that in the plugin, also the "mop" option would be nice to have.
Stimpy68
Posts: 40
Joined: Wednesday 09 May 2018 16:37
Target OS: Linux
Domoticz version:
Location: The Hague, The Netherlands
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by Stimpy68 »

Gytis wrote: Tuesday 24 July 2018 17:00 What is the port that miio_server uses to connect to the roborock vacuum cleaner?

In my case Domoticz and Roborock vacuum are on different subnets therefore I need to do port forward for Domoticz to access vacuum :roll:

Code: Select all

# file miio_server.sh
DAEMON_USER=root
DAEMON=/home/pi/domoticz/plugins/xiaomi-mirobot/miio_server.py
DAEMON_ARGS="192.168.1.12 476e6b70343055483230644c53707a12"
DAEMON_ARGS="$DAEMON_ARGS --host 127.0.0.1 --port 22222"
#
Port 22222 ;)
Prutsium
Posts: 92
Joined: Monday 18 June 2018 11:31
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Germany / Netherlands
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by Prutsium »

Would this plugin also work with the 360 S6? Not sure anyone recieved it already but i am considering to buy the 360 S6 and it looks like a OEM/ODM of the Mi.
Philos31
Posts: 33
Joined: Friday 15 August 2014 22:37
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by Philos31 »

Is there someone who has this plugin working in domoticz on Synology Nas?
I have tried but am missing to many things, maybe someone could help?
RasPi2/KaKu/HUE/Xiaomi/Z-Wave/Nuki/Daikin 3,5kw Ururu Sarara/IR Heating Panels all working together with domoticz
dagasoft
Posts: 27
Joined: Thursday 03 December 2015 14:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by dagasoft »

I've successfully installed the plugin and it's working great.

Do you know if there is a way to get dust bin status when it's full? It would be great to send notifications when you need to clean it.
dlefol
Posts: 35
Joined: Monday 21 December 2015 16:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by dlefol »

As far as I know there is no sensor in the dustbin of the vacuum cleaner so it s not possible to get the information of how full the dustbin is.
Post Reply

Who is online

Users browsing this forum: Amazon [Bot] and 1 guest