Comments (3)
Thanks! I'll update the README to be a bit clearer about subdevices not having tokens.
from miio.
Thanks for the report.
The proper way to do this via miio
is either to connect to the gateway via miio.device
or use discovery:
A call to miio.devices()
would return a browser that should find your gateway and any devices connected to it. You can filter the results and add listeners to anything that is of type controller
to listen for actions:
const devices = miio.devices({
filter: reg => reg.type == 'gateway' || reg.type == 'controller'
});
devices.on('available', reg => {
const device = reg.device;
if(! device) {
console.log(reg.id, 'could not be connected to');
return;
}
console.log('Connected to', device);
if(device.type === 'controller') {
// This is a controller such as a switch, cube or wall mounted switch
device.on('action', action => console.log(action.id));
}
});
That should get you started! To help with debugging its also a good idea to run miio --discover
to make sure that the library can see your gateway and the devices connected to it.
from miio.
This snippet works :)
But in my case, I was using the snippet examples on the main readme and it was not working because of this part :
if (!reg.token) {
console.log(reg.id, 'hides its token');
return;
}
Because all subdevices were hidding their tokens, it was always exiting before listening for action event...
Why exiting if no token ? Because finnaly even with no token, the library manage to detect devices events
Using a simpler snippet example like this would have been an easier way to start with the miio library :
const devices = miio.devices()
devices.on('available', reg => {
const device = reg.device
if (!device) {
console.log(reg.id, 'could not be connected to')
return
}
console.log('Connected to', device.type)
device.on('propertyChanged', e => console.log(device.type + ' : property "' + e.property + '" changed from ' + e.oldValue + ' to ' + e.value))
device.on('action', action => console.log(device.type + ' : action detected "' + action.id + '"'))
})
I'm not here to promote the previous library I mentioned before or any other library, it's just a feedback from a user that tryed to detect events on his chinese low cost home domotic kit π and this token part was not easy to understand.
Even the miio --discover
that I've tried was not clear in my mind how it could helped me, here is the output :
Device ID: 56xxx9
Model info: Unknown
Address: 192.168.31.137
Token: ???
Support: Unknown
Device ID: 54xxx6
Model info: Unknown
Address: 192.168.31.170
Token: 82exxxxx57e6 via auto-token
Support: Unknown
Device ID: 54xxx8
Model info: Unknown
Address: 192.168.31.54
Token: 51xxxxf9a1 via auto-token
Support: Unknown
(node:2340) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot set property 'device' of undefined
````
from miio.
Related Issues (20)
- Xiaomi Walkingpad HOT 1
- Not enough non-option arguments: got 0, need at least 1 error Command failed with exit code 1.
- Xiaomi Air Monitor cgllc.airm.cgdn1
- yeelight strip plus is supported?
- Canβt find Hub / Temperature-Sensors
- yeelink.light.color5 HOT 1
- Mi Smart LED Bulb (B22) - Support
- yeelink.light.mono6 HOT 1
- [add device request] yeelink.light.ceilb
- [add device request] yeelink.light.colorb
- -Bash: miio: command not found HOT 1
- doesn't work on Firmware version: 3.2.10
- Cannot connect to light after configuring wireless network HOT 1
- yeelink.light.bslamp2 HOT 2
- Create device with lib version >= 0.15.0
- Which devices can get tokens by "miio discover" or "mirobo discover --handshake 1"?
- Does this packge still getting maintained?
- Roborock S6 - 3.5.8._2902 - unsupported device
- colorTemperature2rgbUsingTH is not defined
- Device support [Vacum mop 2 ultra]
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from miio.