GithubHelp home page GithubHelp logo

aholstenson / miio Goto Github PK

View Code? Open in Web Editor NEW
1.8K 88.0 350.0 366 KB

Control Mi Home devices, such as Mi Robot Vacuums, Mi Air Purifiers, Mi Smart Home Gateway (Aqara) and more

License: MIT License

JavaScript 100.00%
miio-protocol home-automation mi-home xiaomi aqara yeelight mijia miio

miio's Introduction

👋 Hi, I'm Andreas Holstenson

I work with user-centered problem solving using technology. You'll find me in Malmö, Sweden.

I enjoy building things and over the years on GitHub I've pushed 6353 commits, opened 45 issues and submitted 38 PRs. There's currently 25 repositories around here with 2018 stars.

Want to get in touch? Send me an e-mail at [email protected] or connect with me on LinkedIn.

miio's People

Contributors

aholstenson avatar ben423423n32j14e avatar dy-sh avatar einstweilenhier avatar fdgogogo avatar gromina avatar maxmouchet avatar nicoh88 avatar pieter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

miio's Issues

out of control

Hello aholstenson

I raised an issue in homebridge-miio,my mi-plug is out of control and the detail described in #19.

Below is my inspection log for the plug.
Thanks for your help.

Device ID: 351685
Model info: chuangmi.plug.v1 (power-plug)
Address: 192.168.1.102 (chuangmi-plug-v1_miio351685.lan)
Token: 15a04af260ef7cce0edcf6cca5f09e6c via auto-token
Support: At least basic

Firmware version: 1.2.4_7
Hardware version: MC200

WiFi: L Wi-Fi (70:73:CB:B9:AA:8F) RSSI: -51
WiFi firmware version: SD878x-14.76.36.p79-702.1.0-WM

Remote access (Mi Home App): UDP

Properties:

  • powerChannelMain: false
  • power: { main: false, usb: false }
  • powerChannelUsb: false

Commands for Mi Robot time out on latest Mi Robot firmware

I recently updated to the latest firmware of the Mi Robot (3.3.9_003077). After the update pretty much all commands send using this miio library are timing out. It seems with this firmware update the Mi Robot would benefit from a longer time out configuration when sending the requests.

λ miio --discover
 INFO  Discovering devices. Press Ctrl+C to stop.

Device ID: 51xx03
Model info: Unknown
Address: 192.168.0.133 (Mi-Robot)
Token: 46625a3xxxx66747948 via stored token
Support: Unknown

λ miio --inspect 51xx03
 INFO  Attempting to inspect 51xx03
 WARNING  Could not find device

My network is fine, using the Mi Home app the reaction is instant.

is it possible to disable gateway discovery and minitoring?

i am using homebridge-aqara to control ctrl_neutral1 and get sensor data from temperature, humidity and motion status, and using homebridge-miio to control chuangmi.plug.m1 and zimi.powerstrip.v2. i found a strange thing, at night my ctrl_neutral1 switch and motion sensor will disappear from home app, and if motion sensor is triggered or trun on ctrl_neutral1 switch, ctrl_neutral1 and motion sensor will come back to home app, but it will revert to default name with some hex digit and default room.
i turn on debug and found no error. is it possible that miio library conflicts with homebridge-aqara plugin?
is it possible to disable gateway discovery and minitoring, so i can do a test?

PS: homebridge-miio plugin version is 0.2.1 and miio library version is 0.7.0.

Can't set option containing underscore

The humidifier has options containing an underscore which appears to cause a problem with miio, example:

