Page 1 of 1
Xiaomi PM 2.5 detector
Posted: Tuesday 21 November 2017 4:05
by Slokoavac
Hi,
anyone managed to add support for Xiaomi PM 2.5 detector (
https://www.gearbest.com/living-applian ... 57543.html)?
It's a standalone laser PM 2.5 detector, same as found integrated in Xiaomi Air purifier pro.
I have installed miio and got token id. Not sure i can edit airpurifier.js and make it work. Anyone tried it yet?
cheers
Re: Xiaomi PM 2.5 detector
Posted: Tuesday 28 November 2017 1:36
by Slokoavac
Device works without token. So i can use miio lib to pull data and control the device. Do not have much experience with scripts for Domoticz.
I can get data when using:
Code: Select all
miio --control 192.168.0.180 --method get_prop --params '["aqi"]'
i get:
INFO Attempting to control 192.168.0.180
INFO Got result:
[
38
]
38 is AQI value and i should pull data lets say every 15sec.
Also i can turn it on and off
Code: Select all
miio --control 192.168.0.180 --method set_power --params '["off"]'
miio --control 192.168.0.180 --method set_power --params '["on"]'
Now not sure, since i am not that great with coding, how to put this into virtual sensors for domoticz. I guess virtual switch can run bash script for on and off, but how to put AQI data? json web cmd to idx of the virtual sensor?
sorry, i am pretty new to domoticz

Re: Xiaomi PM 2.5 detector
Posted: Thursday 14 December 2017 20:23
by Slokoavac
I made virtual switch and i can now turn it on and off via bash scripts, but i still do not know how can i enter AQI value in the virtual sensor in domoticz
I know cmd to do it via curl, but how to define AQI variable with miio?
Code: Select all
curl -s "http://192.168.0.155:8080/json.htm?type=command¶m=udevice&idx=33&nvalue=${aqi}"
Re: Xiaomi PM 2.5 detector
Posted: Friday 15 December 2017 0:34
by Slokoavac
So i made it somehow
Edited node js script from github user and used bash script (borrowed from Ben's Xiaomi Purifier 2 script).
node js script (node pm25b.js)
Code: Select all
const miio = require('miio');
const fs = require('fs');
const logger = fs.createWriteStream('log.txt', { flags: 'a' });
const devices = miio.devices({ cacheTime: 30 });
devices.on('available', reg => {
const device = reg.device;
if (!device) {
// console.log();
return;
}
if (device.model == 'zhimi.airmonitor.v1') {
device.defineProperty('aqi');
device.on('propertyChanged', e => {
var output = e.value;
console.log(output);
logger.write(output + "\r\n");
});
device.monitor();
setTimeout(function(){
process.exit();
}, 4000);
}
});
bash script (pm25aqi.sh)
Code: Select all
#!/bin/bash
true; do
# Get the data
data=$(sudo node pm25b.js)
sleep 5
# Load it into Domoticz
echo $data
curl -s "http://192.168.0.155:8080/json.htm?type=command¶m=udevice&idx=33&nvalue=0&svalue=${data}"
finally crone job to run bash script (every minute)
Code: Select all
*/1 *, * * * * cd /home/pi/domoticz/scripts/ && sh pm25aqi.sh