Page 8 of 16
Re: Python plugin: Xiaomi Mi Robot Vacuum
Posted: Monday 21 May 2018 19:33
by gijsje
I do have the problem the vacuum gets stuck under the couch.
There is this
magnetic tape to prevent the vacuum to go over it when you put it on the floor.
Does anyone know if it would also work if you stick it underneath the couch?
Re: Python plugin: Xiaomi Mi Robot Vacuum
Posted: Wednesday 23 May 2018 22:40
by RichardBokker
molnaratti wrote: ↑Friday 11 May 2018 22:01
RichardBokker wrote: ↑Wednesday 14 February 2018 10:37
I got the script working, but had to convert the Robot - state with tostring().
Here is my case-construction that i'm using.
Code: Select all
-- Using TimeBetween script in main LUA script folder
package.path = package.path .. ';' .. '/home/pi/domoticz/scripts/lua/script_time_TimeBetween.lua'
local TimeBetween = require('timebetween')
time = os.date("*t")
commandArray = {}
-- Possible state's of Robot Vacuum: Charging / Paused / Cleaning / Waiting / Back to home / Sleeping
-- Selector witch Robot Vacuum: Clean(10) / Home(20) / Spot(30) / Pauze(40) / Stop(50) / Find(60)
---- Variabele to use
-- StoffieState (uservariable)
-- AtHome (uservariable)
-- Stoffie - Control (device)
-- Stoffie - Status (device)
local stoffie = 'Stoffie - Status'
-- print(otherdevices_svalues[stoffie] .. " dit is de actuele status")
-- Required to convert State to Stringvalue
StoffieStatus = tostring(otherdevices_svalues[stoffie]);
-- IDLE
if (uservariables['StoffieState'] == 'IDLE') then
print ("Stoffie is idle");
if timebetween("08:00","16:00") then -- Run's only during day hours.
if (uservariables['AtHome'] == 'NO') then -- Run's only when nobody is at home
commandArray['SendNotification']='Stoffie is Starting'
commandArray['Variable:StoffieState']='STARTING'
-- Start Robot command, command send once.
commandArray['Stoffie - Control'] = 'Set Level 10'
end
end
end
-- STARTING
if (uservariables['StoffieState'] == 'STARTING') then
if StoffieStatus == 'Cleaning' then -- If robot is cleaning, continu to next step
commandArray['SendNotification']='Stoffie is Running'
commandArray['Variable:StoffieState']='RUNNING'
end
if timebetween("16:00","08:00") then -- is program hangs, to executed state
commandArray['Variable:StoffieState']='EXECUTED'
end
end
-- RUNNING
if (uservariables['StoffieState'] == 'RUNNING') then
if StoffieStatus == 'Back to home' then -- If robot is going back to home, continu to next step
commandArray['SendNotification']='Stoffie is Stopping'
commandArray['Variable:StoffieState']='STOPPING'
end
end
-- STOPPING
if (uservariables['StoffieState'] == 'STOPPING') then
if StoffieStatus == 'Charging' then -- if robot is Charging, continu to next step
commandArray['SendNotification']='Stoffie is Executed'
commandArray['Variable:StoffieState']='EXECUTED'
-- Stop Robot command, command send once.
commandArray['Stoffie - Control'] = 'Set Level 50'
end
end
-- EXECUTED
if (uservariables['StoffieState'] == 'EXECUTED') then
if timebetween("23:55","23:56") then -- Runs only once a day. Reset at end of day.
commandArray['SendNotification']='Stoffie going to Idle'
commandArray['Variable:StoffieState']='IDLE'
end
end
return commandArray
Very good, thanks. You would share the time between.lua script?
Hmm.. it should be on the forum somewhere. Is you search with time between. Cannot answer now with code, on vacation

