homebridge-mi-aqara
homebridge-mi-aqara copied to clipboard
Add support for sensor_cube.aqgl01
I realised that MiAqaraPlatform was finding my cube but not recognising it as the magic cube:
[2018-6-6 16:08:48] [MiAqaraPlatform] [DEBUG][Send]{"cmd":"read", "sid":"158d000231e6d3"}
[2018-6-6 16:08:48] [MiAqaraPlatform] [DEBUG][Revc]{"cmd":"read_ack","model":"sensor_cube.aqgl01","sid":"158d000231e6d3","short_id":60961,"data":"{"voltage":2905}"}
Turns out that my cube is the model "sensor_cube.aqgl01" so I added it to "parser/MagicSquareParser.js" in the following line:
MagicSquareParser.modelName = ['cube', 'sensor_cube', 'sensor_cube.aqgl01'];
Now it finds it, recognises it and configures it, great! :-),
The problem now is that I don't receive any event message from the gateway, when I move the cube it appears in the log of the YiHome App but I receive nothing, what can I do? Can you help me @YinHangCode ?
Thanks!
Same trouble here with the Cube. The Mi Home app shows mine as sensor_cube.aqgl01, and it doesn't appear through Homebridge. Interesting thing, though, is that my MagicSquareParser.js doesn't even have the list you added this name to.
Yesterday, I updated to 0.6.9 and the Cube didn't appear. Today, it's suddenly there.
@Wormaap the interval of the find the new device is 30 minutes, or restart homebridge.
Ahh, that makes sense. The switches that showed up in the Home app still aren't doing much, though, but that's probably just me not having them figured out yet. Thank you! :)
Same problem here. Everything works fine on MI home app. After updating to 0.6.9 cube finally appears to Homekit but actions triggered (shake, flip, etc) are not delivered to Homekit. Any ideas?
Same problem here: the buttons / virtual switches are correctly discovered but not showing any reaction at all. (see also #214)
My cube appears to be discovered, in that logging shows:
[2018-8-19 10:07:33] [MiAqaraPlatform] [DEBUG][Send]{"cmd":"read", "sid":"158d00026e9aaa"}
[2018-8-19 10:07:33] [MiAqaraPlatform] [DEBUG][Revc]{"cmd":"read_ack","model":"sensor_cube.aqgl01","sid":"158d00026e9aaa","short_id":59232,"data":"{\"voltage\":2955}"}
... and I now see 6 StatelessProgrammable switches in Homekit (although I didn't initially) for Flip90, Flip180, Move, TapTwice, ShakeAir and Rotate.
However, assigning actions to these switches does nothing. Should this version of the cube work?
Interestingly I also see Switches for Flip90, Flip180, Move, TapTwice and ShakeAir - and if I try changing the state of one of these in Homekit an error is logged - for example:
[2018-8-19 10:27:44] [MiAqaraPlatform] [DEBUG][Send]{"cmd":"write","model":"sensor_cube.aqgl01","sid":"158d00026e9aaa","data":{"status":"flip90", "key": "db2bfb84e295dc13fd18878efae1f22a"}}
[2018-8-19 10:27:44] [MiAqaraPlatform] [DEBUG][Revc]{"cmd":"write_ack","model":"sensor_cube.aqgl01","sid":"158d00026e9aaa","short_id":59232,"data":"{\"voltage\":2955}"}
EventedHTTPServer [::ffff:192.168.10.172] Muting event '51.10' notification for this connection since it originated here. +9ms
[2018-8-19 10:27:44] [MiAqaraPlatform] [ERROR]SyntaxError: Unexpected string in JSON at position 96
[2018-8-19 10:27:44] [MiAqaraPlatform] [ERROR]SyntaxError: Unexpected string in JSON at position 96
at JSON.parse (<anonymous>)
at MagicSquareSwitchVirtualFlip90Parser.doSomething (/usr/lib/node_modules/homebridge-mi-aqara/parser/MagicSquareParser.js:234:27)
at that.platform.sendWriteCommand.then.result (/usr/lib/node_modules/homebridge-mi-aqara/parser/SwitchVirtualBasePressParser.js:51:34)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
EventedHTTPServer [::ffff:192.168.10.172] HTTP Response is finished +8ms
(node:10331) UnhandledPromiseRejectionWarning: Error: This callback function has already been called by someone else; it can only be called one time.
at /usr/lib/node_modules/hap-nodejs/lib/util/once.js:12:13
at MagicSquareSwitchVirtualFlip90Parser.callback2HB (/usr/lib/node_modules/homebridge-mi-aqara/parser/AccessoryParser.js:197:17)
at /usr/lib/node_modules/homebridge-mi-aqara/parser/SwitchVirtualBasePressParser.js:57:34
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
(node:10331) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 11)
EventedHTTPServer [::ffff:192.168.10.172] HTTP request: /characteristics?id=51.10 +64ms
HAPServer [CC:87:3D:E3:CE:30] HAP Request: GET /characteristics?id=51.10 +0ms
Accessory [Homebridge] Getting value for Characteristic "On" +2ms
Accessory [Homebridge] Got Characteristic "On" value: true +0ms
EventedHTTPServer [::ffff:192.168.10.172] HTTP Response is finished +1ms
Today I updated my gateway firmware to 1.4.1_157.0143 using the Mi Home App (on mainland china server) and now the cube is working fine. My plugin version is 0.6.9 and the buttons/switches are discovered in Homekit, assining actions also works. So you have to update your Gateway and the issue should be solved. Also restart your homebridge to refresh the accessories. So I guess it was a faulty gateway firmware.
Yes, some functionality was restored by the firmware update! Rotate, however, as well as all stateful switches still appear to be broken.
I have installed version 0.7.1. In the release notes (of 0.7.0) is stated that the MagicSquare Rotate StatelessProgrammableSwitch should be working now. I have tested this, however the tile in the Home app does not show any movement when rotating the cube. Neither the action is performed.
So in my opinion the rotate function is still not working.
What about you guys?
In a previous release the rotate tile in the Home app was also moving when performing other actions. Ffor example: flip90, then the flip90 tile was moving but also the rotate tile.
got same problem with rotate, too, not fixed after 0.7.1
But can't hide the switches, even I stated it in the config.
{ "platform": "MiAqaraPlatform", "gateways": { "xxx": "xxx" }, "Xxxxxxxxx": { "MagicSquare_Switch_VirtualFlip180_d768": { "disable": true }, "MagicSquare_Switch_VirtualShakeAir_d768": { "disable": true }, "MagicSquare_Switch_VirtualTapTwice_d768": { "disable": true }, "MagicSquare_Switch_VirtualMove_d768": { "disable": true }, "MagicSquare_Switch_VirtualFlip90_d768": { "disable": true } } },
I have a fix for rotate, the parser is faulty. I read the debug log and found this line: {"cmd":"report","model":"sensor_cube.aqgl01","sid":"158d000230e589","short_id":57705,"data":"{\"rotate\":\"16,500\"}"}
there is no status anymore in the message. If you rotate clockwise, the number is positive. If you rotate counterclockwise the number is negative. So I changed 'status' to 'rotate' in the code. Here is my code for MagicSquareParser.js:
class MagicSquareStatelessProgrammableSwitchRotateParser extends MagicSquareStatelessProgrammableSwitchBaseParser {
getProgrammableSwitchEventCharacteristicValue(jsonObj, defaultValue) {
var value = null;
var proto_version_prefix = this.platform.getProtoVersionPrefixByProtoVersion(this.platform.getDeviceProtoVersionBySid(jsonObj['sid']));
if(1 == proto_version_prefix) {
value = this.getValueFrJsonObjData1(jsonObj, 'rotate');
} else if(2 == proto_version_prefix) {
value = this.getValueFrJsonObjData2(jsonObj, 'cube_status');
} else {
}
if(parseFloat(value) > parseFloat(0)) {
return this.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS;
} else if (value === 'rotate'){
return this.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS;
} else {
return defaultValue;
}
}
}
My idea: Create a new accessory parser that recognizes the rotation direction. So maybe this way:
'MagicSquare_StatelessProgrammableSwitch_Rotate_Clockwise': MagicSquareStatelessProgrammableSwitchRotateClockwiseParser,
'MagicSquare_StatelessProgrammableSwitch_Rotate_Counterclockwise': MagicSquareStatelessProgrammableSwitchRotateCounterclockwiseParser
The new code above recognizes clockwise only.
All other switches are working properly. I haven't checked yet if hiding the switches is possible.
Edit: Working version of MagicSquareParser.js attached
got same problem with rotate, too, not fixed after 0.7.1
But can't hide the switches, even I stated it in the config.
{ "platform": "MiAqaraPlatform", "gateways": { "xxx": "xxx" }, "Xxxxxxxxx": { "MagicSquare_Switch_VirtualFlip180_d768": { "disable": true }, "MagicSquare_Switch_VirtualShakeAir_d768": { "disable": true }, "MagicSquare_Switch_VirtualTapTwice_d768": { "disable": true }, "MagicSquare_Switch_VirtualMove_d768": { "disable": true }, "MagicSquare_Switch_VirtualFlip90_d768": { "disable": true } } },
To disable them you have to the delete the "_d768". See below. This should work. { "platform": "MiAqaraPlatform", "gateways": { "xxx": "xxx" }, "Xxxxxxxxx": { "MagicSquare_Switch_VirtualFlip180": { "disable": true }, "MagicSquare_Switch_VirtualShakeAir": { "disable": true }, "MagicSquare_Switch_VirtualTapTwice": { "disable": true }, "MagicSquare_Switch_VirtualMove": { "disable": true }, "MagicSquare_Switch_VirtualFlip90": { "disable": true } } },
I have a fix for rotate, the parser is faulty. I read the debug log and found this line:
{"cmd":"report","model":"sensor_cube.aqgl01","sid":"158d000230e589","short_id":57705,"data":"{\"rotate\":\"16,500\"}"}
there is no status anymore in the message. If you rotate clockwise, the number is positive. If you rotate counterclockwise the number is negative. So I changed 'status' to 'rotate' in the code. Here is my code for MagicSquareParser.js:class MagicSquareStatelessProgrammableSwitchRotateParser extends MagicSquareStatelessProgrammableSwitchBaseParser { getProgrammableSwitchEventCharacteristicValue(jsonObj, defaultValue) { var value = null; var proto_version_prefix = this.platform.getProtoVersionPrefixByProtoVersion(this.platform.getDeviceProtoVersionBySid(jsonObj['sid'])); if(1 == proto_version_prefix) { value = this.getValueFrJsonObjData1(jsonObj, 'rotate'); } else if(2 == proto_version_prefix) { value = this.getValueFrJsonObjData2(jsonObj, 'cube_status'); } else { } if(parseFloat(value,10) > parseFloat(0)) { return this.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS; } else { return defaultValue; } } }
My idea: Create a new accessory parser that recognizes the rotation direction. So maybe this way:
'MagicSquare_StatelessProgrammableSwitch_Rotate_Clockwise': MagicSquareStatelessProgrammableSwitchRotateClockwiseParser, 'MagicSquare_StatelessProgrammableSwitch_Rotate_Counterclockwise': MagicSquareStatelessProgrammableSwitchRotateCounterclockwiseParser
The new code above recognizes clockwise only.
All other switches are working properly. I haven't checked yet if hiding the switches is possible.
For me this is too technical (however I do understand what you explain). Hopefully one of the developers of this plugin can fix this. @YinHangCode ?
Today I updated my gateway firmware to 1.4.1_157.0143 using the Mi Home App (on mainland china server) and now the cube is working fine. My plugin version is 0.6.9 and the buttons/switches are discovered in Homekit, assining actions also works. So you have to update your Gateway and the issue should be solved. Also restart your homebridge to refresh the accessories. So I guess it was a faulty gateway firmware.
Thank you so much! This solved my problem!
Today I updated my gateway firmware to 1.4.1_157.0143 using the Mi Home App (on mainland china server) and now the cube is working fine. My plugin version is 0.6.9 and the buttons/switches are discovered in Homekit, assining actions also works. So you have to update your Gateway and the issue should be solved. Also restart your homebridge to refresh the accessories. So I guess it was a faulty gateway firmware.
Thank you so much! This solved my problem!
The rotate function is still not working. The other five movements are.
I just installed the cube. And i see the switches in homekit. But when i select one i get:
[2018-11-19 21:38:24] [MiAqaraPlatform] [DEBUG][Revc]{"cmd":"write_ack","model":"sensor_cube.aqgl01","sid":"158d000287911e","short_id":14394,"data":"{\"voltage\":2995}"}
[2018-11-19 21:38:24] [MiAqaraPlatform] [ERROR]SyntaxError: Unexpected token o in JSON at position 1
[2018-11-19 21:38:24] [MiAqaraPlatform] [ERROR]SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)
at MagicSquareSwitchVirtualFlip90Parser.getValueFrJsonObjData1 (/usr/lib/node_modules/homebridge-mi-aqara/parser/AccessoryParser.js:78:32)
at MagicSquareSwitchVirtualFlip90Parser.getStatusLowBatteryCharacteristicValue (/usr/lib/node_modules/homebridge-mi-aqara/parser/AccessoryParser.js:127:30)
at MagicSquareSwitchVirtualFlip90Parser.parserBatteryService (/usr/lib/node_modules/homebridge-mi-aqara/parser/AccessoryParser.js:156:42)
at MagicSquareSwitchVirtualFlip90Parser.parserAccessories (/usr/lib/node_modules/homebridge-mi-aqara/parser/SwitchVirtualBasePressParser.js:63:18)
at MagicSquareParser.parserAccessories (/usr/lib/node_modules/homebridge-mi-aqara/parser/DeviceParser.js:49:27)
at ParseUtil.parserAccessories (/usr/lib/node_modules/homebridge-mi-aqara/lib/ParseUtil.js:112:29)
at MagicSquareSwitchVirtualShakeAirParser.doSomething (/usr/lib/node_modules/homebridge-mi-aqara/parser/MagicSquareParser.js:359:33)
at that.platform.sendWriteCommand.then.result (/usr/lib/node_modules/homebridge-mi-aqara/parser/SwitchVirtualBasePressParser.js:51:34)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:189:7)
(node:18838) UnhandledPromiseRejectionWarning: Error: This callback function has already been called by someone else; it can only be called one time.
at /usr/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/util/once.js:12:13
at MagicSquareSwitchVirtualShakeAirParser.callback2HB (/usr/lib/node_modules/homebridge-mi-aqara/parser/AccessoryParser.js:197:17)
at /usr/lib/node_modules/homebridge-mi-aqara/parser/SwitchVirtualBasePressParser.js:57:34
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:189:7)
(node:18838) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
I just installed the cube. And i see the switches in homekit. But when i select one i get:
[2018-11-19 21:38:24] [MiAqaraPlatform] [DEBUG][Revc]{"cmd":"write_ack","model":"sensor_cube.aqgl01","sid":"158d000287911e","short_id":14394,"data":"{\"voltage\":2995}"} [2018-11-19 21:38:24] [MiAqaraPlatform] [ERROR]SyntaxError: Unexpected token o in JSON at position 1 [2018-11-19 21:38:24] [MiAqaraPlatform] [ERROR]SyntaxError: Unexpected token o in JSON at position 1 at JSON.parse (<anonymous>) at MagicSquareSwitchVirtualFlip90Parser.getValueFrJsonObjData1 (/usr/lib/node_modules/homebridge-mi-aqara/parser/AccessoryParser.js:78:32) at MagicSquareSwitchVirtualFlip90Parser.getStatusLowBatteryCharacteristicValue (/usr/lib/node_modules/homebridge-mi-aqara/parser/AccessoryParser.js:127:30) at MagicSquareSwitchVirtualFlip90Parser.parserBatteryService (/usr/lib/node_modules/homebridge-mi-aqara/parser/AccessoryParser.js:156:42) at MagicSquareSwitchVirtualFlip90Parser.parserAccessories (/usr/lib/node_modules/homebridge-mi-aqara/parser/SwitchVirtualBasePressParser.js:63:18) at MagicSquareParser.parserAccessories (/usr/lib/node_modules/homebridge-mi-aqara/parser/DeviceParser.js:49:27) at ParseUtil.parserAccessories (/usr/lib/node_modules/homebridge-mi-aqara/lib/ParseUtil.js:112:29) at MagicSquareSwitchVirtualShakeAirParser.doSomething (/usr/lib/node_modules/homebridge-mi-aqara/parser/MagicSquareParser.js:359:33) at that.platform.sendWriteCommand.then.result (/usr/lib/node_modules/homebridge-mi-aqara/parser/SwitchVirtualBasePressParser.js:51:34) at <anonymous> at process._tickCallback (internal/process/next_tick.js:189:7) (node:18838) UnhandledPromiseRejectionWarning: Error: This callback function has already been called by someone else; it can only be called one time. at /usr/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/util/once.js:12:13 at MagicSquareSwitchVirtualShakeAirParser.callback2HB (/usr/lib/node_modules/homebridge-mi-aqara/parser/AccessoryParser.js:197:17) at /usr/lib/node_modules/homebridge-mi-aqara/parser/SwitchVirtualBasePressParser.js:57:34 at <anonymous> at process._tickCallback (internal/process/next_tick.js:189:7) (node:18838) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
Try: npm install [email protected]
or
sudo npm install [email protected]
to update to the newest version.
Then restart your homebridge.
It is very important to update your gateway firmware to the newest version using the Mi Home app. My gateway version is: 1.4.1_159.0143 on Mainland China server.