Can I trigger a HomeKit scene when the laptop’s camera is turned on or off

homekitmacbook prowebcam

Like a lot of people nowadays, I'm set up in a home office and I'm often on video calls on my MacBook Pro. My partner sometimes wants to come into my office, but doesn't want to interrupt a video call. We've got a Hue bulb in the landing outside my office, so I was wondering whether I could use that to show whether I'm on a call. Can I trigger a HomeKit scene based on whether my laptop's camera is turned on or off?

Best Answer

It doesn't seem possible to do this with HomeKit, but it is possible to make a script that communicates with IFTTT, and IFTTT will communicate with Hue directly. If you have a Hubitat hub or Home assistant that will also work as a webhook-in-the-middle.

I got through the first part easily: getting a push when camera is opened or closed. To detect camera on:

while true; do log stream | grep -o -m 1 "Post event kCameraStreamStop" > /dev/null && echo STOPPED; done

And camera off:

while true; do log stream | grep -o -m 1 "Post event kCameraStreamStart" > /dev/null && echo STARTED; done

These can be easily converted into a silent, single script that launches at startup. To communicate with the bulbs, we will replace "echo STARTED/STOPPED" with curl to an IFTTT webhook. So you need to make an IFTTT account (If you have used up more than one of your 3 free rules, create another account unless you're paying for premium already), and link up Hue with a webhook. Curl will call this webhook and set your hue bulb to whatever color, Kelvin, and brightness you want or turn it off. If you need more specific guidance then I can help you.

Related Question