iPhone Companion App & NFC Identification

Hi everyone,

so I have registered my iPhone as device via the official home assistant companion app.
In HA it creates a device with multiple entities looking like in this picture:

The device ID that is being used wihtin HA for this device is:
e81d9b39c45f02d6bd1375270891970a

Now I am using the NFC technology within the companion app in my phone, to scan a NFC tag.
The event which is fired looks like this:

event_type: tag_scanned
data:
  tag_id: 04d5cc67-1f81-4695-87e6-4401e236b156
  device_id: FFBD1E33-A7D1-4040-9EDD-94C4EB1F5057
origin: LOCAL
time_fired: "2022-11-25T20:10:22.670409+00:00"
context:
  id: 01GJR6K7JE1H7MNNEWS2HRD335
  parent_id: null
  user_id: 2e7357cb5c9f4a71819a6d234aaaae14

As you can see the device ID of my iPhone registered wihtin HA and the device ID for the NFC scan are different ones.
My question now is, how can I bring both together using a template?
I would like to see that the NFC Scan was fired by my iPhone without the need for a manual mapping table…

The device_id in the tag_scanned event comes from the config entry of the device, which should map to the same value you’d get from e.g. {{ device_id('device_tracker.your_iphone') }}. I’m not sure why you’re seeing a different one, unless you’re running a version of HA before the scan_tag event in the mobile_app integration, which was a long time ago. The device_id you are seeing there looks like a UUID, which is generally what the app sends in other events and when it thinks the server is too old.

If you go to the app’s settings > Debugging > Export Logs, you can look for the ‘scan_tag’ or ‘tag_scanned’ text in the HomeAssistant.txt log file and it should at least give some indication which of the paths it’s taking – the direct event [for older HA] or the webhook [for newer HA] – which may point to where the issue is taking place.

Thanks for your reply.

The device ID I mentioned comes from the template as you suggested:
2022-11-28 13_27_56-Developer Tools – Home Assistant and 2 more pages - Work - Microsoft​ Edge

As you suggested I checked the debugging logs of the companion app.
With a even result of this:

event_type: tag_scanned
data:
  tag_id: 04d5cc67-1f81-4695-87e6-4401e236b156
  device_id: FFBD1E33-A7D1-4040-9EDD-94C4EB1F5057
origin: LOCAL
time_fired: "2022-11-28T12:14:32.251450+00:00"
context:
  id: 01GJZ2J39VPSETC29WBSZ4NZ5N
  parent_id: null
  user_id: 2e7357cb5c9f4a71819a6d234aaaae14

The corresponding log entries are as follows:

2022-11-28 13:14:30.735 [Info] [hakit-work-queue] [Environment.swift:71] init() > WebSocket: Received: event: for HARequestIdentifier(rawValue: 6)
2022-11-28 13:14:31.390 [Info] [main] [IncomingURLHandler.swift:68] handle(userActivity:) > <NSUserActivity: 0x2803271a0>
2022-11-28 13:14:31.412 [Info] [webhookmanager-data] [WebhookManager.swift:402] send(on:server:identifier:request:waitForResponse:) > starting request: taskKey(session: webhook-io.robbie.HomeAssistant, task: 7), server(742A07D2-E5C3-45CF-A7CE-0DA2A218D3D9), type(WebhookResponseUnhandled), request(WebhookRequest(type: "scan_tag", data: ["tag_id": "04d5cc67-1f81-4695-87e6-4401e236b156"], localMetadata: nil))
2022-11-28 13:14:31.574 [Info] [hakit-work-queue] [Environment.swift:71] init() > WebSocket: Received: event: for HARequestIdentifier(rawValue: 6)
2022-11-28 13:14:31.945 [Info] [hakit-work-queue] [Environment.swift:71] init() > WebSocket: Received: event: for HARequestIdentifier(rawValue: 6)
2022-11-28 13:14:32.402 [Info] [webhookmanager-data] [WebhookManager.swift:620] urlSession(_:task:didCompleteWithError:) > got response: taskKey(session: webhook-io.robbie.HomeAssistant, task: 7), type(WebhookResponseUnhandled), server(742A07D2-E5C3-45CF-A7CE-0DA2A218D3D9), request(WebhookRequest(type: "scan_tag", data: Optional(["tag_id": "04d5cc67-1f81-4695-87e6-4401e236b156"]), localMetadata: nil)), statusCode(200), body({
})
2022-11-28 13:14:32.559 [Info] [hakit-work-queue] [Environment.swift:71] init() > WebSocket: Received: event: for HARequestIdentifier(rawValue: 6)

To me it looks like the app is using webhook exactly as it should, does it?
Please additionally note that I have connected my server via Nabu Casa remote ‘Home Assistant Cloud’ - maybe this makes a difference?

The companion App version I am using is:

With Home Assistant server version:
2022-11-28 13_34_00-Settings – Home Assistant and 2 more pages - Work - Microsoft​ Edge

I believe this will smooth things out for you: Fix mobile app passing incorrect device ID when scanning tag by balloob · Pull Request #82820 · home-assistant/core · GitHub

1 Like