miio
miio copied to clipboard
Getting value from Motion Sensor
I am trying to get state and motion values from the Mi Aqara 2 Motion Sensor but have no luck doing so. I only got null for motion, illuminance and -1 for battery level.
Can someone pls help or point me in the right direction?
This is my code so far. I have saved the token in token.json file.
const miio = require('miio');
var token = '*********************************' //gateway
var address = '***.***.***.***' // gateway
// var address='***.***.***.***' lightstrip
var sensorId = '************';
miio.device({ address: address })
.then(device => {
for (d of device.children()) {
if(d.internalId==sensorId){
console.log('Connected to', d.metadata);
// d.on('motionChanged').then(data => console.log(data)).catch(console.error);
// d.illuminance().then(data => console.log(data)).catch(console.error);
// d.state().then(data => console.log(data)).catch(console.error);
// console.log(d.illuminance());
// console.log(d.motion());
}
}
})
The Aqara motion sensor is a Zigbee device. How did you get an IP address for address
? Zigbee is not IP-based...