HomeKit HMHome and HMRoom identifiers / extra metadata
Asked Answered
J

3

6

In my application I am using HomeKit. You can add/remove HMHome and HMRoom object, but I would also like to add some metadata to them. For example in my application I want to be able to add an icon to a HMRoom and add an Array of items to it too.

My solution is that I use it in combination with CoreData and store the extra information about the HMRoom, but there is no way to identify the HMHome and HMRoom objects, other than their name. This would not be a problem if my application would be the only application in the world to edit the HomeKit objects, but of course there could be other applications, also adjusting the HMHome and HMRoom objects (removing them, renaming them).

So I would really have a problem, when the user does one of the following things:

  1. Start my application
  2. Add a HMHome and HMRoom object
  3. Add some metadata to the HMRoom object, through my application, which is stored in my CoreData database
  4. Quit my application
  5. Start another application and rename the HMRoom they just created
  6. Start my application again

Because there is no known identifier for the HMHome and HMRoom objects, I cannot find the metadata I stored in CoreData anymore and that metadata is actually lost, because I can no longer match the name with the created HMRoom with the data in my CoreData database.

So, my question is: Is there a way to 'identify' HMRoom and HMHome objects other than their name?

Jerrilyn answered 14/2, 2015 at 6:57 Comment(0)
D
3

In iOS9, you can use the uniqueIdentifier to always identify the same object. This UUID stays the same whether the room gets renamed.

Doom answered 10/12, 2015 at 15:58 Comment(5)
Can you elaborate? Not sure what you're referring to.Acutance
Unfortunately, the UUID string seems to change each time on fresh app start.Acutance
Be careful. the uniqueIdentifier of a HomeKit object (HMHome, HMAccessory, ...) are not identical over multiple devices of the same iCloud account. Just make this simple experiment: print uniqueIdentifier of an HMHome on a phone, then do the same on another phone (having same iCloud), you will see the 2 uniqueIdentifier are totally different. Not sure yet how we can identify a HomeKit object.Arrival
Yes, the UUID is generated when the database on the phone is created. The UUID should remain the same. So a fresh start, shared home on another phone, or just resetting HomeKit on the phone will create different identifiers when their HomeKit databases get populated.Doom
It is also important to note that this does not work on iOS simulator. On iOS simulator you will get different home ids on each app start. However, on iOS device home ids are the same on each app start.Knisley
C
1

According to the documentation there is no other identifier for HMHome and HMRoom than the name. But they both have accessories property, and HMAccessory has the identifier property, which is persistent (at least until the user removes an accessory and adds it again, which wouldn't be a common thing to see, I hope).

So you can save accessories assigned to a given home or room along with other metadata. And if the home's or room's name changes, in most of the cases you should still be able to detect what the original name was, looking at the stored accessories.

Cucurbit answered 15/2, 2015 at 20:26 Comment(1)
I think this is the best possible solution at the moment. It is very unlikely that a user will be moving Accessories between Homes, so we can confidently use the Accessories in the Home to ID it. However, the same cannot be assumed about users moving Accessories between Rooms. I think an extension to this approach would be to create inventories of Home & Room Accessory IDs and use this as a "fingerprint" for each object. If a Home or Room name changes, you could refer back to the "fingerprint" to re-identify it. You could also allow for percentage matches to account for accessory movement.Ratepayer
H
0

You can use matterControllerID now to identify homes. It is unique to each home, and the same across devices.

Hyden answered 9/5 at 23:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.