Re: Python plugin: Xiaomi Mi Robot Vacuum
Posted: Thursday 24 May 2018 19:50
by Geitje
Dont know, just try it I would say...
gijsje wrote: ↑Monday 21 May 2018 19:33
I do have the problem the vacuum gets stuck under the couch.
There is this
magnetic tape to prevent the vacuum to go over it when you put it on the floor.
Does anyone know if it would also work if you stick it underneath the couch?
Re: Python plugin: Xiaomi Mi Robot Vacuum
Posted: Thursday 24 May 2018 21:18
by l00pz
gijsje wrote: ↑Monday 21 May 2018 19:33
I do have the problem the vacuum gets stuck under the couch.
There is this
magnetic tape to prevent the vacuum to go over it when you put it on the floor.
Does anyone know if it would also work if you stick it underneath the couch?
I use the magnetic tape to stop the Xiaomi Mi Robot from getting stuck on the coffee table, and can confirm this works good. The Xiaomi Mi Robot slightly crosses the tape, and then returns.
Re: Python plugin: Xiaomi Mi Robot Vacuum
Posted: Thursday 24 May 2018 22:23
by gijsje
Thanks for that i will order some
Re: Python plugin: Xiaomi Mi Robot Vacuum
Posted: Saturday 02 June 2018 15:09
by Jheronymus
Jheronymus wrote: ↑Thursday 17 May 2018 16:56
Geitje wrote: ↑Tuesday 06 March 2018 1:29
I already found out.
See this post:
http://www.domoticz.com/forum/viewtopic ... ck#p163889.
Note: insert:
sys.path.append('/usr/local/lib/python3.5/site-packages')
after "import domoticz" in the plugin.py file.
so WITHOUT the
and /b codes mentioned in the post, if you insert them too it does nog work I found out!
Hi, I have a similar problem, but the solution didn't work for me.
When I try to add the line, domoticz won't boot (ie. the browser keeps indicating domoticz is offline or not available)
The error in the domoticz log (without the line)
Code: Select all
Error: (xiaomi-mi-robot-vacuum) failed to load 'plugin.py', Python Path used was '/home/jeroen/domoticz/plugins/xiaomi-robot/:/usr/lib/python3.4/:/usr/lib/python3.4/plat-arm-linux-gnueabihf:/usr/lib/python3.4/lib-dynload'.
Error: (Robottest) Module Import failed, exception: 'ImportError'
Error: (Robottest) Module Import failed: ' Name: msgpack'
I've added this:
Code: Select all
sys.path.append('/usr/local/lib/python3.4/dist-packages')
FYI:
I get this response for searching for msgpack:
Code: Select all
jeroen@Domoticz:~ $ sudo find / -name msgpack*
[sudo] password for jeroen:
/home/jeroen/domoticz/plugins/xiaomi-robot/.env/lib/python3.4/site-packages/pip/_vendor/msgpack
/home/jeroen/.cache/pip/wheels/62/f3/0d/f77f20fce259496b053d6c0dc0eea7114527cf0a7da115a980/msgpack_python-0.4.8-cp34-cp34m-linux_armv6l.whl
/usr/local/lib/python3.4/dist-packages/msgpack_python-0.4.8-py3.4.egg-info
/usr/local/lib/python3.4/dist-packages/msgpack
I've no idea how to debug this at this point. When I run the test script:
jeroen@Domoticz:~/domoticz/plugins/xiaomi-robot $ sudo ./test.py
test: python modules path: ././.env/lib/python3.4/site-packages
test: trying connect to 127.0.0.1:22222
Traceback (most recent call last):
File "./test.py", line 22, in <module>
client = socket.create_connection((args.host, args.port))
File "/usr/lib/python3.4/socket.py", line 509, in create_connection
raise err
File "/usr/lib/python3.4/socket.py", line 500, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
jeroen@Domoticz:~/domoticz/plugins/xiaomi-robot $
But if I start the server from the command line and run the test.py from another console, I can get valid output.
sudo python3 miio_server.py 192.168.1.43 token
server: Starting server on 127.0.0.1 22222
server: connected ('127.0.0.1', 42656)
server: got socket msg: ['status']
server: vac result {'clean_area': 62.4725, 'error': None, 'battery': 100, 'cmd': 'status', 'state_code': 8, 'clean_seconds': 4418, 'fan_level': 60}
server: send reply ('127.0.0.1', 42656)
server: closed connection ('127.0.0.1', 42656)
So, I fixed my earlier problem. I noticed I was using sudo a lot. And you have to be carefull with that while in the virtualenv. As you can see in the logs posted before, the msgpack was installed, but outside the virtual env. /usr/local/lib/python3.4/dist-packages/msgpack
You can test it like this:
Code: Select all
> which python
/usr/bin/python
> which pip3
/usr/bin/pip3
>source .env/bin/activate
>which python3
/home/jeroen/domoticz/plugins/xiaomi-mirobot/.env/bin/python3
>which pip3
/home/jeroen/domoticz/plugins/xiaomi-mirobot/.env/bin/pip3
>sudo which pip3
/usr/bin/pip3 <= sudo points outside the virtualenv
You might also upgrade setuptools in the virtualenv.
then just run the pip3 install -r pip_req.txt command
All should be fine. Close the virtualenv with
Now you can actualy see the packages in the virtualenv:
Code: Select all
>~/domoticz/plugins/xiaomi-mirobot/.env/lib/python3.5/site-packages $ ls
Crypto msgpack
__pycache__ msgpack_python-0.4.8.dist-info
_cffi_backend.cpython-35m-arm-linux-gnueabihf.so netifaces-0.10.6.dist-info
android_backup netifaces.cpython-35m-arm-linux-gnueabihf.so
android_backup-0.1.0.dist-info pip
asn1crypto pip-10.0.1.dist-info
asn1crypto-0.23.0.dist-info pkg_resources
attr pretty_cron
attrs-17.2.0.dist-info pretty_cron-1.0.2.dist-info
cffi psutil
cffi-1.11.2.dist-info psutil-5.4.5.dist-info
click pycparser
click-6.7.dist-info pycparser-2.18.dist-info
construct pycrypto-2.6.1.dist-info
construct-2.8.16.dist-info python_miio-0.3.1.dist-info
cryptography pytz
cryptography-2.1.3.dist-info pytz-2017.3.dist-info
easy_install.py setuptools
enum_compat-0.0.2.dist-info setuptools-39.2.0.dist-info
gevent six-1.11.0.dist-info
gevent-1.2.2.dist-info six.py
greenlet-0.4.12.dist-info typing-3.6.2.dist-info
greenlet.cpython-35m-arm-linux-gnueabihf.so typing.py
idna wheel
idna-2.6.dist-info wheel-0.31.1.dist-info
miio zeroconf-0.19.1.dist-info
mirobo zeroconf.py
Re: Python plugin: Xiaomi Mi Robot Vacuum
Posted: Saturday 02 June 2018 15:29
by Jheronymus
So now I've added the plugin and it is running. NO errors in the log.
I can add the Xiaomi Mi Robot Vacuum hardware (name: PoetsBot, fan level: slider, debug: true)
I can see the devices, but when I add them, the 'control ones' don't appear.
How do I have to set these up?
Under utility I can see:
- Battery
- Care Main Brush
- Care Side Brush
- Care Sensors
- Care Filter
They all show a reasonable percentage.
Under switches I only see
If I click the robot icon, the robot will start cleaning. Clicking it again sends it back home. So it all works.
How do I set this up that I can have the controls for the mode and the fan level?
Re: Python plugin: Xiaomi Mi Robot Vacuum
Posted: Sunday 03 June 2018 23:15
by frenchyyii
corederoma82 wrote: ↑Wednesday 16 May 2018 11:16
corederoma82 wrote: ↑Friday 11 May 2018 9:39
Hi,
can you say me how are the compatible vacuum cleaner model?
Thanks
Somebody can answer me?
Thanks
Roborock S50 is ok if it's the question
And S50 as a "MOP" mode but it's not available with the plugin. I'm trying to get the command line for MOP but can't find it.
Re: Python plugin: Xiaomi Mi Robot Vacuum
Posted: Sunday 03 June 2018 23:32
by frenchyyii
oups.... a new question while speaking about this fantastic plugin. What is the way to add a second robot ?
Regards
Eric
Re: Python plugin: Xiaomi Mi Robot Vacuum
Posted: Monday 04 June 2018 11:35
by snellejellep
i may be a complete idiot but i can not seem to get the token of my little friend in any possible way, i tried almost every guide i could find on the interwebz but no luck for me unfortunately. maby someone overhere can help me as i read some of you have had success so a little help is welcome...
Re: Python plugin: Xiaomi Mi Robot Vacuum
Posted: Wednesday 06 June 2018 20:34
by Jheronymus
snellejellep wrote: ↑Monday 04 June 2018 11:35
i may be a complete idiot but i can not seem to get the token of my little friend in any possible way, i tried almost every guide i could find on the interwebz but no luck for me unfortunately. maby someone overhere can help me as i read some of you have had success so a little help is welcome...
Hi SnelleJelleP,
I've experienced some challenges for getting my token. I've retraced my steps as far as possible. Let us know at what point you get stuck.
I performmed everything on my personal Android phone (Sony Z3 compact, non rooted) and a Windows 10 64bit laptop.
I did tried it first at my workphone (Samsung S7) but failed because company policies forced encrypted backups.
1) I started clicking at the link
https://github.com/mrin/domoticz-mirobo ... vice-token
and ended up here
2)
https://github.com/jghaanstra/com.xiaom ... oid-phones
After a try I couldn't find the token in the database I got. So I ended up installing an old version that I got from apkmirror.
https://apkdot.com/apk/xiaomi-inc/mihome/mihome-5-0-0/
(do this at your own risk, I thought I got it here, not sure. The file I used is called: com.xiaomi.smarthome-5.0.0-60690_minAPI14(armeabi-v7a)(nodpi)_apkmirror.com.apk)
Installed it, don't upgrade. Get your robot back in there.
3) Use adb tool to make the backup
In powershell something like:
>.\adb backup -noapk com.xiaomi.smarthome -f backupsony.ab
Your phone should be usb connected and in developer mode. The erros for adb are quite usefull, so read carefully them if you fail here.
4) install the adbextractor (see article for link)
(at this point you also need your java paths to be correct, which I didn't, so here's a rather weird command)
>'C:\Program Files\Java\jdk1.8.0_161\bin\java.exe' -jar ../android-backup-extractor/abe.jar unpack backupsony.ab backupsony.tar
5) unzip the tar with 7-zip
6) install sqlitebrowser (I used the portable one)
Open the miio2.db and query the database.
I just did select * from devicrecord, it only had one record and the column token is in there somewhere (at the end in my case)
Let us know where you get stuck.
Hope that helps.
Re: Python plugin: Xiaomi Mi Robot Vacuum
Posted: Wednesday 06 June 2018 21:44
by snellejellep
@jheronymus, thankyou for your explanation, i got a token this time, only i think i did something wrong because my robot does not seem to react and i do not get any error messages. so i am kinda stuck because i can not give you any kind of information to help me troubleshoot
Re: Python plugin: Xiaomi Mi Robot Vacuum
Posted: Friday 08 June 2018 16:14
by snellejellep
i do get weird messages in the log and it does not work unfortunately, the log:
- Spoiler: show
Code: Select all
2018-06-08 16:13:36.407 PluginSystem: Starting I/O service thread.
2018-06-08 16:13:36.407 (xiaomi vacuum) Connect directive received, action initiated successfully.
2018-06-08 16:13:36.407 (xiaomi vacuum) Pushing 'onConnectCallback' on to queue
2018-06-08 16:13:36.408 (xiaomi vacuum) Pushing 'DisconnectedEvent' on to queue
2018-06-08 16:13:36.457 (xiaomi vacuum) Processing 'onConnectCallback' message
2018-06-08 16:13:36.457 (xiaomi vacuum) Calling message handler 'onConnect'.
2018-06-08 16:13:36.458 (xiaomi vacuum) MIIOServer connection status is [111] [Connection refused]
2018-06-08 16:13:36.458 (xiaomi vacuum) Processing 'DisconnectedEvent' message
2018-06-08 16:13:36.458 (xiaomi vacuum) Disconnect event received for '127.0.0.1:22222'.
2018-06-08 16:13:36.458 (xiaomi vacuum) Pushing 'onDisconnectCallback' on to queue
2018-06-08 16:13:36.458 (xiaomi vacuum) Processing 'onDisconnectCallback' message
2018-06-08 16:13:36.458 (xiaomi vacuum) Calling message handler 'onDisconnect'.
2018-06-08 16:13:36.458 (xiaomi vacuum) MIIOServer disconnected
Re: Python plugin: Xiaomi Mi Robot Vacuum
Posted: Tuesday 12 June 2018 9:51
by Jheronymus
@snellejellep What happens when you run step 4 and 5 of the installation for the plugin(the tests) on:
https://github.com/mrin/domoticz-mirobo ... stallation
Re: Python plugin: Xiaomi Mi Robot Vacuum
Posted: Wednesday 13 June 2018 19:41
by snellejellep
while i do not see step 5 you mentioned, i did step 4 the test .py and got this:

