Page 2 of 5
Re: Xiaomi Air Purifier 2
Posted: Monday 19 June 2017 9:15
by mozo78
Julz wrote:Hi all,
I'm having trouble getting the bash script to feed updates via JSON to my Raspberry Pi. I can trigger the bash script manually and it seems to update the temperature sensor and PM2.5 sensor values the first time but then the temperature sensor updates to 0.0C and the PM2.5 sensor doesn't update again. I'm pretty sure I've set up the script to trigger at boot via a call to my 'startup.sh' script in my /etc/rc.local but after bootup is complete, doing a 'screen -list' doesn't show any sessions running unlike when I manually execute my startup.sh. Any suggestions?
TIA!
I had the same problem, but this helped me:
http://raspberrypituts.com/raspberry-pi ... planation/
Re: Xiaomi Air Purifier 2
Posted: Monday 10 July 2017 12:52
by ToneStrife
I have miiio working, I want to use the Wifi plugs.
I have read about power-plug and power-switch in the miio wiki but I don't know which commando should I use.
Anyone with an adapted script for the plugs can help me? I have the IPs but after that I'm a little bit stucked.
Re: Xiaomi Air Purifier 2
Posted: Sunday 27 August 2017 18:02
by DAVIZINHO
Hello,
I have a synology NAS with Node.js v4 because i don´t know how to upgrade to v6
I run this comand: "miio --discover --sync" and obtain this error:
[code]
admin@synology:~$ miio --discover --sync
/usr/local/lib/node_modules/miio/cli/index.js:10
const { Browser, Devices } = require('../lib/discovery');
^
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:140:18)
at node.js:1043:3
admin@synology:~$
[/code]
any idea??
thanks a lot and sorry for my poor english

Re: Xiaomi Air Purifier 2
Posted: Tuesday 19 September 2017 11:23
by DAVIZINHO
hello,
Its imposible to me make this works in:
- synology: I cant upgrade the node.js

- raspberry pi zero: the miio not works
But it works perfect for me in a raspberry pi2 with raspbian!!

Re: Xiaomi Air Purifier 2
Posted: Wednesday 04 October 2017 10:47
by Andree
hi,there's a way to making this work on Windows?
Re: Xiaomi Air Purifier 2
Posted: Sunday 22 October 2017 20:16
by tho071088
Hello,
I'm having some problems :
This works :
/var/domoticz/scripts/external/xiaomiAirPurifierControl.sh 192.168.0.55 off
sudo /var/domoticz/scripts/external/xiaomiAirPurifierControl.sh 192.168.0.55 off
This does not work :
Pushing the button on Domoticz
I don't have any errors thrown in the log.

- Capture d’écran 2017-10-22 à 20.13.53.png (98.92 KiB) Viewed 5609 times

- Capture d’écran 2017-10-22 à 20.13.28.png (14.76 KiB) Viewed 5609 times
Any ideas ?
Thanks for your help

