Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates stopping, unnecessary creation of new entities #347

Open
mmccool opened this issue Nov 4, 2024 · 6 comments
Open

Updates stopping, unnecessary creation of new entities #347

mmccool opened this issue Nov 4, 2024 · 6 comments

Comments

@mmccool
Copy link

mmccool commented Nov 4, 2024

I use this to track battery state-of-charge state on various Apple devices to control chargers so that I don’t overcharge my Apple devices (keeping charge below 80% is my target). Unfortunately only the latest iPhone has this feature built in, because Apple.

Anyway, this does not quite work well for two reasons:

  1. Sometimes the devices just stop updating and the automations then use stale state. Restarting the service sometimes fixes it but, see 2. When devices stop updating it does not necessarily affect all the devices. We do have a lot of devices (6, plus a Watch) and am running complications on the Watch. API limits?
  2. Sometimes when the service restarts it creates new entities for all the sensors, which then breaks all the automations and dashboards.

Due to the “sometimes” in 2 it may happen on an update. Not sure when the last update was but it last happened 1 hour ago after I tried to reload the service (but not HA) to try and fix an instance of 1.

@gcobb321
Copy link
Owner

gcobb321 commented Nov 4, 2024

  1. Doing a reload will stop the current instance of iCloud3 and load the code all over again. HA will create the _2 extension on the entity name since iCloud3 was running and the sensor entities exist in HA’s memory tables. On the reload, HA sees that they entities exist and it adds the _2 to create unique entities instead of reusing the ones iCloud3 wants.

What you want to do is an Event Log > Actions > Restart iCloud3. ICloud3 will then restart and it will initialize itself and refresh all locations.

  1. iCloud3 updates the battery info from the mobile app or the Apple account data, using the latest value. It is displayed in the Event Log when it is changed. Look there when you think it has stopped updating and see if old data was being read or if there was some other activity. Set Log Level to debug (Configure Settings > Menu Page 2 > Format Parameters screen) which will add more info to ‘icloud3-0.log’ file which might show what is or is not happening when this occurs.

@mmccool
Copy link
Author

mmccool commented Nov 4, 2024

OK, the reload vs restart explains 2. Still… this does not seem like the right behavior. Other integrations don’t have this problem.

As for 1 - I will try to capture some logs to see better what is going on.

@JtwoA
Copy link

JtwoA commented Nov 5, 2024

Other integrations don’t have this problem.

sigh

@gcobb321
Copy link
Owner

gcobb321 commented Nov 5, 2024

@JtwoA
I have been able to recreate it on the device tracker by having a device (gary_iphone), deleting it in Configure Settings > Update Devices and then reading the same device (c creates gary\iphone_2). HA has a deleted devices list in the device registry. I think then it readds it, it thinks it still exists.

@gcobb321
Copy link
Owner

gcobb321 commented Nov 6, 2024

@JtwoA
I spent most of yesterday trying to solve this and haven't found the solution. HA is assigning the _2 when it finds the entity in memory or in the deleted entities list. I tried all kinds of things to get HA to use the existing one or to create it without the _2. Could you let me give me the name of the other integrations that do not have this problem so I can look at their code. i agree with the sigh but the HA docs are limited, I am one guy, do not staff of programmers that know what they are doing and have to figure out everything as I go along. BIG SIGH

@JtwoA
Copy link

JtwoA commented Nov 6, 2024

@JtwoA I spent most of yesterday trying to solve this and haven't found the solution. HA is assigning the _2 when it finds the entity in memory or in the deleted entities list. I tried all kinds of things to get HA to use the existing one or to create it without the _2. Could you let me give me the name of the other integrations that do not have this problem so I can look at their code. i agree with the sigh but the HA docs are limited, I am one guy, do not staff of programmers that know what they are doing and have to figure out everything as I go along. BIG SIGH

My sigh was directed at the poster who fussed about "other integrations not having this issue" as though you're a paid dev who is doing this full-time. I personally think you've done a fantastic job dealing with Apple's recent changes (as someone who deals with them for business, I understand COMPLETELY).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants