Search code examples
homekit

How can I access historical data from HomeKit sensors -- or alternatively log this data myself


I have an outside and inside temperature sensor on HomeKit. Recently I ran into the problem that I wanted to check the temperatures a couple of days ago. As far as I have been able to determine, there does not seem to be a way to get historical data from HomeKit.

As an alternative, would it be possible to log homekit data yourself? I know that iOS apps can request access to HomeKit data, so that could be one way to go about it. However I would prefer to do this also when my phone is switched off / without network. Is there a (web)API that I can call in order to get access to this data from (say) a Raspberry PI, so that I can log this data on regular intervals?


Solution

  • There is indeed no way to access historical data from Homekit devices (unless you're able to do so though the device-maker's cloud).

    As far as I know there is NO way to get to HomeKit data if you're not an iOS/macOS device. Four years ago Homekit opened up the devices-end so that third party devices could be used. There does not seem to be a similar move on the controller/reader end.

    iOS apps can only access data while they run in the foreground -- supposedly for security and privacy reasons (good reasons as far as I'm concerned :) ). So unless you have an iOS device lying around that you're willing to sacrifice for this, this is a no go. Possibly you could get this to work on a mac that is running 24/7; I'm not sure what the restrictions are there.

    There is something you can do if you want to log this data. Using Shortcuts for Home, you can have a small Shortcut-program run on your home hub (usually Apple TV or HomePod). You will have access to fewer commands than in full (iOS) Shortcuts, however thing you can do is read out the value for HomeKit devices, and make HTTPS (post) calls.

    The iOS Home app unfortunately only allows you to schedule this shortcut to run once a day, however using the third party (free) Eve app you schedule it to run once every 5 minutes. Just make sure you start with setting up the timer, and only then transform it into a shortcut -- because of bugs/limitations of the way Apple works, it doesn't seem to work the other way round.

    I did a writeup of this whole process a couple of days ago, including a way to post the data to a Google Sheet, for a 100% free solution.

    Example Google Sheets with Homekit log