Re: Xiaomi Air Purifier 2
Posted: Tuesday 24 October 2017 22:45
by tho071088
New problem for me :
Domoticz:/var/domoticz/scripts/external/xiaomiAirPurifier.js 192.168.0.55 power off
Sending Power off command
(node:21561) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): SyntaxError: Unexpected token o in JSON at position 0
No idea what to do with this.
Any advise ?
Re: Xiaomi Air Purifier 2
Posted: Wednesday 25 October 2017 6:41
by tho071088
All solved
tho071088 wrote: ↑Tuesday 24 October 2017 22:45
New problem for me :
Domoticz:/var/domoticz/scripts/external/xiaomiAirPurifier.js 192.168.0.55 power off
Sending Power off command
(node:21561) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): SyntaxError: Unexpected token o in JSON at position 0
No idea what to do with this.
Any advise ?
This one was my fault, wrong command sent.
For the other one, I had to make the require this way :
Not working :
const miio = require('miio');
Working :
const miio = require('../../../../usr/lib/node_modules/miio');
Re: Xiaomi Air Purifier 2
Posted: Wednesday 25 October 2017 14:36
by MsbS
tho071088 wrote: ↑Wednesday 25 October 2017 6:41
For the other one, I had to make the require this way :
Not working :
const miio = require('miio');
Working :
const miio = require('../../../../usr/lib/node_modules/miio');
Could you replace the relative path ('../..') with a single / ? Basically :
const miio = require('/usr/lib/node_modules/miio');
For me the script from the first post does nothing - I ran the miio sync command (got no output), when I run the examples with 'node airpurifier.js IP command', nothing happens.
Re: Xiaomi Air Purifier 2
Posted: Wednesday 25 October 2017 14:42
by tho071088
MsbS wrote: ↑Wednesday 25 October 2017 14:36
tho071088 wrote: ↑Wednesday 25 October 2017 6:41
For the other one, I had to make the require this way :
Not working :
const miio = require('miio');
Working :
const miio = require('../../../../usr/lib/node_modules/miio');
Could you replace the relative path ('../..') with a single / ? Basically :
const miio = require('/usr/lib/node_modules/miio');
For me the script from the first post does nothing - I ran the miio sync command (got no output), when I run the examples with 'node airpurifier.js IP command', nothing happens.
No, just a / will not work, already tried
If nothing is displayed, you have to add some lines to the JS file.
process.on('uncaughtException', function (error) {
console.log(error.stack);
});
Re: Xiaomi Air Purifier 2
Posted: Wednesday 25 October 2017 16:01
by Andree
Sorry, there is no way for Windows?
Re: Xiaomi Air Purifier 2
Posted: Thursday 26 October 2017 9:31
by MsbS
tho071088 wrote: ↑Wednesday 25 October 2017 14:42
If nothing is displayed, you have to add some lines to the JS file.
process.on('uncaughtException', function (error) {
console.log(error.stack);
});
Unfortunately, this did not help. I think there's something wrong with node or with miio in my case.
- when I tried 'npm install --save miio', I got a whole lot of errors.
- doing this with sudo ('sudo npm install --save miio') worked, but I still got warning about the version of node:
Code: Select all
wanted: {"node":">=6.0.0"} (current: {"node":"4.8.2","npm":"1.4.21"})
- When I run 'miio --discover --sync', it gives me no output at all, where can I find a logfile to check what went wrong?
Re: Xiaomi Air Purifier 2
Posted: Thursday 26 October 2017 9:47
by tho071088
MsbS wrote: ↑Thursday 26 October 2017 9:31
tho071088 wrote: ↑Wednesday 25 October 2017 14:42
If nothing is displayed, you have to add some lines to the JS file.
process.on('uncaughtException', function (error) {
console.log(error.stack);
});
Unfortunately, this did not help. I think there's something wrong with node or with miio in my case.
- when I tried 'npm install --save miio', I got a whole lot of errors.
- doing this with sudo ('sudo npm install --save miio') worked, but I still got warning about the version of node:
Code: Select all
wanted: {"node":">=6.0.0"} (current: {"node":"4.8.2","npm":"1.4.21"})
- When I run 'miio --discover --sync', it gives me no output at all, where can I find a logfile to check what went wrong?
You have to update node a new version.
Try
sudo apt-get update && sudo apt-get upgrade && sudo apt-get install node
Are you on Raspbian Jessie ?
Re: Xiaomi Air Purifier 2
Posted: Thursday 26 October 2017 10:17
by MsbS
tho071088 wrote: ↑Thursday 26 October 2017 9:47
You have to update node a new version.
Try
sudo apt-get update && sudo apt-get upgrade && sudo apt-get install node
Are you on Raspbian Jessie ?
I'm on Raspbian Stretch - the newer one. Did update, upgrade, install. I get: 'node is already the newest version (0.3.2-7.4).'
Re: Xiaomi Air Purifier 2
Posted: Thursday 26 October 2017 10:35
by tho071088
MsbS wrote: ↑Thursday 26 October 2017 10:17
tho071088 wrote: ↑Thursday 26 October 2017 9:47
You have to update node a new version.
Try
sudo apt-get update && sudo apt-get upgrade && sudo apt-get install node
Are you on Raspbian Jessie ?
I'm on Raspbian Stretch - the newer one. Did update, upgrade, install. I get: 'node is already the newest version (0.3.2-7.4).'
I'm on Jessie and node 6, there is maybe an issue with miio and node 7.
This is outside of my skills, sorry.
Re: Xiaomi Air Purifier 2
Posted: Thursday 26 October 2017 13:00
by MsbS
OK, I think I have this sorted out. I'll leave it here for others who can be struggling.
The key was to install the correct version of nodejs, as per this page:
https://nodejs.org/en/download/package- ... tributions
So, running:
curl -sL
https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
Re: Xiaomi Air Purifier 2
Posted: Friday 03 November 2017 19:17
by DAVIZINHO
hello.
what kind of virtual sensors you create for aqi?
i can obtain the aqi data but not works the update to domoticz comand. allways 0
curl -s "
http://192.168.1.4:8080/json.htm?type=c ... alue=${aqi}"
any idea?
Re: Xiaomi Air Purifier 2
Posted: Friday 03 November 2017 20:44
by tho071088
Custom Sensor type worked for me
Re: Xiaomi Air Purifier 2
Posted: Friday 03 November 2017 20:49
by DAVIZINHO
tho071088 wrote: ↑Friday 03 November 2017 20:44
Custom Sensor type worked for me
Works! thanks!
Re: Xiaomi Air Purifier 2
Posted: Monday 06 November 2017 11:29
by MsbS
My Purifier (using the script from this thread) sometimes sends strange values to the T+H IDX (temperature 0, humidity 0). Did anyone have similar issue? For now, I added an 'if', which does not send the 0/0 data, but maybe there is a better fix.
The aqi reading is correct, no strange values (unless the reading of 10 aqi means broken data - I get that a lot).