which can not be good i think
Re: Python plugin: Xiaomi Mi Robot Vacuum
Posted: Thursday 14 June 2018 14:16
by Skippiemanz
I've got my roborock s50 yesterday(10 days after ordering) in the Netherlands.
I will try to connect it to domoticz this evening.
Fo Who is interested in also buying this xiaomi here is the sellers link
https://nl.aliexpress.com/item/Xiaomi-m ... 4c4dEHGO0Z
Re: Python plugin: Xiaomi Mi Robot Vacuum
Posted: Thursday 14 June 2018 23:47
by Jheronymus
snellejellep wrote: ↑Wednesday 13 June 2018 19:41
while i do not see step 5 you mentioned, i did step 4 the test .py and got this:

which can not be good i think
Sorry about that, with step 5 I meand the second test case, starting it manually:
Code: Select all
sudo ./miio_server.py 192.168.1.12 476e6b70343055483230644c53707a12 --host 127.0.0.1 --port 22222
# then you can run test
sudo ./test.py
The error you're getting is that probably the server is not running. For this to work you need two terminals. One running the server:
Just to be sure nothing is running
Code: Select all
sudo ./miio_server.py 192.168.1.12 476e6b70343055483230644c53707a12 --host 127.0.0.1 --port 22222
This will start a new server (provide correct IP and hahs ofcourse) keep an eye on the console, since it will produce logging!
and the other one running the test script
Both will produce logging information. That is relevant for us.
Re: Python plugin: Xiaomi Mi Robot Vacuum
Posted: Friday 15 June 2018 17:53
by snellejellep
Jheronymus wrote: ↑Thursday 14 June 2018 23:47
Sorry about that, with step 5 I meand the second test case, starting it manually:
Code: Select all
sudo ./miio_server.py 192.168.1.12 476e6b70343055483230644c53707a12 --host 127.0.0.1 --port 22222
# then you can run test
sudo ./test.py
The error you're getting is that probably the server is not running. For this to work you need two terminals. One running the server:
Just to be sure nothing is running
Code: Select all
sudo ./miio_server.py 192.168.1.12 476e6b70343055483230644c53707a12 --host 127.0.0.1 --port 22222
This will start a new server (provide correct IP and hahs ofcourse) keep an eye on the console, since it will produce logging!
and the other one running the test script
Both will produce logging information. That is relevant for us.
Wow thanks, now it works when i use the command:
Code: Select all
sudo ./miio_server.py 192.168.1.12 476e6b70343055483230644c53707a12 --host 127.0.0.1 --port 22222
of course i edited it with my token and ip, then it works but only when that window is running, do i need to setup something to let it start automatically?
i tried following all the steps but i can not seem to get the process miio_server.sh running
Re: Python plugin: Xiaomi Mi Robot Vacuum
Posted: Friday 15 June 2018 21:05
by snellejellep
well i fixed it, i do not think it is the way i am supposed to do it but i added your command:
Jheronymus wrote: ↑Thursday 14 June 2018 23:47
Code: Select all
sudo ./miio_server.py 192.168.1.12 476e6b70343055483230644c53707a12 --host 127.0.0.1 --port 22222
to the /etc/rc.local and that works really well, it only floods my domoticz log, but maby that is normal?
Re: Python plugin: Xiaomi Mi Robot Vacuum
Posted: Saturday 16 June 2018 13:55
by Jheronymus
snellejellep wrote: ↑Friday 15 June 2018 21:05
well i fixed it, i do not think it is the way i am supposed to do it but i added your command:
Jheronymus wrote: ↑Thursday 14 June 2018 23:47
Code: Select all
sudo ./miio_server.py 192.168.1.12 476e6b70343055483230644c53707a12 --host 127.0.0.1 --port 22222
to the /etc/rc.local and that works really well, it only floods my domoticz log, but maby that is normal?
Not entirely sure if this correct though. The logging you can probably disable in the hardware setting (debug true/false).
I had some trouble installing this also. Note that it only works with the last stable version V3.8153 of domoticz.
Also, you need to check your installation in the virtual environment you've setup.
At first I did everything as 'root' (sudo all the commands), also in the virtual environment. Somehow that let to that pip3 installed everything in the normal python folders. (not in the virtualenv.) You can check this by reviewing the logging and paths in the ouput of the pip3 step, or use compare results for:
inside and outside the virtualenv.