I was looking for a way to use my Mac as a “motion sensor”. If I’m using my Mac, I want Home Assistant to see that my office is occupied, even if I’m not moving around enough to trigger a motion sensor.
Hammerspoon and my mqtt-sleepwatcher Spoon to the rescue:.
Hey Dan, thanks for writing this! I have set this up to monitor my desktop at work and my laptop at home. This provides another good metric of where I spend my time. If the computer is active and the screen is unlocked, I’m almost surely sitting in front of it.
I ran into some issues with hammerspoon flaking out and not reporting state anymore and idle timer would not be called. Looking through their github issues, it sounds like the timer object is being eaten by garbage collection. I’ve submitted a PR that might fix this according to this https://github.com/Hammerspoon/hammerspoon/issues/1942#issuecomment-430450705
Just wanted to post here in case anyone else tried this and ran into the same issue.
are you using something similar nowadays? I can’t get your Spoon to work. Within the Hammerspoon console I can see the correct states but for some reason the binary_sensors in Home Assistant stay ‘off’ all the time. In case there is already a better alternative I’d prefer not having to investigate where it goes wrong and trying to fix it myself.
For any future readers, you can still use Hammerspoon but I put together a different config for macOS 15+. It may work on older versions but I don’t have another machine to test it on.