Open robertvklinken opened 5 years ago
I am experiencing the same issue. Did you ever end up fixing the issue Robert?
I have the same issue with the WiFi Power Plugs. If I use an unconfigured plug and set it up, it works fine. Once I hold the button for 5 seconds and repair it to the Wifi, I start getting this message with that particular device. I read somewhere that if you hold the button for 15 seconds, it does a factory reset, but that hasn't worked for me. I know it's not factory reset because rather than the yellow led blinking constantly, it blinks 3 times, pauses and then blinks another 3 times, so on and so forth. I was hoping a factory reset would solve the problem. I also tried deleting the persistence data and starting over, to no avail. I'm hoping someone can help with this issue. Thank you Christian
I have no idea what's going on here. if anyone knows how to fix it, i'll happily accept a pull request as long as it seems stable on my home setup. I've not needed to factory reset my plugs at all but now i'm a bit scared to since i don't have any spares currently. maybe worth pestering the miio
library people, as that's the underlying library being used to communicate with these devices and it's kind of where the pairing magic happens. homebridge-miio is just a thingie to adapt that in to homebridge
@Bluebie do you know if there’s a way to manually assign the token rather than using the discovery?
from memory i think there is a way in the miio library, but i haven't really worked on this plugin in years. i'm pretty out of touch with it. I wonder if the issue maybe that the underlying miio library has a way to store device tokens. could it be that the token changed when you reset the device, and miio is using an old cached token? unsure. maybe something in https://github.com/aholstenson/miio/blob/master/docs/management.md could help figure that out, or maybe you can use that tool to set the token to something fixed?
homebridge-miio is using an older version of miio. i might try it with an up to date version, see if it needs any changes for compatability, perhaps the miio library has some improvements to help with these devices already?
I did some testing with the command line tools in the link you posted and once you reset the device, it can no longer see the token. There is a way to recover the token, which is reset the device again and when it creates its own WiFi network, you join it and then miio can see it again, until you re-pair the device with your WiFi. Just need to figure out a way to tell homebridge-miio what the token for a specific device ID is and then it should work. Other option would be to factory reset the plug, which I can't figure out how to do, and that might keep the token exposed.
@chrisp250 Apologies for the late response. I'm getting back to this now that I have some more free time, did you ever end up finding a fix? I found this issue on GitHub, which suggests downloading a Russian app in order to get the token and set it manually using miio. I can't download it though, as I don't have an Android device.
Edit: I have managed to get the tokens of my devices now, so now the challenge is updating the token using miio or letting homebridge-miio know what the token is, like you said. I think this could be achieved with miio tokens update deviceID --token tokenValue
, but it doesn't work for me unfortunately.
Edit 2: After some more looking around, I have found a solution that works for me. Perhaps it'll be useful to anyone who stumbles upon this in the future. The idea is: we need to get the token of the device, but it is hidden in a database file. Once we get this token, we can manually set it using the miio protocol and that way Homebridge will know the token and be able to interact with the device. In short:
miio tokens update deviceID --token decryptedTokenAsHex
Make sure you do this as the user homebridge runs on!miio discover
now shows Token: 82a...baa via stored token@Bluebie Device tokens stored in memory (through miio tokens update
) are used when running homebridge through the homebridge
command, but are not used when running homebridge through the systemd service (which looks like this). Running miio discover
finds my plugs, with their tokens stored. This is on a fresh install of the Raspberry Pi and homebridge+homebridge-miio.
Does this tell you anything in regards of where we could look to get this issue resolved? I am, in fact, still struggling with this. Did you also ever get around to updating to a newer version of miio? Perhaps that might resolve some things as well.
Here's my final input into this issue, as I was finally able to completely solve this. I'll describe some steps below for anyone else that might run into this in the future. I think this issue can be closed now.
As per my latest two comments: the tokens need to be manually stored in memory to make sure homebridge can use these. After going through everything once again I saw the following on the Miio github:
Make sure to run the miio command as the correct user as tokens are stored tied to the current user
This explains why the stored tokens were showing up through miio discover
but were not showing up for homebridge, as homebridge runs on it's own service user (in my case). To solve the issue, I logged into the homebridge user with sudo su - homebridge
, went through the commands again (miio tokens update deviceID --token decryptedTokenAsHex
) and now the plugs are finally added to Homebridge. I hope this helps someone.
Here are my 2¢. I've spent ~10 hours digging arround homebridge + miio and found that..
homebridge-miio
is terribly outdated (for example MiioDevice.type
property and some others are missing in later miio
, so if you update it all devices become be unsupported).miio
is outdated too (miio cli has got an old terribly non-obvious syntax and error messages, even --help
missing).miio
is installed inside the homebridge-miio
and it shoud be executed within it.miio
in fact but not listed in code, so won't be enabled, what could be simply fixed.So to store your device token (from ios backup for example):
cd node_modules/homebridge-miio/ # Digg into subfolder
npx miio --update deviceID --token decryptedTokenAsHex # Store device token
# If homebridge is running within user, find it
`ps uax | grep -i homebridge`
# Execute command with his privileges
sudo -u homebridge-user npx miio --update deviceID --token decryptedTokenAsHex
If your geting this message with npx miio
:
ERROR Unsupported mode
than something wrong with your cli arguments
If you've got problems with your device recognition (Unsupported, ignoring
), may be your device is not listed in node_modules/homebridge-miio/node_modules/miio/lib/models.js
. You can simply add it to the code, nevertheless all this combination is outdated and will fall apart after any update.
...
'chuangmi.plug.v2': PowerPlug,
+ 'chuangmi.plug.m3': PowerPlug,
+ 'chuangmi.plug.hmi206': PowerPlug,
'rockrobo.vacuum.v1': Vacuum,
...
NB: All this combination is very fragile and will be broken after any upgrade or version missmatch.
PS: There is another way to provide tokens, with in my docker container tokens.json
was located under
/root/.local/share/miio/tokens.json
for root/config/.local/share/miio/tokens.json
for unprivileged usertokens.json
format:
{
"deviceId1": "decryptedTokenAsHex1",
"deviceId2": "decryptedTokenAsHex2"
}
There is a good way to extract the tokens of your Xiaomi devices. Check this out:
https://github.com/PiotrMachowski/Xiaomi-cloud-tokens-extractor
I am running it in my Raspberry Pi and I run the command (listed below) in the command line tools. You will need your Xiaomi username and password, and the server of your Xiaomi account, mostly likely is 'cn', then all your Xiaomi devices will be listed for you and the tokens associated with your devices whichever has it.
bash <(curl -L https://github.com/PiotrMachowski/Xiaomi-cloud-tokens-extractor/raw/master/run.sh)
When you execute this command you will see something like this:
Enter then your username/password and server name (one of: cn, de, us, ru, tw, sg, in, i2)
then you should have a list of Xiaomi devices like this:
If anyone wants to take over this project or do some pull requests bringing it up to date, i'd very much welcome it. I'm not currently using any of these devices but I do still have some in a closet so I could test updates and validate them on my end.
Running into an issue where the device token is hidden and the plug cannot be added.