I wanted a way to report the screen state of my Macbook as an entity in HA. I’m primarily using it as a means to harden lighting automations but of course it can be used for anything you want.
The configuration requires Hammerspoon and a long lived HA token. I’m happy to move this to MQTT if there’s interest. OSX used to provide hooked for lock screen state but they have since been deprecated.
At the present time it provides two binary sensors: screen lock state and screensaver state. macOS can technically be unlocked with an active screensaver so I found it’s easiest to just report both then handle it in the automation however you choose.
See the repo here: macOS State for HA