home-assistant / iOS

:iphone: Home Assistant for Apple platforms
https://companion.home-assistant.io
Other
1.53k stars 296 forks source link

Many entries in integration for the same phone #2869

Open WayneManion opened 1 month ago

WayneManion commented 1 month ago

Model Name: iPhone15,3 (I think this is an iPhone 14 Pro Max) Software Version: 17.5.1 App version: 2024.6

Home Assistant Core Version Core 2024.7.3 Supervisor 2024.06.2 Operating System 12.4 Frontend 20240710.0

Describe the bug I have a Motorola Android phone with the Android Home Assistant Companion (AHAC) app. It works fine. I have the AHAC app on my old TCL Android phone. My daughter uses this phone as a media player and to play games sometimes. It also works fine. My mom doesn't lives by herself. I have the iOS Home Assistant Companion (iHAC) app installed on her phone so I can keep track of her when she picks up my daughter from day care. My mom is fully aware of the device tracking. This also works more or less OK. I have to remind my mom every so often to open the iHAC app just so it keeps talking.

My wife has an iPhone with the iHAC. It does not behave. The device tracker functionality works extremely poorly. We have been using Home Assistant for at least the last five years. She has been using the iHAC app for multiple years on multiple different iPhone models. The device tracking has never worked very well.

I have deleted the phone in the Home Assistant UI and she has uninstalled and reinstalled the iHAC app on her phone. A couple weeks ago when trying to troubleshoot a device tracker problem for the 1000th time, I noticed in the UI page for the Mobile Phone integration that there were many devices all called "Christie's iPhone". Some of these devices had no entities. Some had a single entity (a device_tracker entity to add insult to injury). A couple of the "Christie's iPhone" devices had 15-17 entities of the normal types (binary_sensor, device_tracker, sensor).

I deleted all of the iPhone devices using the Home Assistant web UI. If I remember correctly it took a couple cycles of Home Assistant core restarts to get rid of them all.

Yesterday I was fruitlessly trying once again to figure out why her phone does such a bad job reporting location when I saw many devices again. I believe there were 15 "Christie's iPhone" devices with zero entities, one with a single entity, and three "Christie's iPhone" devices with 15-17 entities each.

How can I keep this from happening?

To Reproduce Delete the "Christie's iPhone" devices. Wait a few days. There will once again be additional devices. These devices may have zero, one, or many associated entities.

Expected behavior A single device called "Christie's iPhone" that works reliably.

Screenshots

Additional context

Screenshot from 2024-07-24 09-55-02 Screenshot from 2024-07-24 09-55-27

WayneManion commented 1 month ago

I deleted all the "Christie's iPhone" entries in the Mobile app integration web UI and then rebooted the HassOS box. Now it looks like this: Screenshot from 2024-07-24 10-36-23

WayneManion commented 1 month ago

Screenshot from 2024-07-24 10-40-05

WayneManion commented 1 month ago

I was able to remove all of the extra Christie's iPhone entries, but I had to remove them one at a time, restarting Home Assistant in between every time. If I deleted more than one entry in one go, the deletion did not work.

bgoncal commented 1 month ago

About the location update: Can you explain how is your setup? How do you exposed HA for remote access, how is it configured in the app. If you check the app permissions, is location allowed "Always" and for "precise location"? Do you have zones configured? iOS works best zone-based, entering and exiting zones.

About the integrations entries: I am not sure why it endup like this, I'll investigate, but just double checking, right now you were able to remove them all and there is just one entry for your wife's phone, correct?

WayneManion commented 1 month ago

I am a Nabu Casa subscriber. She accesses Home Assistant remotely using the UUID-style Nabu Casa server address. We have also tried using Tailscale in the past. I will check the app permissions when she comes home later.

I do have zones set up in Home Assistant. There is a zone set up for her workplace as well as several other places she frequents.

I was able to remove all of the old "Christie's iPhone" entries. The only way I could get rid of them was to use the three dots to delete one, restart Home Assistant, and then repeat. This was something along the lines of 20 Home Assistant core restarts.

WayneManion commented 1 month ago

We looked at her settings and as far as I can tell we have the permissions on her phone set correctly. 854407e5-68be-4f8a-9906-e41b6542cb85 71928d35-5319-4975-b985-8c6028179bb8

WayneManion commented 1 month ago

It is just a couple days later and there are already six "Christie's iPhone" entries appearing in the web UI for the Mobile app integration.

bgoncal commented 1 month ago

Can you share your Wife's HA app logs? I can't reproduce the issue on my side

WayneManion commented 1 month ago

Where do I go to obtain these logs? Are they on my wife's phone somewhere? I never mess with Apple stuff, so I am pretty unfamiliar with how one would find such logs.

bgoncal commented 1 month ago

Companion app settings >> debugging >> export logs

bgoncal commented 1 month ago

Your logs weren't uploaded, please try again

bgoncal commented 1 month ago

Perfect, thanks, I'll get back to you after looking at it, how does the integration list looks now? All cluttered with your wife's phone entries?

