merdok / homebridge-xiaomi-fan

Homebridge plugin for Xiaomi Smartmi and Mija fans
MIT License
113 stars 15 forks source link

Slow in response, timeout? #5

Closed DJay-X closed 4 years ago

DJay-X commented 5 years ago

@merdok After a few days of use unfortunately the plugin didn't work well for me. When I open Eve or Home App, the Fan switch is not responding a long time. Eve App is showing the circle a while, then exclamation mark symbol, and a few seconds later the fan is available. Please see video https://youtu.be/KFvNhxXq0YM This brings the problem that Siri is pointing to that the Fan/Device is not responding. A few seconds later, it works after asking again. The major issue is with automations. Because of that the device is not responding in first place, the automation triggers not "Fan on" etc. I never faced this issue with the old plugin of https://github.com/YinHangCode/homebridge-mi-fan Any Idea? I'd like to prefer your plugin. Thanks.

merdok commented 5 years ago

That sounds strange... Didn't experience such issues. Could you maybe post the homebridge log from that particular time if you have it, or could you replicate this issue and save the log? That could give me some insight on what may cause this.

DJay-X commented 5 years ago

Maybe @Nastras can also give some input at the next opportunity. We know each other. I'm not able to to run debug at the moment. By the way how can I debug a 2nd Homebridge Instance? šŸ˜±šŸ˜…

Nastras commented 5 years ago

You have to enter the following line in the homebridge option file /etc/default from your instance:

DEBUG=* homebridge -D

This activates the debug mode.

With me it can still take some time until I come to the test of the Plugin since I have still another building site at present which I must finish first.

DJay-X commented 5 years ago

@merdok Faster than expected. Hope this helps.

I noticed that the log is taking long on this point when the switch for the fan is also not responding.

2019-08-14T11:14:09.303Z thing:miio:85578936 <- Handshake reply: <Buffer ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff>

Heres some of the log. Not filtered much. Hope this helps anyway. Let me know. Thx a lot.

syslog.txt

merdok commented 5 years ago

It looks more like an issue to me with the fan just responding so slow. Maybe it is due to slow network connection. I can see that the request is send to the fan, it just takes a long time to get an response.

Anyway if i figure out how to use the events then the status will be much better since then i do not have to fetch the status from the fan each time when you open the Home app.

DJay-X commented 5 years ago

Thanks a lot for your brain work. šŸ‘ Slow network connection is not a topic here. ;) More than enough speed in the house. šŸ¤£

I just noticed by now, that you are also in Germany. Maybe you want to join? https://forum.smartapfel.de/forum/thread/1128-xiaomi-mi-smart-ventilator-fan/?postID=62820#post62820 Or are you already in the community?

Thanks again @merdok

merdok commented 5 years ago

You have to take every possibility into account and since i cannot reproduce the issue, there must be a difference between my and your setup. The obvious one is that we have different fans, so it could also be as simple as the fan is responding to slow because to much request are getting to it.

Ja, komme auch as Deutschland :) Danke fĆ¼r den Link werde da mal reinschauen.

Nastras commented 5 years ago

I tested the plugin now. With me everything works except the buzzer function.

For move control it also works when the fan swing is stopped via the Xiaomi app. There should be a switch or slider that switches between the different modes. from 30% 60% ...

I have the first model with Battery: https://www.gearbest.com/living-appliances/pp_391577.html

Nastras commented 5 years ago

Which would also be nice if there were entries in the log.

merdok commented 5 years ago

What model exactly do you have? Your does not have a buzzer? What logs do you mean?

Nastras commented 5 years ago

Does that name help? The first genaration of xiaomi fans. ZhiMiDCVariableFrequencyFan

By log I mean the journalctl. There stood with me only nullen instead of a report which was switched etc.

sudo journalctl -n 30 -fau homebridge-xiaomi-fan

By buzzer we mean beep tones that can be heard during mode change, right?

If so, it has them.

merdok commented 5 years ago

No, sorry i have no idea what that name means. You need to check the homebridge log, there i log the the model. You would need to start homebridge in debug mode to get the full log.

Yes, that is he buzzer. Maybe just on your model it has a different name.

CooperCGN commented 5 years ago

@DJay-X I have the same problem with two S2 fans (2019 generation). Network isn't the problem, running a fast mesh system here. They won't update across iOS devices and timeout.

DJay-X commented 5 years ago

I was not able to test it the last weeks. My fan it the ZRFFS01ZM. At least that's what's on the bottom label. Its the all white, natural wind, fixed build in battery and smartmi on the front.

I get another Fan (S Series) without battery, silver stand, in a couple of days. Will also give it a shot with that.

Meanwhile I rolled back to the https://github.com/YinHangCode/homebridge-mi-fan and there is no delay or timeout at all. So something must be somehow different.

