eliottrobson / homebridge-macos

Homebridge plugin to track Mac OS events
MIT License
7 stars 1 forks source link

Question/Feature request: time machine backups #3

Closed martindinicolino closed 3 years ago

martindinicolino commented 3 years ago

Would it be possible to use this plugin to detect when a time machine backup has finished?

The idea would be to turn on the external hard drives connected to the Mac at a specific time of the day via a smart plug, let it complete the backup, have it unmount (still looking for a solution on how to do that) and then turn the smart plug off.

Any help would be appreciated, I can't code but I am willing to learn.

eliottrobson commented 3 years ago

This is something that will not be supported by this plugin. The reason is that time machine backup status isn't really such a boolean flag. "has backed up" is very subjective to the time since the last backup, unlike whether the screen is on.

However, I'll certainly try to point you into the right direction.

The first thing you'd need is an automation pipeline, something to trigger the smart plug at a certain time, run the backup, unmount and turn off the plug. The simplest option would be a bash script that you trigger via a cron job.

The script would need to do something similar to below (pseudocode):

call homebridge api to turn on plug
loop until drive is mounted (with timeout of 5 mins or so)
start time machine backup and block script until complete (look at tmutil)
unmount drive
call homebridge api to turn off plug

I haven't used homebridge directly, but I would expect you would be able to use CURL to trigger the server methods directly.

I am going to close this issue as it sits outside the realms of this repository, but feel free to continue the discussion and I will help you as much as I can.

martindinicolino commented 3 years ago

Thank you so much for your reply, i will be looking into it

martindinicolino commented 3 years ago

With a lot of help here and there I was able to get it working by using LaunchControl and Pushcut, I can truly recommend LaunchControl, but believe there should be a more elegant solution than Pushcut out there (as it involves receiving and tapping on a notification on the phone to turn off the drives every time). There is definitely room for improvement, so if somebody happens to find this and has a suggestion or is interested in how to replicate the solution, follow the discussion at https://forums.macrumors.com/threads/turn-homekit-smart-plug-off-upon-timemachine-backup-completion.2297742/

@eliottrobson thank you again for your help, and pointing me in the right direction!