/domoticz-mirobot-plugin

Xiaomi Mi Robot Vacuum plugin for Domoticz

Primary LanguagePython

Xiaomi Mi Robot Vacuum - Domoticz Python plugin

This plugin uses the Python-miio library.

See this link for more information on the Domoticz plugins.

How it works

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).

Control: for sending commands.

Fan Level: for adjusting suction power. (MiHome app related: Quiet=38, Balanced=60, Turbo=77, Max=90)

Battery: since 0.0.4 as new device

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.

Since 0.1.2 wrapper-server (MIIO Server) runs outside plugin due limits of domoticz python plugin system.

Installation

Before installation plugin check the python3, python3-dev, pip3 is installed for Domoticz plugin system:

sudo apt-get install python3 python3-dev python3-pip

Make sure you have libffi and openssl headers installed, you can do this on Debian-based systems (like Rasperry Pi) with:

sudo apt-get install libffi-dev libssl-dev.

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:

sudo pip3 install -U setuptools.

Also need to install virtualenv:

sudo pip3 install -U virtualenv.

Then go to plugins folder and clone repository:

cd domoticz/plugins
git clone https://github.com/mrin/domoticz-mirobot-plugin.git xiaomi-mirobot
cd xiaomi-mirobot
virtualenv -p python3 .env
source .env/bin/activate

# and then:
pip3 install -r pip_req.txt 
# or pip3 install gevent msgpack-python python-miio==0.3.1

Since 0.1.2 need some prepare of MIIO Server to run as service:

  1. Open and edit miio_server.sh by vi/nano:
nano miio_server.sh

# 1. Check and update absolute path to miio_server.py
# 2. Update IP and TOKEN for robot
# 3. Optional. Change MIIO server host-port bindings if need it

# 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"
#
  1. Check path to python3 which python3. By default is /usr/bin/python3. If your path different than default, update miio_server.py first line with your path.
#!/usr/bin/python3
  1. For run as system service:
sudo chmod +x miio_server.py
sudo chmod +x miio_server.sh

# check your path here:
sudo ln -s /home/pi/domoticz/plugins/xiaomi-mirobot/miio_server.sh /etc/init.d/miio_server

# add to startup
sudo update-rc.d miio_server defaults
sudo systemctl daemon-reload

# if you want to remove from startup
sudo update-rc.d -f miio_server remove
  1. Run server and test script:
sudo service miio_server start
sudo chmod +x test.py
sudo ./test.py

# to stop miio server service
sudo service miio_server stop

Also you can run MIIO Server manually and look log output:

sudo ./miio_server.py 192.168.1.12 476e6b70343055483230644c53707a12 --host 127.0.0.1 --port 22222

# then you can run test
sudo ./test.py

If server and test is ok, time to restart the Domoticz:

sudo service domoticz.sh restart

Now go to Setup -> Hardware in your Domoticz interface and add type with name Xiaomi Mi Robot Vacuum.

Field Information
Data Timeout Keep Disabled
MIIOServer host:port by default 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)
Debug When set to true the plugin shows additional information in the Domoticz log

After clicking on the Add button the new devices are available in Setup -> Devices.

If you want to change Fan Level Type just disable hardware, update type and enable again. Old device can be deleted manually in Devices menu.

How to update plugin

cd domoticz/plugins/xiaomi-mirobot
git pull

Restart the Domoticz service

sudo service domoticz.sh restart

Screenshots

status_unit control_unit

fan_level fan_level2

care1 care2

bat

How to obtain device Token

Check the instruction