IMG_1140 IMG_1139

CooperCGN commented 5 years ago

I donā€™t think it has something to do with what production year the fan is. I had to return to that other plugin too.

merdok commented 5 years ago

I have also noticed the delay in the Home app but i did not yet have time to investigate this. Probably something with the fan ping so it should not be hard to fix...

CooperCGN commented 5 years ago

Any chance that this will be fixed in the future? I really would like to use this plugin as the other still adds a temperature and humidity sensor with values being zero. This then leads to strange answers when asking Siri what temperature it is in the room.

merdok commented 5 years ago

Yes, i plan to fix it. I currently just struggle to get the miio events working. As soon as i get them working this should be an easy fix...

CooperCGN commented 5 years ago

Great, if I only could help but my programming skills are quite limited :(

merdok commented 5 years ago

I do not quite understand why the events are not working. I saw many examples where people are using this exactly the same way i try but it just doesn't want to work for me... There must be something i am missing.

CooperCGN commented 5 years ago

With events you mean changes coming from the fan by e.g. pressing one of the buttons or using the mi app?

merdok commented 5 years ago

Both of them, basically this is needed to notify the plugin when something with the fan changes. Right now only the plugin can request data from the fan and it needs to be done by pooling. With events the pooling would be not necessary anymore and whenever something changes the fan could notify the plugin about that.

huongminh commented 5 years ago

any progress on this? your plugin is the better but just this issue needs a fix to make it really shine.

merdok commented 5 years ago

Not yet, but i am on it.

Nastras commented 4 years ago

@merdok Anything else happen with the plugin?

merdok commented 4 years ago

My fan is currently hidden in the basement due to winter :p I will for sure continue to work on this. The problem is that the issue with the miio plugin events is still not resolved. I even opened an issue in their github repo but without response... I still need to find a way to somehow get the events to work.

Nastras commented 4 years ago

It's a pity that you haven't made any progress because your plugin has potential šŸ˜‰

merdok commented 4 years ago

Like i said, i will have a deep look into it again soon and hopefully can make some progress.

Nastras commented 4 years ago

šŸ‘šŸ‘šŸ‘

malmentm commented 4 years ago

I also have the same slow response issue :(

merdok commented 4 years ago

Summer is slowly coming here so i will soon bring the fan back from my basement and then i can hopefully fix the issue.

malmentm commented 4 years ago

It seems like this Humidifier suffers from the same issue. https://github.com/russtone/homebridge-mi-humidifier/issues/21

esgie commented 4 years ago

In my case - so called Smartmi Standing Fan 2S EU version - ā€œnot respondingā€ issue, at least in the older plugin (homebridge-mi-fan), influenced only the accessories bound to the same room as the fan. All the other rooms werenā€™t reporting anything suspicious. What made me wonder is that after moving the fan to another room in the HomeKit, the accessories from that particular room started to suffer from the not responding issue (they were still operable though after opening each device individually), whether the devices from the previous location started to work perfectly. That made me think that the issue happens exactly in the moment of displaying the room with the fan in the Home app, so it had to be somehow connected with the fan polling performed by HomeKit when showing the fan icon. I have found out that every time the plugin makes multiple miio get_prop requests (separately for each characteristics) which seems to be too much for the fan, which responds with a significant - like 1-2 sec - lag, of course with multiple separate responses. That is done every time the Fan accessory is displayed in the Home app. The response delay is long enough to make HomeKit assume that the network is down, so from now on it binds the ā€œnot respondingā€ state to all the accessories which havenā€™t been yet initialized (the ones that were lucky enough and have finished loading their characteristics successfuly arenā€™t affected).

I have found out the above today, so itā€™s maybe too early to be sure 100% and I do not know if it is related to this one plugin here (it might, as the issues are similiar) but I am pretty convinced that the issue is caused during polling via HomeKit. If so, the root cause of the problem might be the fact that the plugin totally lacks of caching and every time requests the values from the fan (which means 7-8 requests in case of just displaying the fan icon in the Home app, the fan responds too slowly to handle it before HomeKit assumes timeout) rather than reading all the values once in a while with single request and then providing them per request from local cacheas well as updating them through events. Other idea is that the polling should be performed in asynchronous way but it isnā€™t, making the whole HomeKit request stall. I dunno, I have very limited knowledge about nodejs and homebridge-plugins (yet?)

Since frew hrs I am testing a quick workaround (for the older plugin), I have took the plugin and deleted all the code responsible for non-critical (from my pov) stuff: temperature and humidity which are totally absent, but also parental lock, led bulb and buzzer which I donā€™t need. As the number of characteristics and services is reduced, it results in reduced number of requests when displaying the icon in Home as well. This time itā€™s enough for polling to complete before times run out and all the accessories are accessible (including the fan which since then is working without any significant lag). It seems to work without hangs until now, which hadnā€™t happen in the past.

Obviously, thatā€™s only a lame workaround - it reduces plugins functionality and the success still isnā€™t guaranteed and may depend on configuration and network conditions. It is still race between slow polling and HomeKit timeout.

merdok commented 4 years ago

You are right that the issue is related to a slow response from the fan. Pooling is never a good way to get status from a device, especially when the device like this fan is powered with a battery. The network interface from the fan needs to somehow preserve battery so it goes to sleep when not used for some time. I guess even the fan without the battery behaves that way because it is basically the same fan just without the battery.

The correct solution here is to get the events to work. Till now i did not get them to work, and my post in the miio github repo got no response. This makes me believe that maybe the events are not working because of the above reasons. If that is the case the only real way would be like you say to cache some things instead doing a live update. This would of course fix the "not responding" issue but in the other way it could introduce new issue where the status is incorrect.

Nevertheless, summer is slowly coming here and i will bring my fan back from the basement and work for the best solution.

esgie commented 4 years ago

You are right that the issue is related to a slow response from the fan. Pooling is never a good way to get status from a device, especially when the device like this fan is powered with a battery. The network interface from the fan needs to somehow preserve battery so it goes to sleep when not used for some time. I guess even the fan without the battery behaves that way because it is basically the same fan just without the battery. I agree. Thatā€™s the usual cost of using devices without native Homekit support. However, I still feel that the root cause of the non working plugins lies somewhere else. As far as I understand, when the accessory is being connected to the HomeKit, the device state must (or at least should...) be polled, at least once, to sync HomeKit with the real state. But plugins seems to lag from the very beginning, starting from the initial polling.

I own numerous Homekit devices around the house and few of them has surely slower responses than the fan, in particular the Bluetooth stuff doesnā€™t seem to be that responsive, but some WiFi appliances as well (due to distance from the router or even need to query the cloud in case of some stuff connected via homebridge), but they still donā€™t cause the HomeKit failure in any way, the fact they are waiting for the value doesnā€™t make the whole HomeKit query freezee until reception. That is why assume that the root cause is somewhat connected to the way the plugin interacts with HomeKit, e.g. itā€™s not informing it that we should wait a little longer, but instead it reports the failure - or even some faulty stuff, as the HomeKit freezees globally.

malmentm commented 4 years ago

Any hope of getting this plugin up and running properly? :=)

merdok commented 4 years ago

My Fan is still in the basement but it is getting warmer and warmer here everyday so i will probably bring it back up soon and then i can continue to work on the plugin :)

