Python plugin: Xiaomi Mi Robot Vacuum Topic is solved

Python and python framework
DAVIZINHO
Posts: 202
Joined: Sunday 27 August 2017 18:00
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Spain
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by DAVIZINHO » Monday 27 August 2018 11:51

dlefol wrote:
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.
i thing so.
the mihome app send notificacion with a "timer" no more :-(

dagasoft
Posts: 16
Joined: Thursday 03 December 2015 15:11
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by dagasoft » Tuesday 28 August 2018 17:51

dlefol wrote:
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.
So how does Mi Home notify about cleaning the dust bin?

I get notifications that say "you have to empty the dust bin".

dagasoft
Posts: 16
Joined: Thursday 03 December 2015 15:11
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by dagasoft » Tuesday 28 August 2018 20:50

DAVIZINHO wrote:
Monday 27 August 2018 11:51
dlefol wrote:
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.
i thing so.
the mihome app send notificacion with a "timer" no more :-(
Thank you for your reply. So I think I will implement notifications through a timer in domoticz to remember to clean the dust bin after some hours of use. I see in the python script that there is an option to get all time cleaned, do you know if we are able to read it from domoticz?

Thanks.

User avatar
scriptedbackdoor
Posts: 3
Joined: Tuesday 02 October 2018 6:09
Target OS: Windows
Domoticz version: Stable
Location: Texas, Austin
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by scriptedbackdoor » Tuesday 02 October 2018 6:49

How can it be used with iRoomba robocouum?

wouterlet
Posts: 4
Joined: Tuesday 02 October 2018 20:52
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by wouterlet » Thursday 18 October 2018 14:26

Philos31 wrote:
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?
I'm looking for this also. I found the manuals but there is no "apt-get" available on my synology. It seemed Debian Chroot did this in the past, but isn't available anymore. Who knows a solution?

misko903
Posts: 48
Joined: Thursday 27 September 2018 22:58
Target OS: Raspberry Pi
Domoticz version: Latest
Location: Trencin, Slovakia
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by misko903 » Thursday 08 November 2018 14:33

I got closer with your posts, but I have ended here:

Code: Select all

(.env) pi@raspberrypi:~/domoticz/plugins/xiaomi-mi-robot-vacuum $ pip3 install -r pip_req.txt
after few installs come this message:

Code: Select all

...
Using cached https://files.pythonhosted.org/packages/6b/88/48dbe88b10098f98acef33218763c5630b0081c7fd0849ab4793b1e9b6d3/zeroconf-0.19.1-py2.py3-none-any.whl
Installing collected packages: android-backup, asn1crypto, attrs, pycparser, cffi, click, construct, six, idna, cryptography, enum-compat, greenlet, gevent, msgpack-python, netifaces, pretty-cron, pycrypto, pytz, typing, zeroconf, python-miio

Could not install packages due to an EnvironmentError: [Errno 13] Prístup odmietnutý: '/home/pi/domoticz/plugins/xiaomi-mi-robot-vacuum/.env/lib/python3.5/site-packages/android_backup-0.1.0.dist-info'
Consider using the `--user` option or check the permissions.

then i was trying

Code: Select all

pi@raspberrypi:~/domoticz/plugins/xiaomi-mi-robot-vacuum/.env/lib/python3.5/site-packages $ ls
and saw that the files your shell listed is much smaller than yours:

Code: Select all

easy_install.py  pip-18.1.dist-info  __pycache__  setuptools-40.5.0.dist-info  wheel-0.32.2.dist-info
pip              pkg_resources       setuptools   wheel
what i am doing wrong?

Thanks for replies!

Jheronymus wrote:
Saturday 02 June 2018 15:09
Jheronymus wrote:
Thursday 17 May 2018 16:56
Geitje wrote:
Tuesday 06 March 2018 2: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

Code: Select all

>deactivate
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

misko903
Posts: 48
Joined: Thursday 27 September 2018 22:58
Target OS: Raspberry Pi
Domoticz version: Latest
Location: Trencin, Slovakia
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by misko903 » Friday 09 November 2018 23:17

update:
firing:

Code: Select all

pi@raspberrypi:~/domoticz/plugins/xiaomi-mi-robot-vacuum $ virtualenv -p python3 .env
caused:

Code: Select all

Already using interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /home/pi/domoticz/plugins/xiaomi-mi-robot-vacuum/.env/bin/python3
Traceback (most recent call last):
  File "/usr/local/bin/virtualenv", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.5/dist-packages/virtualenv.py", line 762, in main
    symlink=options.symlink,
  File "/usr/local/lib/python3.5/dist-packages/virtualenv.py", line 998, in create_environment
    install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages=site_packages, clear=clear, symlink=symlink)
  File "/usr/local/lib/python3.5/dist-packages/virtualenv.py", line 1318, in install_python
    make_exe(py_executable)
  File "/usr/local/lib/python3.5/dist-packages/virtualenv.py", line 449, in make_exe
    os.chmod(fn, newmode)
PermissionError: [Errno 1] Operation not permitted: '/home/pi/domoticz/plugins/xiaomi-mi-robot-vacuum/.env/bin/python3'
tried to uninstall virtual env with

Code: Select all

sudo pip uninstall virtualenv
and installed it back

Code: Select all

virtualenv -p python3 .env
but result is the same.

Code: Select all

>sudo which pip3
/usr/bin/pip3
should I and if yes, how I can uninstall pip3 from usr/bin?

EDIT:
i have made something:

Code: Select all

> sudo which pip3
/usr/local/bin/pip3
nothing else is changed, still the same virtualenv errors.

misko903
Posts: 48
Joined: Thursday 27 September 2018 22:58
Target OS: Raspberry Pi
Domoticz version: Latest
Location: Trencin, Slovakia
Contact:

Re: Python plugin: Xiaomi Mi Robot Vacuum

Post by misko903 » Sunday 11 November 2018 0:02

installed it new from scratch.

everything works, except:

Code: Select all

pi@raspberrypi:~/domoticz/plugins/xiaomi-mirobot $ sudo ./test.py
test: python modules path: ././.env/lib/python3.5/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.5/socket.py", line 712, in create_connection
    raise err
  File "/usr/lib/python3.5/socket.py", line 703, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
after that,

Code: Select all

pi@raspberrypi:~/domoticz/plugins/xiaomi-mirobot $ sudo service miio_server stop
pi@raspberrypi:~/domoticz/plugins/xiaomi-mirobot $ sudo ./miio_server.py IP token --host 127.0.0.1 --port 22222
Traceback (most recent call last):
  File "./miio_server.py", line 18, in <module>
    from miio import Vacuum, DeviceException
  File "/usr/local/lib/python3.5/dist-packages/miio/__init__.py", line 2, in <module>
    from miio.airconditioningcompanion import AirConditioningCompanion
  File "/usr/local/lib/python3.5/dist-packages/miio/airconditioningcompanion.py", line 8, in <module>
    from .device import Device, DeviceException
  File "/usr/local/lib/python3.5/dist-packages/miio/device.py", line 16, in <module>
    from .protocol import Message
  File "/usr/local/lib/python3.5/dist-packages/miio/protocol.py", line 190, in <module>
    Const(0x2131, Int16ub),
  File "/usr/local/lib/python3.5/dist-packages/construct/core.py", line 1930, in __init__
    super(Const, self).__init__(subcon)
  File "/usr/local/lib/python3.5/dist-packages/construct/core.py", line 288, in __init__
    raise TypeError("subcon should be a Construct field")
TypeError: subcon should be a Construct field
and there I have ended.

Stimpy68
Posts: 12
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 » Monday 19 November 2018 11:37

Can't seem to find it anywhere, how do you update the miirobo part?

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests