Xiaomi Air Purifier 2

Python and python framework
kofec
Posts: 33
Joined: Friday 16 September 2016 14:16
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Air Purifier 2

Post by kofec » Friday 02 February 2018 15:55


molnaratti
Posts: 14
Joined: Friday 02 February 2018 17:21
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Air Purifier 2

Post by molnaratti » Friday 02 February 2018 17:29

Nice! :)
thanx

Little problem:
./MyAir.py 192.168.1.112 4a7e68c46bb35be46231dce8df35b77a
Traceback (most recent call last):
File "./MyAir.py", line 64, in <module>
print(MyAir.status())
File "/usr/local/lib/python3.5/dist-packages/miio/airpurifier.py", line 215, in status
properties[0:13]
File "/usr/local/lib/python3.5/dist-packages/miio/device.py", line 216, in send
m = Message.build(msg, ctx)
TypeError: build() takes 2 positional arguments but 3 were given

How can I solve it?

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

Re: Xiaomi Air Purifier 2

Post by kofec » Friday 02 February 2018 18:04

Can you execute ./MyAir.py 192.168.1.112 4a7e68c46bb35be46231dce8df35b77a --debug

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

Re: Xiaomi Air Purifier 2

Post by kofec » Friday 02 February 2018 18:09

You can also display version of you packages:

Code: Select all

pi@Rpi:~/domoticz/plugins/domoticz-AirPurifier $ pip freeze
aiohttp==2.2.5
android-backup==0.1.0
asn1crypto==0.24.0
astral==1.4
async-timeout==2.0.0
asyncio==3.4.3
attrs==17.3.0
certifi==2017.7.27.1
cffi==1.11.2
chardet==3.0.4
click==6.7
construct==2.8.17
cryptography==2.1.4
enum-compat==0.0.2
homeassistant==0.56.2
idna==2.6
iotop==0.6
Jinja2==2.9.6
keyring==10.1
keyrings.alt==1.3
MarkupSafe==1.0
multidict==3.3.0
netifaces==0.10.6
pretty-cron==1.0.2
pyasn1==0.1.9
pycparser==2.18
pycrypto==2.6.1
pygobject==3.22.0
python-apt==1.1.0b5
python-miio==0.3.3
pytz==2017.3
pyxdg==0.25
PyYAML==3.12
requests==2.14.2
samsungctl==0.6.0
SecretStorage==2.3.1
six==1.11.0
typing==3.6.2
voluptuous==0.10.5
xmltodict==0.11.0
yarl==0.13.0
zeroconf==0.19.1

molnaratti
Posts: 14
Joined: Friday 02 February 2018 17:21
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Air Purifier 2

Post by molnaratti » Friday 02 February 2018 18:21

thank you for helping

./MyAir.py 192.168.1.112 4a7e68c46bb35be46231dce8df35b77a --debug
Namespace(IPaddress='192.168.1.112', debug=True, favoriteLevel=None, mode=None, power=None, token='4a7e68c46bb35be46231dce8df35b77a')
Traceback (most recent call last):
File "./MyAir.py", line 64, in <module>
print(MyAir.status())
File "/usr/local/lib/python3.5/dist-packages/miio/airpurifier.py", line 215, in status
properties[0:13]
File "/usr/local/lib/python3.5/dist-packages/miio/device.py", line 216, in send
m = Message.build(msg, ctx)
TypeError: build() takes 2 positional arguments but 3 were given

pip freeze
beautifulsoup4==4.5.3
certifi==2018.1.18
chardet==3.0.4
cryptography==1.7.1
Django==1.11.9
django-request==1.5.4
enum34==1.1.6
get==0.0.39
gyp==0.1
html5lib==0.999999999
idna==2.6
ipaddress==1.0.17
keyring==10.1
keyrings.alt==1.3
lxml==3.7.1
post==0.0.26
public==0.0.65
pyasn1==0.1.9
PyBluez==0.18
pycrypto==2.6.1
pygobject==3.22.0
pyOpenSSL==16.2.0
Pyste==0.9.10
python-dateutil==2.6.1
pytz==2017.3
pyxdg==0.25
query-string==0.0.28
request==0.0.26
requests==2.18.4
RPi.GPIO==0.6.3
SecretStorage==2.3.1
six==1.11.0
urllib3==1.22
webencodings==0.5
websocket-client==0.37.0

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

Re: Xiaomi Air Purifier 2

Post by kofec » Friday 02 February 2018 18:30

This script base library "python-miio" which I don't see in your library so please install it
https://pypi.python.org/pypi/python-miio

pip3 install python-miio

you can also execute pip -V

molnaratti
Posts: 14
Joined: Friday 02 February 2018 17:21
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Air Purifier 2

Post by molnaratti » Friday 02 February 2018 18:35

pip3 freeze :

Code: Select all

aiohttp==2.3.7
android-backup==0.1.0
astral==1.4
async-timeout==2.0.0
attrs==17.4.0
certifi==2017.11.5
chardet==3.0.4
click==6.7
construct==2.9.26
cryptography==1.7.1
enum-compat==0.0.2
homeassistant==0.61.1
idna==2.6
iotop==0.6
Jinja2==2.10
keyring==10.1
keyrings.alt==1.3
MarkupSafe==1.0
multidict==4.0.0
netifaces==0.10.6
pretty-cron==1.0.2
pyasn1==0.1.9
pycrypto==2.6.1
pygatt==3.2.0
pygobject==3.22.0
pyserial==3.4
python-apt==1.1.0b5
python-miio==0.3.4
pytz==2017.3
pyxdg==0.25
PyYAML==3.12
requests==2.18.4
samsungctl==0.7.0
SecretStorage==2.3.1
six==1.11.0
typing==3.6.2
urllib3==1.22
voluptuous==0.10.5
websocket-client==0.45.0
yarl==0.18.0
zeroconf==0.19.1
pip install python-miio
Collecting python-miio
Downloading python-miio-0.3.4.tar.gz
python-miio requires Python '>=3.4' but the running Python is 2.7.13

pip -V
pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)
pip3 -V
pip 9.0.1 from /home/pi/.local/lib/python3.5/site-packages (python 3.5)

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

Re: Xiaomi Air Purifier 2

Post by kofec » Friday 02 February 2018 18:53

Ok latest version of library has bug: https://github.com/rytilahti/python-miio/issues/201

you have to downgrade - so please execute:

pip3 install -U python-miio==0.3.3
pip3 install -U construct==2.8.17

molnaratti
Posts: 14
Joined: Friday 02 February 2018 17:21
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Air Purifier 2

Post by molnaratti » Friday 02 February 2018 19:05

Works ! :)
./MyAir.py 192.168.1.112 4a7e68c46bb35be46231dce8df35b77a
<AirPurifierStatus power=off, aqi=26,average_aqi=12,temperature=21.1, humidity=44%,mode=OperationMode.Idle,led=True,led_brightness=LedBrightness.Bright,buzzer=True, child_lock=False,favorite_level=10,filter_life_remaining=99, filter_hours_used=1, use_time=5400, purify_volume=54, motor_speed=0>

domoticz crash :(Image
Attachments
Képernyőfotó 2018-02-02 - 18.02.52.png
Képernyőfotó 2018-02-02 - 18.02.52.png (206.62 KiB) Viewed 2144 times

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

Re: Xiaomi Air Purifier 2

Post by kofec » Friday 02 February 2018 19:30

Please restart domoticz and copy logs and pastę here

molnaratti
Posts: 14
Joined: Friday 02 February 2018 17:21
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Air Purifier 2

Post by molnaratti » Friday 02 February 2018 19:47

Code: Select all

2018-02-02 18:44:47.505  TCPServer: shared server started...
2018-02-02 18:44:47.505  RxQueue: queue worker started...
2018-02-02 18:44:49.507  XiaomiGateway: will listen on 9898 for hardware id 3
2018-02-02 18:44:49.508  XiaomiGateway: Delaying worker startup...
2018-02-02 18:44:49.509  YeeLight Worker started...
2018-02-02 18:44:54.509  Kodi: Started
2018-02-02 18:44:54.515  OpenWeatherMap: Started
2018-02-02 18:44:54.515  (Ble) Started.
2018-02-02 18:44:54.516  (purifier) Started.
2018-02-02 18:44:54.517  EventSystem: reset all events...
2018-02-02 18:44:54.522  dzVents: Write file: /home/pi/domoticz/scripts/dzVents/generated_scripts/proba_lépcső_fel_2.lua
2018-02-02 18:44:54.523  dzVents: Write file: /home/pi/domoticz/scripts/dzVents/generated_scripts/nappali.lua
2018-02-02 18:44:54.524  EventSystem: reset all device statuses...
2018-02-02 18:44:54.525  XiaomiGateway: Worker started...
2018-02-02 18:44:54.526  XiaomiGateway: Using 192.168.1.140 for local IP address.
2018-02-02 18:44:54.613  Kodi: (OSMC) Starting thread.
2018-02-02 18:44:54.631  Kodi: (OSMC) Connected to '192.168.1.105:9090'.
2018-02-02 18:44:54.702  XiaomiGateway: RGB Gateway Detected
2018-02-02 18:44:54.713  Kodi: Starting I/O service thread.
2018-02-02 18:44:54.807  Kodi: (OSMC) Event: 'Video - The Fall [S3E1], Episode 1 (2016)'.
2018-02-02 18:44:54.947  PluginSystem: Entering work loop.
2018-02-02 18:44:55.002  (geteway) Lighting Limitless/Applamp (Geteway light)
2018-02-02 18:44:55.073  (geteway) Temp (Kint)
2018-02-02 18:44:55.080  (geteway) Humidity (kint)
2018-02-02 18:44:55.122  (geteway) Temp (Nappali)
2018-02-02 18:44:55.150  (geteway) Humidity (Nappali pára)
2018-02-02 18:44:55.180  (geteway) Light/Switch (fürdő kapcsoló)
2018-02-02 18:44:55.207  (geteway) Light/Switch (Xiaomi Wired Dual Wall Switch Channel 0)
2018-02-02 18:44:55.239  (geteway) Light/Switch (terasz kapcsoló)
2018-02-02 18:44:55.275  (geteway) Light/Switch (tv 2 kapcsolo)
2018-02-02 18:44:55.302  (geteway) Light/Switch (kanapé előtt kapcsoló)
2018-02-02 18:44:55.433  (geteway) Light/Switch (vilanyradiátor)
2018-02-02 18:44:55.461  (geteway) General/kWh (Villany radiátor fogyasztás)
2018-02-02 18:44:55.529  MQTT: Connecting to localhost:1883
2018-02-02 18:44:55.563  (geteway) Light/Switch (Nappali konnektor)
2018-02-02 18:44:55.633  MQTT: connected to: localhost:1883
2018-02-02 18:44:55.734  MQTT: Subscribed
2018-02-02 18:44:55.859  (Ble) Initialized version 0.0.2, author 'mrin'
2018-02-02 18:44:55.875  (Ble) Entering work loop.
2018-02-02 18:44:56.277  Python EventSystem: Initalizing event module.
2018-02-02 18:44:56.285  EventSystem: Queue thread started...
2018-02-02 18:44:56.293  EventSystem: Started
2018-02-02 18:44:57.760  Error: Domoticz received fatal signal 11 !...
2018-02-02 18:44:57.766  Error:   /home/pi/domoticz/domoticz() [0x245628]
2018-02-02 18:44:57.766  Error:   /home/pi/domoticz/domoticz(_Z14signal_handleri+0x4c) [0x2456e0]
2018-02-02 18:44:57.767  Error:   /lib/arm-linux-gnueabihf/libc.so.6(__default_sa_restorer+0) [0xb6c576b0]
2018-02-02 18:45:34.326  TCPServer: shared server started...
2018-02-02 18:45:34.326  RxQueue: queue worker started...
2018-02-02 18:45:36.328  XiaomiGateway: will listen on 9898 for hardware id 3
2018-02-02 18:45:36.329  XiaomiGateway: Delaying worker startup...
2018-02-02 18:45:36.330  YeeLight Worker started...
2018-02-02 18:45:41.330  Kodi: Started
2018-02-02 18:45:41.332  OpenWeatherMap: Started
2018-02-02 18:45:41.332  (Ble) Started.
2018-02-02 18:45:41.333  (purifier) Started.
2018-02-02 18:45:41.334  EventSystem: reset all events...
2018-02-02 18:45:41.338  XiaomiGateway: Worker started...
2018-02-02 18:45:41.340  XiaomiGateway: Using 192.168.1.140 for local IP address.
2018-02-02 18:45:41.343  dzVents: Write file: /home/pi/domoticz/scripts/dzVents/generated_scripts/proba_lépcső_fel_2.lua
2018-02-02 18:45:41.344  dzVents: Write file: /home/pi/domoticz/scripts/dzVents/generated_scripts/nappali.lua
2018-02-02 18:45:41.345  EventSystem: reset all device statuses...
2018-02-02 18:45:41.438  Kodi: (OSMC) Starting thread.
2018-02-02 18:45:41.451  Kodi: (OSMC) Connected to '192.168.1.105:9090'.
2018-02-02 18:45:41.539  Kodi: Starting I/O service thread.
2018-02-02 18:45:41.613  Kodi: (OSMC) Event: 'Video - The Fall [S3E1], Episode 1 (2016)'.
2018-02-02 18:45:41.768  PluginSystem: Entering work loop.
2018-02-02 18:45:42.337  MQTT: Connecting to localhost:1883
2018-02-02 18:45:42.441  MQTT: connected to: localhost:1883
2018-02-02 18:45:42.468  (Ble) Initialized version 0.0.2, author 'mrin'
2018-02-02 18:45:42.482  (Ble) Entering work loop.
2018-02-02 18:45:42.543  MQTT: Subscribed
2018-02-02 18:45:42.914  Python EventSystem: Initalizing event module.
2018-02-02 18:45:42.925  EventSystem: Queue thread started...
2018-02-02 18:45:42.926  EventSystem: Started
2018-02-02 18:45:43.882  Error: Domoticz received fatal signal 11 !...
2018-02-02 18:45:43.888  Error:   /home/pi/domoticz/domoticz() [0x245628]
2018-02-02 18:45:43.888  Error:   /home/pi/domoticz/domoticz(_Z14signal_handleri+0x4c) [0x2456e0]
2018-02-02 18:45:43.889  Error:   /lib/arm-linux-gnueabihf/libc.so.6(__default_sa_restorer+0) [0xb6c2f6b0]
delete domoticz-AirPurifier plugin and restart, no error
Domoticz Version: 3.8875

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

Re: Xiaomi Air Purifier 2

Post by kofec » Friday 02 February 2018 21:23

It looks like generic issue with python plugins. There is a lot about in forum. I'm using latest stable version

molnaratti
Posts: 14
Joined: Friday 02 February 2018 17:21
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Air Purifier 2

Post by molnaratti » Friday 02 February 2018 22:24

thank you for employing him

mozo78
Posts: 18
Joined: Friday 09 June 2017 6:29
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Air Purifier 2

Post by mozo78 » Sunday 04 February 2018 23:58

Dear kofec,

Thank you for your work! :)

I could add it, it apperars in the hw list, but the air purifier does not appear in the device list. A few seconds later in the log i can find an error message:

Error: Airpurifier hardware (32) thread seems to have ended unexpectedly

Domoticz version 3.8153 (last stable version)

From command line I can reach it:

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>

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

Re: Xiaomi Air Purifier 2

Post by kofec » Monday 05 February 2018 7:14

Try restart domoticz. Maybe something more will be in logs.

molnaratti
Posts: 14
Joined: Friday 02 February 2018 17:21
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Air Purifier 2

Post by molnaratti » Monday 05 February 2018 18:32

I was also trying to make a stable version, though it is the problem

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

Re: Xiaomi Air Purifier 2

Post by kofec » Monday 05 February 2018 18:58

Can you change debug to true

mozo78
Posts: 18
Joined: Friday 09 June 2017 6:29
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Air Purifier 2

Post by mozo78 » Tuesday 06 February 2018 9:31

kofec wrote:
Monday 05 February 2018 7:14
Try restart domoticz. Maybe something more will be in logs.
Cannot see any more error logs. But when I enable the airpurifier plugin, the Dlink connector python plugin not working any more. Also without error log. Just not working. Strange...

Good news!

A removed the whole plugin, and started again from 0. And now it is working like a charm. My dlink connector is working either.

Thank you again for your work! If you make a donate button, i will buy you a beer! ;)

DAVIZINHO
Posts: 198
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 » Saturday 03 March 2018 23:53

Hello, im trying to add more parameters to the status function but i cant.

I see that the miio library have more parameters for air purifier like "xxxxxxxxx"

i modify the airpurifier.js adding the 'filter_life_remaining' and 'filter_hours_used'
like this

Code: Select all

stats = device.getProperties([ 'power', 'mode', 'aqi', 'temperature', 'humidity', 'filter_life_remaining', 'filter_hours_used' ])
console.log(stats);
process.exit();
but not received data:

Code: Select all

pi@raspberrypi:~/Xiaomi $ sudo ./airpurifier.js 192.168.1.72 status
{ power: true,
  mode: 'auto',
  aqi: 8,
  temperature: 19.2,
  humidity: 56,
  filter_life_remaining: undefined,
  filter_hours_used: undefined }
any idea?

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

Re: Xiaomi Air Purifier 2

Post by kofec » 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>

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests