Xiaomi Air Purifier 2

Python and python framework
User avatar
remb0
Posts: 1002
Joined: Thursday 11 July 2013 22:21
Target OS: Raspberry Pi
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: Xiaomi Air Purifier 2

Post by remb0 » Thursday 08 March 2018 18:36

I move this great work to the right forum: python

DAVIZINHO
Posts: 206
Joined: Sunday 27 August 2017 18:00
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Spain
Contact:

Re: Xiaomi Air Purifier 2

Post by DAVIZINHO » Thursday 08 March 2018 21:33

kofec wrote:
Thursday 08 March 2018 16:57
If you want you can try the script 'MyAir.py" from https://github.com/kofec/domoticz-AirPurifier
e.g:
pi@raspberrypi:~/domoticz/plugins/domoticz-AirPurifier $ ./MyAir.py 192.168.1.40 933c4c22df26adaec86d6fd788f5af72
<AirPurifierStatus power=on, aqi=9,average_aqi=8,temperature=21.1, humidity=31%,mode=OperationMode.Auto,led=True,led_brightness=LedBrightness.Bright,buzzer=True, child_lock=False,favorite_level=10,filter_life_remaining=53, filter_hours_used=1614, use_time=7632371, purify_volume=77517, motor_speed=355>
Great!!! works fine. thanks a lot!

AiAmA
Posts: 1
Joined: Saturday 10 March 2018 18:14
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Air Purifier 2

Post by AiAmA » Saturday 10 March 2018 18:26

kofec wrote:
Friday 02 February 2018 15:55
I have created a plugin: https://github.com/kofec/domoticz-AirPurifier
Nice plugin, thanks! I'm having a little hiccup though when

Code: Select all

./MyAir.py 192.168.1.129 7d5474e308cf13f359373fd1c2b0e676 --debug
it returns

Namespace(IPaddress='192.168.1.129', debug=True, favoriteLevel=None, mode=None, power=None, token='7d5474e308cf13f359373fd1c2b0e676')
Traceback (most recent call last):
File "./MyAir.py", line 64, in <module>
print(MyAir.status())
File "/home/pi/.local/lib/python3.5/site-packages/miio/airpurifier.py", line 174, in __repr__
self.led_brightness,
File "/home/pi/.local/lib/python3.5/site-packages/miio/airpurifier.py", line 105, in led_brightness
return LedBrightness(self.data["bright"])
File "/usr/lib/python3.5/enum.py", line 241, in __call__
return cls.__new__(cls, value)
File "/usr/lib/python3.5/enum.py", line 476, in __new__
raise ValueError("%r is not a valid %s" % (value, cls.__name__))
ValueError: 9 is not a valid LedBrightness

And the domoticz log shows
2018-03-10 17:09:04.849 Error: (AirPurifier) failed to load 'plugin.py', Python Path used was '/home/pi/domoticz/plugins/domoticz-AirPurifier/:/usr/lib/python35.zip:/usr/lib/python3.5:/usr/lib/python3.5/plat-arm-linux-gnueabihf:/usr/lib/python3.5/lib-dynload'.
2018-03-10 17:09:04.849 Error: (Mari Puri) Module Import failed, exception: 'ImportError'
2018-03-10 17:09:04.849 Error: (Mari Puri) Module Import failed: ' Name: miio'
2018-03-10 17:09:04.849 Error: (Mari Puri) Error Line details not available.
2018-03-10 17:10:00.421 Error: Mari Puri hardware (6) thread seems to have ended unexpectedly

:shock: :shock: :shock: :shock:

kofec
Posts: 35
Joined: Friday 16 September 2016 14:16
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Air Purifier 2

Post by kofec » Tuesday 27 March 2018 22:45

There was an issue in library python-miio
please install the latest version:
pip3 install -U python-miio

mgrom
Posts: 6
Joined: Saturday 07 April 2018 8:11
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Air Purifier 2

Post by mgrom » Saturday 07 April 2018 8:24

MyAir.py is working like a charm, so I have python-miio installed, but the plugin is not loading correctly in domoticz:

Code: Select all

