Python plugin: Xiaomi Mi Robot Vacuum Topic is solved

Python and python framework
snellejellep
Posts: 116
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi
Domoticz version: 3.97xx
Location: The Neterlands
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by snellejellep » Saturday 16 June 2018 15:42

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 gateway/vacuum | yeelight | philips hue | zwave |ubiquiti unifi | harmony

Andyf66
Posts: 49
Joined: Wednesday 13 June 2018 12:13
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by Andyf66 » Sunday 17 June 2018 23:01

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: 49
Joined: Wednesday 13 June 2018 12:13
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by Andyf66 » Monday 18 June 2018 13:33

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: 124
Joined: Tuesday 07 April 2015 21:29
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by Quax1507 » Tuesday 19 June 2018 11:22

@Andyf66: I am interested in Your script! Would be happy if You share it with me!

Andyf66
Posts: 49
Joined: Wednesday 13 June 2018 12:13
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by Andyf66 » Tuesday 19 June 2018 15:44

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 robovac@.service 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: 49
Joined: Wednesday 13 June 2018 12:13
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by Andyf66 » Tuesday 19 June 2018 15:52

You now need to instantiate your services...

Code: Select all

sudo systemctl daemon-reload

Code: Select all

sudo systemctl start robovac@xiaomi-upstairs-vac.service
sudo systemctl start robovac@xiaomi-downstairs-vac.service
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 robovac@xiaomi-upstairs-vac.service
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: 49
Joined: Wednesday 13 June 2018 12:13
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by Andyf66 » Tuesday 19 June 2018 16:07

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: 124
Joined: Tuesday 07 April 2015 21:29
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by Quax1507 » Wednesday 20 June 2018 9:50

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: 49
Joined: Wednesday 13 June 2018 12:13
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by Andyf66 » Wednesday 20 June 2018 12:08

Glad to help and that my instructions were clear enough.

Andy.

satanasinc
Posts: 30
Joined: Monday 19 October 2015 12:15
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by satanasinc » Friday 22 June 2018 13:18

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: 124
Joined: Tuesday 07 April 2015 21:29
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by Quax1507 » Monday 25 June 2018 21:34

Second robot arrived and integrated successfully!

Thank You again!

dlefol
Posts: 47
Joined: Monday 21 December 2015 17:35
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by dlefol » Wednesday 04 July 2018 20:32

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: 110
Joined: Monday 30 November 2015 12:36
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by nizaga » Wednesday 11 July 2018 21:44

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: 1
Joined: Friday 20 July 2018 11:02
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by Gytis » 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:

Stimpy68
Posts: 6
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 » Saturday 11 August 2018 13:22

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: 6
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 » Saturday 11 August 2018 19:36

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: 56
Joined: Monday 18 June 2018 11:31
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Germany / Netherlands
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by Prutsium » Sunday 12 August 2018 11:37

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: 54
Joined: Friday 15 August 2014 22:37
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by Philos31 » Monday 13 August 2018 12:23

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: 15
Joined: Thursday 03 December 2015 15:11
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by dagasoft » Monday 27 August 2018 9:45

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: 47
Joined: Monday 21 December 2015 17:35
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by dlefol » Monday 27 August 2018 11:40

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: No registered users and 8 guests