WayneManion commented 1 month ago

Yes, it is still a awash with "Christie's iPhone" entries.

bgoncal commented 1 month ago

Btw, my bad I should have asked you to send the logs in private since they have sensitive information to stay public in GitHub, please feel free to delete it and send to me Bruno.pantaleao@nabucasa.com

WayneManion commented 1 month ago

Btw, my bad I should have asked you to send the logs in private since they have sensitive information to stay public in GitHub, please feel free to delete it and send to me Bruno.pantaleao@nabucasa.com

Done.

bgoncal commented 1 month ago

Wayne, did you disable "iOS" integration? I see in the logs it is not loaded

WayneManion commented 1 month ago

Wayne, did you disable "iOS" integration? I see in the logs it is not loaded

Not that I can remember.

Screenshot from 2024-08-06 09-36-05 Just now I went to the Integrations page in the web UI. I clicked 'Add integration' and searched for iOS. I found 'Home Assistant iOS'. I clicked that. Screenshot from 2024-08-06 09-33-40

I got a dialog that said: "Do you want to start setup?". I clicked the only option, "submit". Screenshot from 2024-08-06 09-33-22

I did all of this in Brave Browser on my Arch Linux desktop machine fwiw. Do I need to use an iOS device to set this up?

bgoncal commented 1 month ago

This should have been configured automatically when you setup and iOS device, so currently there is no active iOS integration on your list?

WayneManion commented 1 month ago

Screenshot from 2024-08-06 09-37-49 I would expect to see "Home Assistant iOS" or "iOS" in this list, so... no. There does not appear to be an active iOS integration.

We have been using Home Assistant for years. Over this time, lots of stuff has changed, but the configuration.yaml and all that stuff has been like a Ship of Theseus.

Clarification: we have been using Home Assistant since before there was an iOS app.

bgoncal commented 1 month ago

Can you try to add the iOS integration again and then check your HA Core logs to see if there is anything relevant there?

WayneManion commented 1 month ago