return device.call('set_led_b', ['bright']

Error output when attempting the above:

{ Error
at Object.reject (/root/node_modules/miio/lib/device.js:213:13)
at Device._onMessage (/root/node_modules/miio/lib/device.js:104:8)
at emitTwo (events.js:106:13)
at Socket.emit (events.js:192:7)
at UDP.onMessage [as onmessage] (dgram.js:547:8) code: -5001 }

Xiaomi Mi Smart Socket - Can't change state

Hi,

I am trying to control my Xiamo Mi Smart Socket but I can't seem to be able to turn the plug on or off.

Output of miio --inspect 192.168.xx.xxx

 INFO  Attempting to inspect 192.168.xx.xxx

Device ID: 45286364
Model info: chuangmi.plug.m1 (power-plug)
Address: 192.168.xx.xxx (chuangmi-plug-m1_miio4528xxxx)
Token: 0480404f6870c4d2e0ea19271d1e4261 via auto-token
Support: At least basic

Firmware version: 1.2.4_17
Hardware version: MW300

WiFi: xxxxx (00:60:64:E1:xx:xx) RSSI: -58
WiFi firmware version: SD878x-14.76.36.p84-702.1.0-WM

Remote access (Mi Home App): TCP

Properties:
  - powerChannel0: false
  - power: { '0': false }

But when I execute the following script, it runs forever without returinng any error:

const miio = require('miio');

// Create a new device over the given address
miio.device({
	address: '192.168.xx.xxx' , token: '0480404f6870c4d2e0ea19271d1e4261'
}).then(device => {
	if(device.hasCapability('power')) {
		console.log('power is now', device.power);
		return device.setPower(! device.power);
	}
}).catch(console.error);

I have discovered the token by re-initiating my plug and running miio --discover while I was connecting to the plug wifi. I then finished to set up the plug through my iPhone.

/usr/bin/env: node: No such file or directory

Hello,
I`m trying to integrate my Xiaomi Air Purifier with Domoticz. Followed the instructions to install miio device library and command line utility:

root@stf-pi:/usr/local# npm install --save miio npm WARN engine [email protected]: wanted: {"node":">=6.0.0"} (current: {"node":"0.10.29","npm":"1.4.21"}) [email protected] node_modules/miio ├── [email protected] ├── [email protected] ├── [email protected] ([email protected]) ├── [email protected] ([email protected]) └── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected]) root@stf-pi:/usr/local# ls bin etc games include lib man node_modules sbin share src root@stf-pi:/usr/local# npm install -g miio npm WARN engine [email protected]: wanted: {"node":">=6.0.0"} (current: {"node":"0.10.29","npm":"1.4.21"}) /usr/local/bin/miio -> /usr/local/lib/node_modules/miio/cli/index.js [email protected] /usr/local/lib/node_modules/miio ├── [email protected] ├── [email protected] ├── [email protected] ([email protected]) ├── [email protected] ([email protected]) └── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
Not sure how to interpret this output. Unfortunately when trying to discover the device:
root@stf-pi:/usr/local# miio --discover --sync /usr/bin/env: node: No such file or directory
What am I missing? Unfortunately my linux knowledge is limited.

device.init not reject

when i use this way to connect vacuum,
device.init() .then(() => /* device is ready for commands */) .catch(console.error);
it always call then,not catch when error happen ,like ip address is not corrent.

how to control yeelight device

hello,how can i control yeelight device?
is it auto-token?
will i config the token myself?

why there is not set_rgb,set_mode.. method etc.

feature request: initialise without monitoring

It currently isn't possible to initialise devices without activating the monitor function. I think monitor should not be activated until an application binds to one of the interfaces which requires it, so it doesn't generate extra traffic when users have no interest in the monitor feature.

At a minimum, the monitor function shouldn't run _loadProperties() until a timeout/interval/process.nextTick executes, so users have a chance to stopMonitoring() after initialising a device, before it starts generating network traffic.

Air Purifier 2 set_mode options (high, medium and low do not work)

Just gave this library a quick 15 minute play around. Don't have any mobile emulators at the moment. I'll download and set one up some time this week.

Modes that do no longer seem to work are: low, medium and high. Which makes some sense since the UI on the app in iOS doesn't have these sort of options?

on status shows wrong with chuangmi-plug-v1

i am using homebridge-miio plugin, which is using the miio lib .From homekit , I can turn on or turn off the plugin , but once I turn on it ,after a while it will show off status even it's on . Looks like it somehow failed fetch the up status.

from the miio lib ,it says at least basic, not sure if this is the case. I am rasie the issue in here now.
since this is the issue that I met when I use this module
Device ID: 937021
Model info: chuangmi.plug.v1 (power-plug)
Address: 192.168.88.18 (chuangmi-plug-v1_miio937021)
Token: a6ab080d5223bdbc73fbf572ef8388dc via auto-token
Support: At least basic

here is the log

May 31 13:54:07 stevenhomesmart homebridge[20969]: [5/31/2017, 1:54:07 PM] [XiaomiMiio] miIO Plug 937021 fetch status
May 31 13:54:44 stevenhomesmart homebridge[20969]: [5/31/2017, 1:54:44 PM] [XiaomiMiio] miIO Plug 937021 fetch status
May 31 13:58:07 stevenhomesmart homebridge[20969]: [5/31/2017, 1:58:07 PM] [XiaomiMiio] miIO Plug 937021 fetch status
May 31 14:00:58 stevenhomesmart homebridge[20969]: [5/31/2017, 2:00:58 PM] [XiaomiMiio] miIO Plug 937021 fetch status
May 31 14:04:05 stevenhomesmart homebridge[20969]: [5/31/2017, 2:04:05 PM] [XiaomiMiio] miIO Plug 937021 fetch status
May 31 14:08:48 stevenhomesmart homebridge[20969]: [5/31/2017, 2:08:48 PM] [XiaomiMiio] miIO Plug 937021 fetch status
May 31 14:11:36 stevenhomesmart homebridge[20969]: [5/31/2017, 2:11:36 PM] [XiaomiMiio] miIO Plug 937021 fetch status
May 31 14:11:40 stevenhomesmart homebridge[20969]: [5/31/2017, 2:11:40 PM] [XiaomiMiio] miIO Plug 937021 power to 1
May 31 14:13:03 stevenhomesmart homebridge[20969]: [5/31/2017, 2:13:03 PM] [XiaomiMiio] miIO Plug 937021 fetch status
May 31 14:13:04 stevenhomesmart homebridge[20969]: [5/31/2017, 2:13:04 PM] [XiaomiMiio] miIO Plug 937021 power to 1

enabled the debug log yesterday, from the debug log ,it seems able to fetch the status correct

May 30 23:53:10 stevenhomesmart homebridge[5975]: [5/30/2017, 11:53:10 PM] [XiaomiMiio] miIO Plug 937021 fetch status
May 30 23:53:10 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:53:10 GMT miio.device.937021 -> (3) {"id":3543,"method":"get_prop","params":["power"]}
May 30 23:53:10 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:53:10 GMT miio.device.937021 <- Message: {"result":["on"],"id":3543}
May 30 23:53:16 stevenhomesmart homebridge[5975]: [5/30/2017, 11:53:16 PM] [XiaomiMiio] miIO Plug 937021 power to 1
May 30 23:53:16 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:53:16 GMT miio.device.937021 -> (3) {"id":3544,"method":"set_on","params":[]}
May 30 23:53:16 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:53:16 GMT miio.device.937021 <- Message: {"result":0,"id":3544}
May 30 23:53:16 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:53:16 GMT miio.device.937021 -> (3) {"id":3545,"method":"get_prop","params":["power"]}
May 30 23:53:16 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:53:16 GMT miio.device.937021 <- Message: {"result":["on"],"id":3545}
May 30 23:53:31 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:53:31 GMT miio.device.937021 -> (3) {"id":3546,"method":"get_prop","params":["power"]}
May 30 23:53:32 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:53:32 GMT miio.device.937021 <- Message: {"result":["on"],"id":3546}
May 30 23:53:32 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:53:32 GMT miio.device.937021 -> (3) {"id":3547,"method":"get_prop","params":["on","usb_on"]}
May 30 23:53:32 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:53:32 GMT miio.device.937021 <- Message: {"result":[true,true],"id":3547}
May 30 23:53:46 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:53:46 GMT miio.device.937021 <- Handshake reply: <Buffer a6 ab 08 0d 52 23 bd bc 73 fb f5 72 ef 83 88 dc>
May 30 23:53:46 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:53:46 GMT miio.device.937021 -> (3) {"id":3548,"method":"get_prop","params":["power"]}
May 30 23:53:46 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:53:46 GMT miio.device.937021 <- Message: {"result":["on"],"id":3548}
May 30 23:54:01 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:54:01 GMT miio.device.937021 -> (3) {"id":3549,"method":"get_prop","params":["power"]}
May 30 23:54:01 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:54:01 GMT miio.device.937021 <- Message: {"result":["on"],"id":3549}
May 30 23:54:02 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:54:02 GMT miio.device.937021 -> (3) {"id":3550,"method":"get_prop","params":["on","usb_on"]}
May 30 23:54:02 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:54:02 GMT miio.device.937021 <- Message: {"result":[true,true],"id":3550}
May 30 23:54:16 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:54:16 GMT miio.device.937021 -> (3) {"id":3551,"method":"get_prop","params":["power"]}
May 30 23:54:16 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:54:16 GMT miio.device.937021 <- Message: {"result":["on"],"id":3551}
May 30 23:54:31 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:54:31 GMT miio.device.937021 -> (3) {"id":3552,"method":"get_prop","params":["power"]}
May 30 23:54:31 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:54:31 GMT miio.device.937021 <- Message: {"result":["on"],"id":3552}
May 30 23:54:32 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:54:32 GMT miio.device.937021 -> (3) {"id":3553,"method":"get_prop","params":["on","usb_on"]}
May 30 23:54:32 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:54:32 GMT miio.device.937021 <- Message: {"result":[true,true],"id":3553}
May 30 23:54:47 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:54:47 GMT miio.device.937021 <- Handshake reply: <Buffer a6 ab 08 0d 52 23 bd bc 73 fb f5 72 ef 83 88 dc>
May 30 23:54:47 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:54:47 GMT miio.device.937021 -> (3) {"id":3554,"method":"get_prop","params":["power"]}
May 30 23:54:47 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:54:47 GMT miio.device.937021 <- Message: {"result":["on"],"id":3554}
May 30 23:55:01 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:55:01 GMT miio.device.937021 -> (3) {"id":3555,"method":"get_prop","params":["power"]}
May 30 23:55:01 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:55:01 GMT miio.device.937021 <- Message: {"result":["on"],"id":3555}
May 30 23:55:02 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:55:02 GMT miio.device.937021 -> (3) {"id":3556,"method":"get_prop","params":["on","usb_on"]}
May 30 23:55:02 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:55:02 GMT miio.device.937021 <- Message: {"result":[true,true],"id":3556}
May 30 23:55:16 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:55:16 GMT miio.device.937021 -> (3) {"id":3557,"method":"get_prop","params":["power"]}
May 30 23:55:16 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:55:16 GMT miio.device.937021 <- Message: {"result":["on"],"id":3557}
May 30 23:55:31 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:55:31 GMT miio.device.937021 -> (3) {"id":3558,"method":"get_prop","params":["power"]}
May 30 23:55:31 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:55:31 GMT miio.device.937021 <- Message: {"result":["on"],"id":3558}
May 30 23:55:32 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:55:32 GMT miio.device.937021 -> (3) {"id":3559,"method":"get_prop","params":["on","usb_on"]}
May 30 23:55:32 stevenhomesmart homebridge[5975]: Tue, 30 May 2017 23:55:32 GMT miio.device.937021 <- Message: {"result":[true,true],"id":3559}

maybe some bug here ,will check it tomorrow, if I have time, if not ,hope someone can take a look ,as I pretty much provide everything you need for debug

[Request] Hue and Saturation for Yeelight Color bulb

According to someone from the Xiaomi Yeelight staff there is an interface to change hue and saturation for the Yeelight Color bulbs. Would be nice if this could be added to the YeelightColor class next to the setRGB (which seems to be undocumented in the device documentation).

My Yeelight Color bulb is still on transport from China so cant check if this interface is exposed though.

set_power function doesn't work in zhimi.airpurifier.v1

tried the power plug ,works fine, but the same function doesn't work in zhimi,airpurifier.v1 from the document ,it says have't tested, trying hookup it with homebridge-miio, but if miio doesn't support it ,then homebridge-miio wont' work for sure.

any idea?

####here is my device
Device ID: 45531555
Model info: zimi.powerstrip.v2 (power-strip)
Address: 192.168.88.55 (zimi-powerstrip-v2_miio45531555)
Token: 4407cd577d6f7787fd63a759fc9fdf95 via auto-token
Support: At least basic

Device ID: 937021
Model info: chuangmi.plug.v1 (power-plug)
Address: 192.168.88.18 (chuangmi-plug-v1_miio937021)
Token: a6ab080d5223bdbc73fbf572ef8388dc via auto-token
Support: At least basic

Device ID: 52786
Model info: zhimi.airpurifier.v1 (air-purifier)
Address: 192.168.88.23 (zhimi-airpurifier-v1_miio52786)
Token: 0cc749b4c2124fc67f435e93c0045378 via auto-token
Support: At least basic

the script output

pi@stevenhomesmart:/Git/temp $ node set.js 192.168.88.23 power on
{ Error: Method set_power is not supported
at Object.reject (/usr/lib/node_modules/miio/lib/device.js:213:13)
at AirPurifier._onMessage (/usr/lib/node_modules/miio/lib/device.js:104:8)
at emitTwo (events.js:106:13)
at Socket.emit (events.js:191:7)
at UDP.onMessage (dgram.js:549:8) code: -10000 }
pi@stevenhomesmart:
/Git/temp $ ls^C
pi@stevenhomesmart:/Git/temp $ node set.js 192.168.88.55 power on
[ 'ok' ]
pi@stevenhomesmart:
/Git/temp $ node set.js 192.168.88.18 power on
[ 'ok' ]
pi@stevenhomesmart:/Git/temp $ node set.js 192.168.88.18 power off
[ 'ok' ]
pi@stevenhomesmart:
/Git/temp $

here is the script that i use

#!/usr/bin/node
/* eslint-disable */

// Location of miio node lib
const miio = require('miio');

// No need to change any lines in this section
var deviceip = process.argv[2];
var secondarg = process.argv[3];
var thirdarg = process.argv[4];
function exit() {
process.exit(-1);
}

// Power On (on / off specified as on or off)
if ( secondarg === "power" ) {
setTimeout(exit, 7000);
miio.device({
address: deviceip
}).then(device => {
return device.call('set_power', [thirdarg])
.then(console.log)
.catch(console.error);
})}

// Status
if ( secondarg === "status" ) {
setTimeout(exit, 7000);
miio.device({
address: deviceip
}).then(device => {
return device.call('get_prop', ["humidity","temp_dec","power","mode","led_b","buzzer","child_lock","limit_hum","trans_level"])
.then(console.log)
.catch(console.error);
})}

// Status temperature and humidity only
if ( secondarg === "status2" ) {
setTimeout(exit, 7000);
miio.device({
address: deviceip
}).then(device => {
return device.call('get_prop', ["temp_dec","humidity"])
.then(console.log)
.catch(console.error);
})}

// Set mode (silent, medium or high)
if ( secondarg === "mode" ) {
setTimeout(exit, 7000);
miio.device({
address: deviceip
}).then(device => {
return device.call('set_mode', [thirdarg])
.then(console.log)
.catch(console.error);
})}

// Set buzzer (on or off)
if ( secondarg === "buzzer" ) {
setTimeout(exit, 7000);
miio.device({
address: deviceip
}).then(device => {
return device.call('set_buzzer', [thirdarg])
.then(console.log)
.catch(console.error);
})}

// led
if ( secondarg === "led" ) {
setTimeout(exit, 7000);
miio.device({
address: deviceip
}).then(device => {
return device.call('set_led_b', [JSON.parse(thirdarg)])
.then(console.log)
.catch(console.error);
})}

// Humidity limit percent (specified as 40, 50, 60, 70 or 80)
if ( secondarg === "humiditylimit" ) {
setTimeout(exit, 7000);
miio.device({
address: deviceip
}).then(device => {
return device.call('set_limit_hum', [JSON.parse(thirdarg)])
.then(console.log)
.catch(console.error);
})}

Catch crypto errors on incoming packets

When UDP packets are received, miio should check for failures decrypting the packet, and discard invalid packets, possibly with some debugging api or mode to make these errors visible again. My homebridge-miio instance just crashed inexplicably because of this. I guess some other network app may have sent in to the local port accidentally.

crypto.js:157
  var ret = this._handle.final();
                         ^

Error: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt
    at Decipheriv.final (crypto.js:157:26)
    at Packet.set raw [as raw] (homebridge-miio/node_modules/miio/packet.js:98:14)
    at Device._onMessage (homebridge-miio/node_modules/miio/device.js:33:19)
    at emitTwo (events.js:106:13)
    at Socket.emit (events.js:192:7)
    at UDP.onMessage [as onmessage] (dgram.js:547:8)

Getting blank subdevice from gateway

i initialized the gateway successfully ,but there is no sub devices in the array. i can ensure there is sub device has connect with the gateway. thanks.

":"function lookup4(address, callback) {\n return lookup(address || '127.0.0.1', 4, callback);\n}","owner":"#"},"_receiving":false,"_bindState":1,"type":"udp4","fd":null,"_reuseAddr":true},"devices":[]}}
1: this.device.devices = []

monitor's error handler throws errors

On node v7.5.0 with miio v0.4.0:

(node:937) TypeError: Cannot read property 'stack' of undefined
    at getProperties.then.catch.err (node_modules/miio/device.js:193:44)
(node:937) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
    at emitWarning (internal/process/promises.js:69:15)
    at emitPendingUnhandledRejections (internal/process/promises.js:86:11)
    at runMicrotasksCallback (internal/process/next_tick.js:61:9)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)
(node:937) TypeError: Cannot read property 'stack' of undefined
    at getProperties.then.catch.err (node_modules/miio/device.js:193:44)

This code has been moved in the current head but still exists at https://github.com/aholstenson/miio/blob/master/device.js#L240

Unhandled promise rejection

homebridge-miio have some error log, it throw from your miio module? ☘️

[5/22/2017, 8:35:42 PM] [homebridge-miio.XiaomiMiio] Couldn't investigate device { id: 56301635,
  address: '192.168.0.101',
  port: 54321,
  token: '00000000000000000000000000000000',
  lastSeen: 1495456538258,
  writeOnly: true } Error: Timeout
    at _ensureToken.then (/usr/lib/node_modules/homebridge-miio/node_modules/miio/lib/device.js:223:23)
(node:1970) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'model' of undefined
[5/22/2017, 8:35:42 PM] [homebridge-miio.XiaomiMiio] Couldn't investigate device { id: 48607372,
  address: '192.168.0.107',
  port: 54321,
  token: '6eccb9043ba1af9de7359c6ff7733eec',
  lastSeen: 1495456538260,
  writeOnly: true } Error: Timeout
    at _ensureToken.then (/usr/lib/node_modules/homebridge-miio/node_modules/miio/lib/device.js:223:23)
[5/22/2017, 8:35:42 PM] [homebridge-miio.XiaomiMiio] Couldn't investigate device { id: 52811490,
  address: '192.168.0.108',
  port: 54321,
  token: '19533b578d009fc04ae67293ea3ad662',
  lastSeen: 1495456538261,
  writeOnly: true } Error: Timeout
    at _ensureToken.then (/usr/lib/node_modules/homebridge-miio/node_modules/miio/lib/device.js:223:23)
(node:1970) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Cannot read property 'model' of undefined
(node:1970) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): TypeError: Cannot read property 'model' of undefined
[5/22/2017, 8:35:42 PM] [homebridge-miio.XiaomiMiio] Couldn't investigate device { id: 54171853,
  address: '192.168.0.102',
  port: 54321,
  token: '99695a066dec30ba352f37167e5993d5',
  lastSeen: 1495456538261,
  writeOnly: true } Error: Timeout
    at _ensureToken.then (/usr/lib/node_modules/homebridge-miio/node_modules/miio/lib/device.js:223:23)
(node:1970) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 4): TypeError: Cannot read property 'model' of undefined
[5/22/2017, 8:35:42 PM] [homebridge-miio.XiaomiMiio] Couldn't investigate device { id: 52813292,
  address: '192.168.0.104',
  port: 54321,
  token: 'ad48f6c715ff3b778c4c5c13601d1d77',
  lastSeen: 1495456538262,
  writeOnly: true } Error: Timeout
    at _ensureToken.then (/usr/lib/node_modules/homebridge-miio/node_modules/miio/lib/device.js:223:23)
(node:1970) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 5): TypeError: Cannot read property 'model' of undefined
[5/22/2017, 8:35:43 PM] [homebridge-miio.XiaomiMiio] Couldn't investigate device { id: 52773248,
  address: '192.168.0.110',
  port: 54321,
  token: '7c1cd402f2298ca4a58da2723c099f19',
  lastSeen: 1495456538261,
  writeOnly: true } Error: Timeout
    at _ensureToken.then (/usr/lib/node_modules/homebridge-miio/node_modules/miio/lib/device.js:223:23)
(node:1970) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 6): TypeError: Cannot read property 'model' of undefined
(node:1970) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 7): Error: Call to device timed out

Amazon echo

I want Tor Control the vacuum with Alexa and ha Bridge. How to Start the vacuum with command line?
Or Pause
Thanks

Catch a click on a lumi.switch

Hi there :)

I tried to catch a click on my switch & spend almost an hour trying everything with miio but nothing worked :(

I just discovered https://github.com/marvinroger/node-lumi-aqara few minutes ago and test this snippet :

const Aqara = require('lumi-aqara')
const aqara = new Aqara()
aqara.on('gateway', (gateway) => {
    console.log('Gateway discovered')
    gateway.on('ready', () => console.log('Gateway is ready'))
    gateway.on('subdevice', (device) => {
        if (device.getType() === 'switch') {
            console.log('Found switch :)')
            console.log(`  Battery: ${device.getBatteryPercentage()}%`)
            console.log(`  SID: ${device.getSid()}`)
            device.on('click', () => console.log(`${device.getSid()} is clicked`))
        }
    })
})

Then this is the output I just had :

Gateway discovered
Gateway is ready
Found switch :)
  Battery: 53.6%
  SID: 15xxxd0

Then I clicked on my switch and tadaaa : 15xxxd0 is clicked

So now I wonder what I missed here when using miio ?

What's the proper way to do this ?

Thanks

Add alternative way to discover device model

The discovery currently implemented uses hostname lookup to figure out the model of a device, but not all networks supports this lookup.

An alternative way to discover the model is needed, probably by connecting to it during the discovery phase to run miIO.info.

Miio --discover does not find gateway

Hi all,

i'm trying to get miio to work with my gateway with no success. I've got a lumi.gateway.v3 but the
miio --discover just runs forever without any output.

I've tried other libraries and I was able to connect to the gateway and get info from de sub devices.

I've tried to discover the gateway with the developer mode ON and with both local area network communication protocol ON and OFF.

any thoughts?

thanks.

Wifi Plug and Lumi Plug have different device.type strings?

a chuangmi-plug-m1 wifi power plug device has a "switch" type but a lumi gateway plug has a "plug" type, though they are very similar devices, aside from the lumi plug having some extra power usage measurement functionality. Shouldn't they be the same type, or at least, similar words?

Can not get device information

Hi,In the use of this plug-in, I have some problems. Do not know why not get the device information.
The information obtained is as follows:
Device ID: 48562027
Model info: Unknown
Address: 192.168.31.161

Token: ???
Support: Unknown

Device ID: 1097069
Model info: Unknown
Address: 192.168.31.182

Token: ???
Support: Unknown

Device ID: 48395663
Model info: Unknown
Address: 192.168.31.69

Token: ???
Support: Unknown

Device ID: 49371632
Model info: Unknown
Address: 192.168.31.74

Token: ???
Support: Unknown

Device ID: 54965957
Model info: Unknown
Address: 192.168.31.171

Token: b0b89550227b8c3caebe86f1359b16a5 via auto-token
Support: Unknown

Device ID: 48282918
Model info: Unknown
Address: 192.168.31.6

Token: b0b10d0edc28ce80ab1bc4f253a2a96a via auto-token
Support: Unknown

(node:3537) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot set property 'device' of undefined
(node:3537) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:3537) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Cannot set property 'device' of undefined

Xiaomi Philips LED Ceiling Lamp information

Hi there,
At first lamp:
20170517172505_59301

I've got some data for this lamp. At first I've tried to capture packets but couldn't get any data using miio -- json-dump, data always was N/A. The lamp itself descovered by miio --discover, but with no token. ( I got it with resetting device and also compared it with the one in android). I've tried different capture methods, using wireshark with android emulator, wireshark with remote tcpdump from my router, wireshark with arpspoofing lamp and phone with mihome app but no luck. I see the packets (udp port 54321) but they all goes through xiaomi cloud and this data couldn't be used with miio --json-dump .(always N/A)
So I first created rules to control lamp via xiaomi button (via xiaomi gateway), blocked internet access to them (lamp and gateway) so I couldn't use them via mihome app, it says that devices disconnected, and only after when I pressed button i see packets flowing from gateway to lamp and finnaly they could be read by miio --json dump and I got the data :))) then I just enabled internet, created new rules, disconnect them, capture... few times.
So what I've got:

miio --inspect
INFO Attempting to inspect 57992992
Device ID: 57992992
Model info: philips.light.ceiling (generic)
Address: ####
Token: #### via stored token
Support: At least basic

Firmware version: 1.4.5
Hardware version: MTK7697
MCU firmware version: 0027

WiFi: ##### RSSI: -47
WiFi firmware version: 4.0.0

Remote access (Mi Home App): Maybe

Turn on/off light
data= {"method":"set_power","params":["on"],"from":"nbl.52273049","id":108981800}
data= {"method":"set_power","params":["off"],"from":"nbl.52273049","id":108981800}

Toggle on/off
data= {"method":"toggle","params":[],"from":"nbl.52273049","id":105969770}

Increase/Decrease Brightness
data= {"method":"auto_bri_inc","params":[],"from":"nbl.52273049","id":107126017}
data= {"method":"auto_bri_dec","params":[],"from":"nbl.52273049","id":107126017}

Increase/Descrease Color Temperature
data= {"method":"auto_cct_inc","params":[],"from":"nbl.52273049","id":107126037}
data= {"method":"auto_cct_dec","params":[],"from":"nbl.52273049","id":107126037}

Set Brightness + ColorTemp (0-100, 0-100; Where 0,0 - "Center night light mode")
data= {"method":"set_bricct","params":[10,10],"from":"nbl.52273049","id":107131875}

Set Fixed Scene (Scenes 1-4)
data= {"method":"apply_fixed_scene","params":[4],"from":"nbl.52273049","id":105954042}

Switch between fixed Scenes (only 3 of four)
data= {"method":"switch_the_scene","params":[],"from":"nbl.52273049","id":105962452}

Reply
data= {"result":["ok"],"id":105965605}

Maybe this info helpul for you and you could support for this device.

Block-scoped declarations (let, const, function, class) not yet supported outside strict mode

Today, I updated the npm module to the latest.

I got this error on all request:

root@raspberrypi:/usr/share/openhab2/miairpurifier# miio --discover
/usr/lib/node_modules/miio/cli/index.js:86
let out;
^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:387:25)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:148:18)
at node.js:405:3
root@raspberrypi:/usr/share/openhab2/miairpurifier#

Would you please help me? May I do wrong anything?

Thank you in advance.

Only the first invocation of setPower() works

Playing with miio in the node repl, I kept getting weird broken promise errors after the first use of setPower(). I've written a little test script which toggles the power input to the device. The first setPower() command always works fine for me, but the second always crashes. This occurs even if I change the last line bounce(false, 4, 0.5); to bounce(true, 4, 0.5);

const MiioDevice = require("miio").Device;
const Heater = new (require('miio').Device)('chuangmi-plug-m1_miio46068323.local');

function bounce(val, count, delay) {
  console.log("Setting value to " + JSON.stringify(val));
  Heater.setPower(val).then(()=> {
    console.log("Ok!");
    if (count > 0) setTimeout(()=> bounce(!val, count-1, delay), delay * 1000);
  }).catch((...args)=> {
    console.error("error!!", ...args);
  })
}

bounce(false, 4, 0.5);
$ node toggle-test.js
Setting value to false
Ok!
Setting value to true
error!! undefined

Alternative way to support devices on Smart Home Gateway

As reported in #19 several libraries using the Local Developer API of the Aqara gateway can break things. This issue is for tracking an alternative way to implement support for devices on the Smart Home Gateway by combining just the broadcasts from the Local Developer API with miIO-methods for listing and controlling the devices.

Current status is that there is a call: device.call('get_device_prop', [ 'lumi.0', 'device_list' ]) that lists the devices, but I'm not sure how to map that into the type of subdevice yet.

Update: Current type mapping:
0 - Gateway
1 - lumi.switch
2 - lumi.motion
3 - lumi.magnet
4 - ???
5 - ???
6 - ???
7 - lumi.ctrl_neutral2
8 - lumi.cube
9 - lumi.ctrl_neutral1
10 - lumi.sensor_ht
11 - lumi.plug

miio --discover fails to recognize gateway 2

First of all, thanks for your fantastic work.

BTW, I believe I have a Xiaomi Gateway 2 (DGNWG02LM) but miio is not recognizing it properly.

$ miio --discover --sync
INFO Discovering devices. Press Ctrl+C to stop.

Device ID: 44605366
Model info: Unknown
Address: 192.168.31.68
Token: db25a7539e35bc660f201eb69958e75f via auto-token
Support: Unknown

Device ID: 52269167 ---> This is Xiaomi Gateway 2
Model info: Unknown
Address: 192.168.31.207
Token: 607a194ccaf7e9c7d8fca7ab8371630d via auto-token
Support: Unknown

Device ID: 158d000157382e --> Temp & Humidity sensor connected to the gateway
Model info: lumi.sensor_ht (sensor)
Address: Owned by 52269167
Token: Automatic via parent device
Support: At least basic

Device ID: 158d0001874c26 --> PIR sensor connected to the gateway
Model info: lumi.motion (motion)
Address: Owned by 52269167
Token: Automatic via parent device
Support: At least basic

Device ID: 158d00012ca74c --> Wireless switch connected to the gateway
Model info: lumi.switch (controller)
Address: Owned by 52269167
Token: Automatic via parent device
Support: At least basic

Device ID: 158d00014d3826 --> Window/door magnetic sensor connected to the gateway
Model info: lumi.magnet (magnet)
Address: Owned by 52269167
Token: Automatic via parent device
Support: At least basic

So, miio doesn't discover 52269167 as gateway but somehow sensors connected to the gateway are discovered properly.

I tried miio --inspect and I think it discovered gateway like the following:
miio --inspect 52269167
INFO Attempting to inspect 52269167

Device ID: 52269167
Model info: lumi.gateway.v3 (gateway)
Address: 192.168.31.207
Token: 607a194ccaf7e9c7d8fca7ab8371630d via auto-token
Support: At least basic

Firmware version: 1.3.1_141
Hardware version: MW300
MCU firmware version: 0141

WiFi: BSGSNet (F0:B4:29:F6:23:D4) RSSI: -57
WiFi firmware version: SD878x-14.76.36.p84-702.1.0-WM

Remote access (Mi Home App): UDP

Here, I have still no idea whether my one is v2 or v3. Its model name is DGNWG02LM which is printed in the back of gateway. One thing to notice is firmware version. At the moment, I deliberately didn't update to the recent firmware 1.4.1_145.0141. Maybe that could be the reason why miio fails to discover it as gateway.

However, the gateway replies the list of sub devices well like the following:
miio --control 52269167 --method get_device_prop --params '["lumi.0","device_list"]'
INFO Attempting to control 52269167

INFO Got result:
[
"lumi.158d000157382e", // lumi.sensor_ht
10,
1,
0,
2,
"lumi.158d0001874c26", //lumi.motion (motion)
2,
1,
0,
11,
"lumi.158d00012ca74c", //lumi.switch (controller)
1,
1,
0,
10,
"lumi.158d00014d3826", //lumi.magnet (magnet)
3,
1,
0,
10
]

Thanks for your sharing again :)

miio --discover node issues

xiaomi vacuum, miio --discover --sync cmd:

Device ID: 55388595
Model info: Unknown
Address: 192.168.8.1
Token: 7a6c4e46553032326c53365374413834 via auto-token

Support: Unknown
(node:94) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Call to device timed out
(node:94) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

please help me out..

call hasCapability and getting error

Hi, when i call the function "hasCapability“, i'm getting the following error.
if(this.handle.hasCapability('power')) {
^

TypeError: this.handle.hasCapability is not a function

i think it is because it doesn't initialized successfully, but i don't know why, their is no other log i can check, could you help? thanks.

[Question / Request] Resolve multiple devices

First all, great work. Second, this is not an issue and might not even be a feature request. Sorry for that.

I'd like to integrate this library in an app for a home domotica controller (Homey by Athom). I'd like to know if it's possible to resolve multiple device with their own handle simultaneously when initializing this app for the home domotica controller instead of having to resolve the device every time a command is triggered.

For instance when someone uses a purifier and a vacuum cleaner both devices can be resolved and have their own commands. I can get this to work to resolve the device every time a command is given but I'd rather resolve all devices once upon initialization of my own app.

Hope it makes sense.

Air Purifier Sensor data is undefined

`'use strict';

const miio = require('miio');

// Create a new device over the given address
const device = miio.createDevice({
model: 'zhimi.airpurifier.m1',
address: '192.168.1.15'
});

function exit() {
process.exit(-1);
}

const value = device.getProperties([ 'aqi', 'temp_dec', 'humidity' ]).promise.then(console.log)
setTimeout(exit, 3000);

`

This line of code returns

TypeError: Cannot read property 'then' of undefined at Object.<anonymous> (/usr/share/openhab2/miairpurifier/monitoring_miairpurifier.js:17:78) at Module._compile (module.js:571:32) at Object.Module._extensions..js (module.js:580:10) at Module.load (module.js:488:32) at tryModuleLoad (module.js:447:12) at Function.Module._load (module.js:439:3) at Module.runMain (module.js:605:10) at run (bootstrap_node.js:427:7) at startup (bootstrap_node.js:151:9) at bootstrap_node.js:542:3

could not get vacuum type

i run miio --discover, it shows below, and not able to get the type of vacuum

Device ID: 55353665 Model ID: Unknown Type: undefined Address: 192.168.2.251 (rockrobo) Token: null Support: Unknown

no output

Hi,

I've installed miio, to find the token for a xiaomi plug

However when I execute miio, i have not output (comand lasts no more than 1 second to execute).

Im running this in a raspian jessie distro. Any feedback of what might be the problem?

TODO: Implement Discovery

miio wifi devices can be discovered using MDNS. On macOS you can discover the miio wifi devices by running dns-sd -B _miio._udp. Cross platform mdns node libraries should be able to do a decent job of discovering devices on the local network.

how to pack a new message

I just say the latest gateway API supports event simulation, like you could simulate the double click switch action.

i couldn't find where to pack the new message to the device, would mind explain little bit, how to implement a new function to simulate the sub device event? many thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.