2018-04-07 08:15:46.682 Error: (AirPurifier) failed to load 'plugin.py', Python Path used was '/home/osmc/domoticz/plugins/xiaomi-purifier/:/usr/lib/python35.zip:/usr/lib/python3.5:/usr/lib/python3.5/plat-arm-linux-gnueabihf:/usr/lib/python3.5/lib-dynload'.
2018-04-07 08:15:46.682 Error: (Purifier) Module Import failed, exception: 'ImportError'
2018-04-07 08:15:46.682 Error: (Purifier) Module Import failed: ' Name: miio'
2018-04-07 08:15:46.682 Error: (Purifier) Error Line details not available.
I think that this could be related to python path used, because pip3 install -U installs package in ~/.local/ but this path is not in the list from log:
'/home/osmc/domoticz/plugins/xiaomi-purifier/:/usr/lib/python35.zip:/usr/lib/python3.5:/usr/lib/python3.5/plat-arm-linux-gnueabihf:/usr/lib/python3.5/lib-dynload'
Can you help me with this?


EDIT:
I've changed one of the lines to:

Code: Select all

pathOfPackages = '/home/osmc/.local/lib/python3.5/site-packages'
And now it seems that the package is recognized, but.... I've got bigger problem. Domoticz crashes with:

Code: Select all

2018-04-07 08:56:12.146  Error: Domoticz received fatal signal 11 !...
2018-04-07 08:56:12.148  Error:   /home/osmc/domoticz/domoticz() [0x24f04c]
2018-04-07 08:56:12.148  Error:   /home/osmc/domoticz/domoticz(_Z14signal_handleri+0x4c) [0x24f104]
2018-04-07 08:56:12.148  Error:   /lib/arm-linux-gnueabihf/libc.so.6(+0x24fd0) [0x76c66fd0]

mgrom
Posts: 6
Joined: Saturday 07 April 2018 8:11
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Air Purifier 2

Post by mgrom » Wednesday 11 April 2018 10:13

Ok, I've finally compiled domoticz from source and it's working :)

deennoo
Posts: 942
Joined: Wednesday 10 December 2014 14:06
Target OS: Linux
Domoticz version: beta
Location: Bordeaux France
Contact:

Re: Xiaomi Air Purifier 2

Post by deennoo » Wednesday 30 May 2018 23:55

ben53252642 wrote:
Wednesday 18 January 2017 19:55
8) For those who want to load the Temperature, Humidity and Aqi (pm2.5 estimate) into Domoticz sensors, below is a updatedomoticz.sh bash script:

Code: Select all

#!/bin/bash
while true; do

