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
Xiaomi PM 2.5 detector
Moderator: leecollings
-
- Posts: 14
- Joined: Monday 20 November 2017 15:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.8153
- Location: Balkans
- Contact:
Xiaomi PM 2.5 detector
Pi 2 (raspbian stretch) w. Conrad VOC USB, Xiaomi PM 2.5 detector , Xiaomi/Philips bulbs, Mi Flora BT, Xiaomi GW (w. temp/humidity/pir)
Pi Zero W (raspbian stretch) w. - Xiaomi GW (temp/hum/door)
Pi Zero W (raspbian stretch) w. - Xiaomi GW (temp/hum/door)
-
- Posts: 14
- Joined: Monday 20 November 2017 15:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.8153
- Location: Balkans
- Contact:
Re: Xiaomi PM 2.5 detector
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:
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
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
I can get data when using:
Code: Select all
miio --control 192.168.0.180 --method get_prop --params '["aqi"]'
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"]'
sorry, i am pretty new to domoticz
Pi 2 (raspbian stretch) w. Conrad VOC USB, Xiaomi PM 2.5 detector , Xiaomi/Philips bulbs, Mi Flora BT, Xiaomi GW (w. temp/humidity/pir)
Pi Zero W (raspbian stretch) w. - Xiaomi GW (temp/hum/door)
Pi Zero W (raspbian stretch) w. - Xiaomi GW (temp/hum/door)
-
- Posts: 14
- Joined: Monday 20 November 2017 15:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.8153
- Location: Balkans
- Contact:
Re: Xiaomi PM 2.5 detector
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?
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}"
Pi 2 (raspbian stretch) w. Conrad VOC USB, Xiaomi PM 2.5 detector , Xiaomi/Philips bulbs, Mi Flora BT, Xiaomi GW (w. temp/humidity/pir)
Pi Zero W (raspbian stretch) w. - Xiaomi GW (temp/hum/door)
Pi Zero W (raspbian stretch) w. - Xiaomi GW (temp/hum/door)
-
- Posts: 14
- Joined: Monday 20 November 2017 15:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.8153
- Location: Balkans
- Contact:
Re: Xiaomi PM 2.5 detector
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)
bash script (pm25aqi.sh)
finally crone job to run bash script (every minute)
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}"
Code: Select all
*/1 *, * * * * cd /home/pi/domoticz/scripts/ && sh pm25aqi.sh
Pi 2 (raspbian stretch) w. Conrad VOC USB, Xiaomi PM 2.5 detector , Xiaomi/Philips bulbs, Mi Flora BT, Xiaomi GW (w. temp/humidity/pir)
Pi Zero W (raspbian stretch) w. - Xiaomi GW (temp/hum/door)
Pi Zero W (raspbian stretch) w. - Xiaomi GW (temp/hum/door)
Who is online
Users browsing this forum: Xenon and 1 guest