esgie commented 4 years ago

The humidifier plugin facing the same issue has been already fixed. Unluckily, the commit with the fix is not trivial and it looks like some significant parts of the code had to be rewritten from scratch. Anyway, the humidifier fix which is truly working (checked on my own) might be helpful or at least inspiring in fixing the fan.

merdok commented 4 years ago

Thanks for the info. Will check that out!

esgie commented 4 years ago

I have european variant of Xiaomi Smartmi Standing Fan 2S. I was very interested in making the fan work, so I have thought about reducing the general pluginā€™s overhead assuming it may be reduced to a level not affecting whole HomeKit. I have took the second plugin, homebridge-mi-base as a base as it is possibly suffering from the same bug as yours, but the overhead is a little less intense, causing devices to be displayed as timed out in a random moments and then back again as ok, and making whole HomeKit lagged... but still working and if you are patient, you still we able to control devices. In case of this plugin here, in my case the overhead leads to a full deadlock of the whole home in a short time until stopping the instance. Basing on the plugin for similiar Chinese variant, I have simplified the fan speed control so it ignores the natural wind mode state and proceeds to regular mode - that was due to the fact that the normal/wind mode logic was somehow broken leading to total freeze of the fan - it becames unacessible even through xiaomi app - and need of restting the token (or waiting until battery runs out I guess...). I have removed temperature and humidity sensors, which doesnā€™t seem to be onboard in this model (and also requires polling, so increases overhead...). I am also disabling all the minor extras like led, buzzer or parental lock, each service means more concirrent requests, which the fan canā€™t process. Those steps reduced the lag to an acceptable level - I mean, no more Time Outs in HomeKit, all seems to be responsive. I was very disappointed with the lack of Manual controls per. 5 degree as I loved the excellent idea from your plugin! Inspired, I have added a possibility to manual move the fan to my lite version of homebridge-mi-fan plugin - please note it is a momentary switch so it does not continously request the sluggish fan for its state, so they shouldnā€™t increase the lag. I really love the feature. Well, you can check my lite version at; https://github.com/esgie/homebridge-mi-fan or install directly from github via npm install -g esgie/homebridge-mi-fan

