JeroenVdb / homebridge-daikin-cloud

This Homebrige plugin connects to the Daikin Cloud and loads all your devices to be controled via Homebridge and Homekit.
https://www.npmjs.com/package/homebridge-daikin-cloud
Apache License 2.0
38 stars 11 forks source link

Device status after changes #77

Open BrunoBernardini opened 1 month ago

BrunoBernardini commented 1 month ago

Describe Your Problem:

Disclaimer: I am submitting this as a support request because I'm unsure whether the problem lies with HomeKit or the plugin.

Whenever I apply a change to one of my Daikin Perfera units (I've got three of them), it takes quite some time for the device's status (On/Off) to actually update in the Home app, even though the air conditioner receives the command immediately. When I make a change within the Home app, it initially appears to show the status change, but if I close and reopen the app, it reverts to the previous state as if the change I made didn't happen, and it takes a little while (even one or two minutes) to display the correct current status (after actively closing and reopening the app). If I make a change from the control center, it's even worse, as it doesn't show any status change at all at that moment.

I understand there is the API limit that restricts automatic refreshes to once every 15 minutes. However, if I understood correctly the way it works, the status of the device should still update immediately when a change is made, right?

As I mentioned, I suspect this might be an issue with HomeKit. However, this wouldn't make much sense to me because my other HomeKit-compatible devices (such as my TV) don't have this issue at all. Therefore, I'm uncertain where the issue lies.

Logs (with debug mode enabled):

[01/08/2024, 22:12:16] [DaikinCloud] --- Daikin info for debugging reasons (enable Debug Mode for more logs) ---
Setup Payload:
X-HM://0024MN40B8OL1
Enter this code with your HomeKit app on your iOS device to pair with Homebridge:

    ┌────────────┐     
    │ 700-56-459 │     
    └────────────┘     

[01/08/2024, 22:12:16] Homebridge v1.8.4 (HAP v0.12.2) (Homebridge 5C04) is running on port 51313.
[01/08/2024, 22:12:16] 

NOTICE TO USERS AND PLUGIN DEVELOPERS
> Homebridge 2.0 is on the way and brings some breaking changes to existing plugins.
> Please visit the following link to learn more about the changes and how to prepare:
> https://github.com/homebridge/homebridge/wiki/Updating-To-Homebridge-v2.0

[01/08/2024, 22:12:17] [DaikinCloud] Restoring existing accessory from cache: Bruno
[01/08/2024, 22:12:17] [DaikinCloud] Device found with id: fdf4955f-55f9-4acc-8d06-bc5b73c5f709
[01/08/2024, 22:12:17] [DaikinCloud]     id: fdf4955f-55f9-4acc-8d06-bc5b73c5f709
[01/08/2024, 22:12:17] [DaikinCloud]     name: Bruno
[01/08/2024, 22:12:17] [DaikinCloud]     last updated: Thu Aug 01 2024 22:10:39 GMT+0200 (Central European Summer Time)
[01/08/2024, 22:12:17] [DaikinCloud]     modelInfo: BRP069C4x
[01/08/2024, 22:12:17] [DaikinCloud]     deviceModel: dx4
[01/08/2024, 22:12:17] [DaikinCloud]     config.showExtraFeatures: true
[01/08/2024, 22:12:17] [DaikinCloud]     config.excludedDevicesByDeviceId: true
[01/08/2024, 22:12:17] [DaikinCloud] Restoring existing accessory from cache: Soggiorno
[01/08/2024, 22:12:17] [DaikinCloud] Device found with id: f9e13d69-6d0d-4cbb-b9a9-3db9ab7f20c6
[01/08/2024, 22:12:17] [DaikinCloud]     id: f9e13d69-6d0d-4cbb-b9a9-3db9ab7f20c6
[01/08/2024, 22:12:17] [DaikinCloud]     name: Soggiorno
[01/08/2024, 22:12:17] [DaikinCloud]     last updated: Thu Aug 01 2024 22:10:32 GMT+0200 (Central European Summer Time)
[01/08/2024, 22:12:17] [DaikinCloud]     modelInfo: BRP069C4x
[01/08/2024, 22:12:17] [DaikinCloud]     deviceModel: dx4
[01/08/2024, 22:12:17] [DaikinCloud]     config.showExtraFeatures: true
[01/08/2024, 22:12:17] [DaikinCloud]     config.excludedDevicesByDeviceId: true
[01/08/2024, 22:12:17] [DaikinCloud] Restoring existing accessory from cache: Fabio e Fabiola
[01/08/2024, 22:12:17] [DaikinCloud] Device found with id: e83c34f3-2fb8-4520-a6c1-30d0458ead6f
[01/08/2024, 22:12:17] [DaikinCloud]     id: e83c34f3-2fb8-4520-a6c1-30d0458ead6f
[01/08/2024, 22:12:17] [DaikinCloud]     name: Fabio e Fabiola
[01/08/2024, 22:12:17] [DaikinCloud]     last updated: Thu Aug 01 2024 22:11:48 GMT+0200 (Central European Summer Time)
[01/08/2024, 22:12:17] [DaikinCloud]     modelInfo: BRP069C4x
[01/08/2024, 22:12:17] [DaikinCloud]     deviceModel: dx4
[01/08/2024, 22:12:17] [DaikinCloud]     config.showExtraFeatures: true
[01/08/2024, 22:12:17] [DaikinCloud]     config.excludedDevicesByDeviceId: true
[01/08/2024, 22:12:17] [DaikinCloud] --------------- End Daikin info for debugging reasons --------------------

Plugin Config:

{
    "clientId": "myClientID",
    "clientSecret": "thats-a-secret",
    "callbackServerExternalAddress": "my.raspberry.pi5's.ip",
    "callbackServerPort": "8900",
    "oidcCallbackServerBindAddr": "127.0.0.1",
    "showExtraFeatures": true,
    "updateIntervalInMinutes": 15,
    "forceUpdateDelay": 60000,
    "platform": "DaikinCloud"
}

Screenshots:

![RPReplay_Final1722719536](https://github.com/user-attachments/assets/738d2c88-e6cc-44e4-b8e8-8ff8b98614a7) ![RPReplay_Final1722718044](https://github.com/user-attachments/assets/dcdf7ecb-4253-480b-aaf4-c6e958ae07d4) **Daikin Environment:** * **Daikin model**:FTXM35A2V1B * **Daikin firmware version**: 2201B701 **Homebridge Environment:** * **Plugin Version**: v2.5.0-beta.4 * **Homebridge Version**: v1.8.4 * **Node.js Version**: v20.15.0 * **NPM Version**: Not installed (just downloaded the plugin through Homebridge's UI). * **Operating System**: Debian GNU/Linux 12 (bookworm)
JeroenVdb commented 1 month ago

@BrunoBernardini the issue your describing has passed here a few times already. It is not a Home app or Homebridge issue.

What you are seeing isn't really a bug but comes because of the way we work with the Daikin API and the restrictions it brings:

Because of these limitations, when strictly working with the API:

So when you say

Whenever I apply a change to one of my Daikin Perfera units (I've got three of them), it takes quite some time for the device's status (On/Off) to actually update in the Home app, even though the air conditioner receives the command immediately.

This is because of the limited updates we can do. At the moment you can lower the updateIntervalInMinutes setting. The default is every 15 minutes (4 * 24 = 96 calls per day). If you lower it to every 7 minutes you will do 205 calls per day. Then you have 45 calls left for actions. Which might be enough.

What can the plugin do in the future?

When I make a change within the Home app, it initially appears to show the status change, but if I close and reopen the app, it reverts to the previous state as if the change I made didn't happen, and it takes a little while (even one or two minutes) to display the correct current status (after actively closing and reopening the app).

Like said, this is a problem with the API not immediately reflecting the change. I see this in the Daikin app as well. The update taking more then 2 minutes I see more as a bug on Daikin side. It was not like this previously.

Now it works as this:

  1. Set operation mode to "on" in the Home app
  2. Send command to Daikin API, a timer starts to update the data in 1 minute so the API gets time to update
  3. Homebridge asks for the operation mode, because in our device data is not updated yet we'll send back "off"
  4. Home app will display "off"
  5. A force update happens after 1 minute, hopefully already containing the correct data
  6. After 15 minutes a new updates happens, that is done every 15 minutes

So there is a 1 minute gap where the data is always wrong.

What can we do? It was coined by @Apollon77 or @jacoscaz to to optimistically update the device data. That means when you make an action we change the local data. So then we assume, if the call to Daikin doesn't fail, that the command was send and is executed and so we set the operation mode to "on". After 1 minute the force update will happen again, hopefully already containing the correct data.

TLDR;

It's not really a bug but we can improve the experience by:

Apollon77 commented 1 month ago

Agreed. I think Homebridge itself already does optimistic update as you saw in the app. But when you reload in home app the it updates data again from the plugin where the change is still pending. So yes doing the same optimistic update of the "cached data" in the plugin might be an idea.

In fact that's always such a topic about accuracy of data and such slow processes like here.

BrunoBernardini commented 1 month ago

Hi @JeroenVdb and @Apollon77, Thank you for your responses, and also, I should have said it earlier, thank you to the entire team for making and maintaining this plugin; it's really the only solution that worked for me.

After reading @JeroenVdb's comment, the way it works is much clearer to me now. What I was missing was that the status is updated only after the API result, while I thought it was updated locally at the moment of the change. I don't want to pretend to know this plugin as much as you, but based on what you've written I actually believe that the "Optimistic update" would be the best solution to this problem, and that (together with the hot/slow hours and/or increased polling features) would be a massive improvement in the user experience, especially for people like my parents who are also going to use the air conditioners through HomeKit and are not as "geeky" as I am when it comes to this kind of stuff. 😅

I just have one more little question: is the API limit 200 calls per day or 250? I'm asking because in the Readme (and in the plugin, once installed into Homebridge) it says that it's 200, but here you said 250. Which is the correct one?

Anyway, I'm really looking forward to these changes! In case you need someone to test them, I'd be glad to give you feedback. :)

JeroenVdb commented 1 month ago

Ow, I don't know why I was talking about 250. The rate limit is on 200.

jacoscaz commented 1 month ago

It's not really a bug but we can improve the experience by:

  • optimistic update
  • add hot/slow hours and/or increased polling when actions are taken

Ya, I do think optimistic update would deliver a lot of ROI for relatively small effort.

PS: @JeroenVdb that entire comment is very well-written and deserves to be pinned somewhere - kudos for it!

jacoscaz commented 1 month ago

Another thing that I think the Onecta App does is refreshing the state of all devices upon opening, which is why changing the state of my devices within the first 1 - 2 seconds of opening the app does not usually work.

While I don't think homebridge plugins can ever become aware of when users open the Home app on their devices, perhaps we could have a mechanism that hard-refreshes all devices whenever the state of anything is queried after more than X seconds from the last query.

EDIT: I think the above, if actually possible at all, would be better than slow/fast hours as it would tailor to one's specific usage of their control devices (phone, iPads, apple tvs and whatnot). Yes, we would need to carefully balance it considering the very limited pool of 200 requests per day but there should be a little bit of wiggle room in there.

JeroenVdb commented 1 month ago

While I don't think homebridge plugins can ever become aware of when users open the Home app on their devices, perhaps we could have a mechanism that hard-refreshes all devices whenever the state of anything is queried after more than X seconds from the last query. EDIT: I think the above, if actually possible at all, would be better than slow/fast hours as it would tailor to one's specific usage of their control devices (phone, iPads, apple tvs and whatnot). Yes, we would need to carefully balance it considering the very limited pool of 200 requests per day but there should be a little bit of wiggle room in there.

Yes, that is maybe a better approach then doing fast reloads when de device is "on" and some time after actions are taken.

I'm going to try to check if it's possible. Like you said, it will mainly depend on how Home app works and how often it queries Homebridge. We might also have to consider other apps that are build on Homebridge/HomeKit.

Simplified it could work like any other cache: we keep device data and serve it back to the client and invalidate the cache after X amount of minutes. The assumption is that if Home isn't querying us every 5 minutes we can "save" a lot of calls + go fetch data more often with the saved calls. Downside is that when we are queried a lot + cache max-age is lower then the amount of calls we can do per day, you will hit the rate limit.