Search code examples
c#homekit

Show lock status of windows pc as a tile in the home app on iOS


I already made a service which sends a push notification to my iPhone whenever my pc locks/unlocks, pretty simple. But it would be really nice if i could see the lock status in my home app. Guess i will need to have some kind of "bridge" running as a service on my pc.

So, i was wondering if any of you guys have tried something similar? and can point me in the right direction. If it's even possible of course.

Screenshot of current service notifications


Solution

  • Well, it definitely is possible. I'll give you a short outline:

    1. Get the HAP-Spec: https://developer.apple.com/support/homekit-accessory-protocol/
    2. You need to find a suitable representation for your PC inside the HomeKit ecosystem. That is, think about what Services your PC should expose and how you want to map them to the Services defined by Apple. The problem is that, while the Home app can display any accessory - even if it is a custom one, it will only display some generic information if it doesn't know the accessory's services. I suggest using the Lock Mechanism or Switch service. Choose the one that results in the best-fitting graphical representation inside the Home app. (Check out the spec, there are a lot more services).
    3. Implement your HomeKit accessory: I suggest using https://homebridge.io or https://github.com/homebridge/HAP-NodeJS directly. You may also want to take a look at https://www.npmjs.com/package/homebridge-http-switch, which wouldn't require any HomeKit related coding from your side.
    4. Host your HomeKit accessory: The thing here is that the Home app is going to request the accessory's current state each time you open it. Thus, hosting the bridge on your pc is maybe not the best idea (if your PC is locked and sleeping or powered off, the accessory ether won't answer, or you need Wake on Lan and then the PC-fans and Monitor turn on...depends on your setup). You probably want to host your bridge on a raspberry pi that is always running.
    5. Write some script that sends a http message to your bridge whenever the pc is locked/unlocked.