Maybe someone will find my concept of avoiding the bads useful until the issue is truly fixed. I am not exactly a node.js guy so makin pg a fix is out of my reach, but at least I am able to use the fan in a basic scope without serious issues and affecting whole HomeKit, even if the functionality is slightly reduced.

Please note the removed libs for traditional fans, they wonā€™t work, only 2S. my config (including custom options for enabling/disabling manual controls).

    {
        "platform": "MiFanPlatform",
        "deviceCfgs": [
            {
                "type": "ZhiMiFan2S",
                "ip": "192.168....",
                "token": "...",
                "fanDisable": false,
                "fanName": "Smartmi Standing Fan 2S",
                "ledBulbDisable": true,
                "buzzerSwitchDisable": true,
                "fanLockPhysicalControlsSwitchDisable": true,
                "fanSwingModeSwitchDisable": false,
                "fanRotationSpeedDisable": false,
                "manualSwingDisable": false,
                "manualSwingName": {
                    "right": "Fan RIGHT",
                    "left": "Fan LEFT"
                }
            }
        ]
    },

`

woinkeyman commented 4 years ago

Thanks for the info. Will check that out!

Hi Merdok - been having the same issue, let me know if thereā€™s anything I can do to help! Running a 2s, 2, and 1, so happy to help test things :)

merdok commented 4 years ago

Will do šŸ™‚

edelmaca commented 4 years ago

Hey, Iā€™m using your plugin as well. I encountered timeout problems since then. After installing your plugin everything i thought everything is working well. I can control my ventilator with Siri, Home App and Eve. But the first few seconds the plugin is not responding and is showing ā€œupdatingā€ and is timing out with the message ā€œno responseā€. Sadly some other devices included in HomeKit with Homebridge are timing out as well since installing your plugin. I tried playing with the polling rate, but it didnā€™t change the behavior. I am using the 2019 2S. (za4)

merdok commented 4 years ago

Ok, guys let me see if i can provide a quick workaround for that now over the weekend. I plan greatly improve this plugin and i already have ideas for that. But before i do that i want to do some major changes to my other homerbidge plugin, in the meantime i will try to invest some time next weekend to at least provide a quick solution for the timeout issues. I know that summer is coming so the fans will not be used a lot again šŸ˜„

woinkeyman commented 4 years ago

Awesome! Thanks for looking into it, @merdok :)

merdok commented 4 years ago

Update 0.9.0 should fix the "timeout" and "not responding" issues. Did some small tests locally and everything looks pretty good. Did not try yet how it will behave after a longer time so it would be good if you guys could let me know if everything works correct and if after a longer run everything is still stable.

So right now i cache the latest known status and do not wait anymore till i get a response from the fan. This does not block HomeKit anymore, but in some minor cases when the request to the fan takes to long it might show the incorrect status (this should happen very rarely).

I have plans to improve the plugin even more and add new features so stay tuned :)

edelmaca commented 4 years ago

I will give it a try and will report back if i run in to bugs. Thanks for your quick response and this fix.

Edit: looking good so far. MiHome and Apple Home app get the correct actions back and the home app is snappy again. Perfect Now letā€™s hope this stays that way.

Looking forward for the bigger updates. Honestly I canā€™t imagine how this perfect plugin could get any better.

Edit on next morning: Everything is running fine. But I noticed, if I set natural mode in the MiHome app, and want to control the fan from Apple home, it changes to standard mode. I canā€™t get it to start in natural wind mode from within the Home App. I canā€™t change it from there. I have to go back into the MiHome App. Is this a known behavior?

Edit: hopefully the last one. Ok, I missed, that the Rotation direction switch is the Switch for natural and standard mode. But this one is not working in Apple home, at least for me. šŸ¤” If i switch it within Eve app, it stays that way, even after switching the fan on and of from Apple home. So now it is working good enough for me. Thanks

merdok commented 4 years ago

The fan should actually start in the last selected mode, no matter where it was set. And yes i had to use the rotation direction to selected beetwen standard and natural because the Home app does not provide a dedicated switch for that, and since the rotation direction is anyway not used by the xiaomi fan i used that for the mode.

edelmaca commented 4 years ago

Yes, now it does start the last used mode. At the beginning it did not. I think this was somehow my mistake. After rebooting everything it worked fine. After using it one day now I noticed the commands get somehow lost. I have to command Siri two times to get the right thing to do. It feels like I have to wake the plugin up and after that the second command gets through. The same behavior is true if I use shortcuts to control the fan. I send the command, wait a few seconds and send it again. The home app mostly gets everything right on first try.

malmentm commented 4 years ago

Anyone else has to repeat ā€œstart the fanā€ when talking to Siri almost every time?