This is the last 100 lines from the log file after failing to set up the iOS integration (I was using Firefox this time):

    has_devices = await cast(
                  ^^^^^^^^^^^
TypeError: object bool can't be used in 'await' expression
2024-08-06 09:54:52.877 WARNING (SyncWorker_36) [py.warnings] /usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py:1063: InsecureRequestWarning: Unverified HTTPS request is being made to host '192.168.1.1'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(

2024-08-06 09:54:54.064 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 255, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 411, in _async_refresh
    self.async_update_listeners()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 165, in async_update_listeners
    update_callback()
  File "/config/custom_components/opnsense/__init__.py", line 470, in process_entities
    entities = self.process_entities_callback(self.hass, self.config_entry)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/opnsense/switch.py", line 179, in process_entities_callback
    key="service.{}.{}".format(service["name"], property),
                               ~~~~~~~^^^^^^^^
KeyError: 'name'
2024-08-06 09:55:23.877 WARNING (SyncWorker_34) [py.warnings] /usr/local/lib/python3.12/site-packages/urllib3/connectionpool.py:1063: InsecureRequestWarning: Unverified HTTPS request is being made to host '192.168.1.1'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(

2024-08-06 09:55:25.141 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 255, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 411, in _async_refresh
    self.async_update_listeners()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 165, in async_update_listeners
    update_callback()
  File "/config/custom_components/opnsense/__init__.py", line 470, in process_entities
    entities = self.process_entities_callback(self.hass, self.config_entry)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/opnsense/switch.py", line 179, in process_entities_callback
    key="service.{}.{}".format(service["name"], property),
                               ~~~~~~~^^^^^^^^
KeyError: 'name'
2024-08-06 09:55:27.840 ERROR (MainThread) [frontend.js.latest.202407100] Uncaught error from Firefox 128.0 on Linux x86_64
ReferenceError: Polymer is not defined
/hacsfiles/fan-control-entity-row/fan-control-entity-row.js:9:1
2024-08-06 09:55:39.738 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 452, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 543, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 83, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 85, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 242, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 81, in with_admin
    return await func(self, request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 222, in post
    return await super().post(request, flow_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 74, in wrapper
    return await method(view, request, data, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 122, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 368, in async_configure
    result = await self._async_configure(flow_id, user_input)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 415, in _async_configure
    result = await self._async_handle_step(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 518, in _async_handle_step
    result: _FlowResultT = await getattr(flow, method)(user_input)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_flow.py", line 70, in async_step_confirm
    has_devices = await cast(
                  ^^^^^^^^^^^
TypeError: object bool can't be used in 'await' expression
bgoncal commented 1 month ago

That looks very unrelated unfortunately, I see on your screenshot that you have only 4 devices under mobile_app integraton, did you clean up again?

WayneManion commented 1 month ago

No. The extra entries are still there. I guess there are multiple "entries" for the same "device".

Screenshot from 2024-08-06 10-04-12

WayneManion commented 1 month ago

Maybe this is more relevant:

2024-08-06 10:06:55.525 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 452, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 543, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 210, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 85, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 242, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 81, in with_admin
    return await func(self, request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 222, in post
    return await super().post(request, flow_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 74, in wrapper
    return await method(view, request, data, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 122, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 368, in async_configure
    result = await self._async_configure(flow_id, user_input)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 415, in _async_configure
    result = await self._async_handle_step(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 518, in _async_handle_step
    result: _FlowResultT = await getattr(flow, method)(user_input)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_flow.py", line 70, in async_step_confirm
    has_devices = await cast(
                  ^^^^^^^^^^^
TypeError: object bool can't be used in 'await' expression
bgoncal commented 1 month ago

Unfortunately it also looks unrelated, I am still trying to find something in your logs that could explain that but I could not find it yet.

While I do that if you have time (I know it's boring and annoying to ask your wife's phone haha), I would like to see if the same behavior would happen doing the following:

If you also have another iOS device you could try and check how it behaves, it would be nice to find a pattern.

WayneManion commented 1 month ago

I will try to give that a shot when she is home later.

Reminder: my mom's phone is also connected to our HA instance. She has her own house, so getting a hold of her phone to do this stuff is more challenging. I would have to do all of this stuff on her phone, it would be difficult or impossible to guide her through it.

bgoncal commented 1 month ago

But your mom's iPhone is working well right? Or did I misunderstood?

WayneManion commented 1 month ago

But your mom's iPhone is working well right? Or did I misunderstood?

I bring it up to ask if I need to jump through the same set of hoops on my mom's phone as well.

bgoncal commented 1 month ago

No need, just your wife's

WayneManion commented 1 month ago

We followed the removal and re-installation steps. I emailed you a copy of the Home Assistant server log file that was generated during the iOS setup and server configuration process.

When my wife set up the server in the phone app she said the server address was already populated. Would this have come from some kind of network probe? Or would it have been left over from the previous install of the app?

Does the testflight version of the Home Assistant Companion app have additional logging enabled?

jerremyscott commented 1 month ago

FYI - I'm having this exact same issue. I don't mean to hijack the convo, but I'd love to know the solution to the problem. In my case, I noticed one of my kids phones was not updating the location. After jerking with it (renaming entities, etc), both kids' phones stopped working. After troubleshooting (and in frustration) I've done

Wife location is showing properly in HA but the kids are not.

Currently I've deleted the kids mobile devices AGAIN from HA and will delete HA App from each of the kids devices when I get home today. Then I'll reboot and try to reinstall.

WayneManion commented 3 weeks ago

So far, so good FYI. I've been getting good "compliance" from her phone as far as providing location updates. It has been a few days and I don't see any extra, unwanted entries in the Mobile App integration.

Thanks again for your help BPG.

bgoncal commented 3 weeks ago

Great to hear that @WayneManion! I am still debugging to see what could cause that

WayneManion commented 3 weeks ago

I spoke too soon. Screenshot_20240813-181245

bgoncal commented 3 weeks ago

Please export and send me the logs again, also check the event log (companion settings >> debugging >> event log) and tell me if you see any errors related to "webhook"

WayneManion commented 3 weeks ago

I emailed the logs from the server side. The phone logs will have to wait until my wife comes home.

When I deleted my wife's phone entries last time I also deleted the entry for my mom's phone. I think everything was OK with my wife's phone until my mom opened the Home Assistant app and her phone's Home Assistant device entry (just called "iPhone") was created. It could just be a coincidence though.

My mom is not running the Test Flight version of the Home Assistant iOS app.

WayneManion commented 3 weeks ago

I sent over the logs from my wife's phone by email.

593 errors in the log 1361 appearances of the string webhook

A bunch of lines like this:

2024-08-14 20:20:38.088 [Error] [webhookmanager-data] [WebhookManager.swift:565] responseInfo(from:) > no persisted info for LocalUploadTask <40CB8785-549C-43D0-A6B9-21638149BFD4>.<1> (nil)
2024-08-14 20:20:38.088 [Error] [webhookmanager-data] [WebhookManager.swift:565] responseInfo(from:) > no persisted info for LocalUploadTask <88AC5E8A-95CC-470F-9226-DDD8998D12C2>.<2> (nil)
2024-08-14 20:20:38.088 [Error] [webhookmanager-data] [WebhookManager.swift:565] responseInfo(from:) > no persisted info for LocalUploadTask <922ED83A-3C86-4E1B-A4FE-926AD1643947>.<3> (nil)
2024-08-14 20:20:38.089 [Error] [webhookmanager-data] [WebhookManager.swift:565] responseInfo(from:) > no persisted info for LocalUploadTask <D1A0A256-BF0C-400B-AB4A-88BFEC3C7006>.<4> (nil)
2024-08-14 20:20:38.169 [Error] [webhookmanager-data] [WebhookManager.swift:565] responseInfo(from:) > no persisted info for LocalUploadTask <40CB8785-549C-43D0-A6B9-21638149BFD4>.<1> (nil)