Skip to content

Commit

Permalink
New device:
Browse files Browse the repository at this point in the history
 * Care - Main Brush
 * Care - Side Brush
 * Care - Sensors
 * Care - Filter
 * Care Reset Control

New wrapper-tcp-server for python-miio
  • Loading branch information
mrin committed Nov 5, 2017
1 parent 174be40 commit ea1da2d
Show file tree
Hide file tree
Showing 8 changed files with 488 additions and 218 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.vendors/
.idea/
__pycache__
.pyc
python-mirobo.seq
.env
log
Empty file removed .vendors/.gitkeep
Empty file.
63 changes: 26 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@

# Xiaomi Mi Robot Vacuum - Domoticz Python plugin

*This plugin uses the [Python-mirobo](https://github.com/rytilahti/python-mirobo) library.*
*This plugin uses the [Python-miio](https://github.com/rytilahti/python-miio) library.*

*See this [link](https://www.domoticz.com/wiki/Using_Python_plugins) for more information on the Domoticz plugins.*

## How it works

Plugin provides: Status, Control, Fan Level and Battery devices.
Plugin provides: Status, Control, Fan Level, Battery, Care status devices

**Status**: show current status in readable layout of switch. Status updates by polls
(interval) and when you click Control device (for instant status change).
Expand All @@ -17,8 +18,9 @@ Plugin provides: Status, Control, Fan Level and Battery devices.

**Battery**: since ```0.0.4``` as new device

Plugin calls **python-mirobo** (in subprocess) via own wrapper behind for converting results from lib to JSON and then update status of device.
Domoticz has some limitation in python plugin system, so this lib doesn't work well directly in plugin (plugin halted after first heartbeat).
**Care**: since ```0.1.0``` new 5 devices (care status + reset tool)

Since ```0.1.0``` plugin uses wrapper-server for python-miio lib. It helps to use this plugin in Domoticz without blocking mode.

## Installation

Expand All @@ -28,20 +30,29 @@ Before installation plugin check the `python3` and `python3-dev` is installed fo

Also do note that the setuptools version is too old for installing some requirements, so before trying to install this package you should update the setuptools with:

```pip3 install -U setuptools```.
```sudo pip3 install -U setuptools```.

Also need to install virtualenv:
```sudo pip3 install -U virtualenv```.

Please make sure you have libffi and openssl headers installed, you can do this on Debian-based systems (like Rasperry Pi) with
```apt-get install libffi-dev libssl-dev```.
```sudo apt-get install libffi-dev libssl-dev```.

Then go to plugins folder and clone plugin:
Then go to plugins folder and clone plugin then activate virtualenv:
```
cd domoticz/plugins
git clone https://github.com/mrin/domoticz-mirobot-plugin.git xiaomi-mirobot
```
Then install [python-mirobo](https://github.com/rytilahti/python-mirobo) locally (due issues with python paths) with all dependencies:

Now create virtualenv and install required libs:
```
cd xiaomi-mirobot
pip3 install python-mirobo -t .vendors
virtualenv -p python3 .env
pip3 install -r pip_req.txt
# or pip3 install gevent msgpack-python python-miio==0.3.1
```

Restart the Domoticz service
Expand All @@ -56,6 +67,7 @@ Now go to **Setup** -> **Hardware** in your Domoticz interface and add type with
| Data Timeout | Keep Disabled |
| IP address | Enter the IP address of your Vacuum (see the MiHome app or router dhcp, should be static) |
| Token | This token is only attainable before the device has been connected over the app to your local wifi (or alternatively, if you have paired your rooted mobile device with the vacuum, or if you share access to Vacuum via MiHome to rooted device) |
| MIIOServer host:port | Local server will be started with plugin on 127.0.0.1:22222 |
| Update interval | In seconds, this determines with which interval the plugin polls the status of Vacuum. Suggested is no lower then 5 sec due timeout in python-mirobo lib, but you can try any. |
| Fan Level Type | ```Standard``` - standard set of buttons (values supported by MiHome); ```Slider``` - allow to set custom values, up to 100 (in standard Max=90) (values not supported by MiHome) |
| Python Path | Path to Python 3, default is python3 |
Expand All @@ -72,8 +84,6 @@ cd domoticz/plugins/xiaomi-mirobot
git pull
```

For update python-mirobo use ```pip3 install python-mirobo -t .vendors --upgrade```

Restart the Domoticz service
```
sudo service domoticz.sh restart
Expand All @@ -87,33 +97,12 @@ sudo service domoticz.sh restart
![fan_level](https://user-images.githubusercontent.com/93999/29668575-6906ea22-88e9-11e7-8508-8f0ff48e2f78.png)
![fan_level2](https://user-images.githubusercontent.com/93999/29713051-86cd023c-89a5-11e7-83cc-5953b8cbbfa5.png)

![bat](https://user-images.githubusercontent.com/93999/29769383-c8202814-8bf2-11e7-86b2-3629bfc63dc0.png)

### How to obtain device Token

*Important* For Mi Robot with firmware 3.3.9_003077 or higher use these methods to obtain the device token: https://github.com/jghaanstra/com.xiaomi-miio/blob/master/docs/obtain_token_mirobot_new.md

**Android rooted device**

*(Also you can share Vacuum via MiHome to the other rooted device)*
![care1](https://user-images.githubusercontent.com/93999/32418537-08d3c918-c27d-11e7-89e9-10daf79bcdb4.png)
![care2](https://user-images.githubusercontent.com/93999/32418538-08ef7e10-c27d-11e7-9ff8-8dfff1c20377.png)

Need database file miio2.db which located here:
```
/data/data/com.xiaomi.smarthome/databases/miio2.db
```
Open file with any SQLite db editor/manager. Table "devicerecord" with column "token".
![bat](https://user-images.githubusercontent.com/93999/29769383-c8202814-8bf2-11e7-86b2-3629bfc63dc0.png)

**Reset robot**

Install lib and check it
```
pip3 install python-mirobo
mirobo discover
```
You should see something like this:
```
mirobo.vacuum: IP 192.168.1.12: Xiaomi Mi Robot Vacuum - token: b'ffffffffffffffffffffffffffffffff'
```
### How to obtain device Token

Reset the robot, then connect to the network its announcing (SSID "rockrobo-XXXX").
Then run ```mirobo discover``` and you should receive token.
Check the [instruction](https://github.com/rytilahti/python-miio#finding-the-token)
107 changes: 0 additions & 107 deletions mirobo-wrapper.py

This file was deleted.

21 changes: 21 additions & 0 deletions pip_req.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
android-backup==0.1.0
asn1crypto==0.23.0
attrs==17.2.0
cffi==1.11.2
click==6.7
construct==2.8.16
cryptography==2.1.3
enum-compat==0.0.2
gevent==1.2.2
greenlet==0.4.12
idna==2.6
msgpack-python==0.4.8
netifaces==0.10.6
pretty-cron==1.0.2
pycparser==2.18
pycrypto==2.6.1
python-miio==0.3.1
pytz==2017.3
six==1.11.0
typing==3.6.2
zeroconf==0.19.1
Loading

0 comments on commit ea1da2d

Please sign in to comment.