# Get the data
data=$(node airpurifier.js 192.168.0.240 status)
# Sort it
temperature=$(echo "$data" | grep "temperature" | sed -e s/[^0-9.]//g)
humidity=$(echo "$data" | grep "humidity" | sed -e s/[^0-9.%]//g)
aqi=$(echo "$data" | grep "aqi" | sed -e s/[^0-9.]//g)

# Load it into Domoticz
curl -s "http://USERNAME:PASSWORD@192.168.0.5/json.htm?type=command&param=udevice&idx=607&nvalue=0&svalue=${temperature};${humidity};0"
curl -s "http://USERNAME:PASSWORD@192.168.0.5/json.htm?type=command&param=udevice&idx=599&svalue=${aqi}"

sleep 60
done
I need your help for Xiaomi pm2.5 sensor; The Python Plugin doesn't work @ home.

I prefere your solution

i have modify your airpurifier.js for the pm2.5 sensor and result is :

Code: Select all

{ power: true, aqi: 14, batteryLevel: 100, charging: true }
Of course i juste need aqi value

using

Code: Select all

aqi=$(echo "$data" | grep "aqi" | sed -e s/[^0-9.]//g)
this give me the batterie level to = 14100, can you help me ?
Domoticz stable 3.5877 for real & Domoticz beta for test
Rfxtrxe / RFLink / Milight / Yeelight / ESP8266 / MQTT / BLE
http://domo-attitude.fr

DAVIZINHO
Posts: 206
Joined: Sunday 27 August 2017 18:00
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Spain
Contact:

Re: Xiaomi Air Purifier 2

Post by DAVIZINHO » Thursday 31 May 2018 0:03

for aqi i use this:

Code: Select all

aqi=$(echo "$data" | grep -Po ' aqi=\K[^,]+')

marafado88
Posts: 7
Joined: Saturday 09 June 2018 3:16
Target OS: Linux
Domoticz version:
Contact:

Re: Xiaomi Air Purifier 2

Post by marafado88 » Sunday 10 June 2018 22:37

I have received tons of warnings at step 2) and 3) :( :
2) Install miIO Device Library: npm install --save miio

Code: Select all

npm WARN engine miio@0.15.6: wanted: {"node":">=6.6.0"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine chalk@2.4.1: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine abstract-things@0.9.0: wanted: {"node":">=6.6.0"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine tinkerhub-discovery@0.3.1: wanted: {"node":">=6.0.0"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine supports-color@5.4.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine ansi-styles@3.2.1: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine has-flag@3.0.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine find-up@2.1.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine os-locale@2.1.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine string-width@2.1.1: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine locate-path@2.0.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine dwaal@0.1.4: wanted: {"node":">=6.0.0"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine execa@0.7.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine mem@1.1.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine strip-ansi@4.0.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine camelcase@4.1.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine strip-ansi@4.0.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine is-fullwidth-code-point@2.0.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine p-locate@2.0.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine path-exists@3.0.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine ansi-regex@3.0.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine ansi-regex@3.0.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine mimic-fn@1.2.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine p-finally@1.0.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine npm-run-path@2.0.2: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine get-stream@3.0.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine p-limit@1.3.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine path-key@2.0.1: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine p-try@1.0.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
3) Install miio command line utility: npm install -g miio

Code: Select all

npm WARN engine miio@0.15.6: wanted: {"node":">=6.6.0"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine abstract-things@0.9.0: wanted: {"node":">=6.6.0"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine chalk@2.4.1: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine tinkerhub-discovery@0.3.1: wanted: {"node":">=6.0.0"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine dwaal@0.1.4: wanted: {"node":">=6.0.0"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine find-up@2.1.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine os-locale@2.1.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine string-width@2.1.1: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine supports-color@5.4.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine ansi-styles@3.2.1: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine locate-path@2.0.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine mem@1.1.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine execa@0.7.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine camelcase@4.1.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine has-flag@3.0.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine is-fullwidth-code-point@2.0.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine strip-ansi@4.0.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine strip-ansi@4.0.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine mimic-fn@1.2.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine ansi-regex@3.0.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine ansi-regex@3.0.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine p-locate@2.0.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine path-exists@3.0.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine p-limit@1.3.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine npm-run-path@2.0.2: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine get-stream@3.0.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine p-finally@1.0.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine path-key@2.0.1: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
npm WARN engine p-try@1.0.0: wanted: {"node":">=4"} (current: {"node":"0.10.29","npm":"1.4.21"})
and in the end i was unable to run 4):
4) Run this command to discover and sync the key from your Air Purifier: miio --discover --sync

Code: Select all

miio --discover --sync
I have run all of those commands at root, who is the same user running domoticz.

Piwek
Posts: 1
Joined: Friday 24 August 2018 23:27
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Air Purifier 2

Post by Piwek » Friday 24 August 2018 23:42

Hi, I have a problem with this plugin:

Code: Select all

2018-08-24 23:40:16.608 Error: (AirPurifier) failed to load 'plugin.py', Python Path used was '/home/pi/domoticz/plugins/domoticz-AirPurifier/:/usr/lib/python35.zip:/usr/lib/python3.5:/usr/lib/python3.5/plat-arm-linux-gnueabihf:/usr/lib/python3.5/lib-dynload'. 

 2018-08-24 23:40:16.609 Error: (Oczyszczacz) Module Import failed, exception: 'ImportError' 

 2018-08-24 23:40:16.609 Error: (Oczyszczacz) Module Import failed: ' Name: miio' 

 2018-08-24 23:40:16.609 Error: (Oczyszczacz) Error Line details not available. 

Code: Select all

./MyAir.py 192.168.1.4 e8c60b26d83ca76c9b94ee066f4ccf23 --debug
Namespace(IPaddress='192.168.1.4', debug=True, favoriteLevel=None, mode=None, power=None, token='e8c60b26d83ca76c9b94ee066f4ccf23')
<AirPurifierStatus power=on, aqi=10, average_aqi=8, temperature=26.6, humidity=59%, mode=OperationMode.Auto, led=True, led_brightness=LedBrightness.Dim, illuminance=None, buzzer=False, child_lock=False, favorite_level=10, filter_life_remaining=6, filter_hours_used=3274, use_time=11784415, purify_volume=130722, motor_speed=344, motor2_speed=None, volume=None, filter_rfid_product_id=None, filter_rfid_tag=None, filter_type=None, learn_mode=False, sleep_mode=None, sleep_time=None, sleep_mode_learn_count=None, extra_features=0, turbo_mode_supported=False, auto_detect=None, button_pressed=None>


kofec
Posts: 35
Joined: Friday 16 September 2016 14:16
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Air Purifier 2

Post by kofec » Monday 03 September 2018 22:41

As other above you need to correct:
pathOfPackages = '/home/osmc/.local/lib/python3.5/site-packages'
- to your path where miio packages is installed

nono212
Posts: 31
Joined: Sunday 18 December 2016 14:47
Target OS: Linux
Domoticz version: 3.6179
Contact:

Re: Xiaomi Air Purifier 2

Post by nono212 » Saturday 06 October 2018 21:55

Can you please help the script myAir is not working but airpurifier.js does


nono212@syno:/volume1/@appstore/domoticz/var/plugins/domoticz-AirPurifier$ ./MyAir.py 192.168.1.76 78de1a56c6b7ab88048242e471234683 --debug
Traceback (most recent call last):
File "./MyAir.py", line 11, in <module>
import miio.airpurifier
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/miio/__init__.py", line 2, in <module>
from miio.airconditioningcompanion import AirConditioningCompanion
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/miio/airconditioningcompanion.py", line 7, in <module>
from .click_common import command, format_output, EnumType
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/miio/click_common.py", line 251, in <module>
result_msg_fmt: Union[str, callable]="{result}"):
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/typing.py", line 537, in __getitem__
dict(self.__dict__), parameters, _root=True)
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/typing.py", line 467, in __new__
params.append(_type_check(p, msg))
File "/volume1/@appstore/py3k/usr/local/lib/python3.5/typing.py", line 299, in _type_check
raise TypeError(msg + " Got %.100r." % (arg,))
TypeError: Union[arg, ...]: each arg must be a type. Got <built-in function callable>.



nono212@syno:/volume1/@appstore/domoticz/var/plugins/domoticz-AirPurifier$ node airpurifier.js 192.168.1.76 status
{ power: true,
mode: 'silent',
aqi: 39,
temperature: 23,
humidity: 54 }


nono212@syno:pip3 freeze
android-backup==0.2.0
appdirs==1.4.3
asn1crypto==0.24.0
attrs==18.2.0
cffi==1.11.5
Click==7.0
construct==2.9.41
cryptography==2.3.1
idna==2.7
ifaddr==0.1.4
ipaddress==1.0.22
pretty-cron==1.2.0
pycparser==2.19
python-miio==0.4.1
pytz==2018.5
six==1.11.0
tqdm==4.26.0
zeroconf==0.21.3

yom
Posts: 7
Joined: Sunday 13 October 2013 2:46
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Air Purifier 2

Post by yom » Saturday 08 December 2018 1:39

Hi,

Just want to say a big thank you to ben53252642 !
Nice Job, nice share :-)

ben53252642
Posts: 540
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Xiaomi Air Purifier 2

Post by ben53252642 » Friday 14 December 2018 17:49

The original post has been updated to fix a bug with the LED control in the airpurifier.js file.

Please be sure to use the latest version of miio, it can be upgraded with this command:

npm install miio@latest --save

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 3 guests