Using Maker Api - How to light up a bulb if you are on a video call?

This is my approach and it works! I am sure someone already played with this. I saw a few alternatives around. I share the process so you can point me to things that I could/should do differently since I am just starting with Hubitat.

My requirements:

  • Instead of going with Zoom webhooks or similar, the key for me was not if a specific app is running or not; the key is if I am using the webcam. In my case, if I am on a call without a webcam, I am ok to attend to interruptions. So I decide to monitor my webcams, and if they are running ->, I turn the light red.
  • I work on mac
  • I have 2 webcams

Future requirements:

  • In the future, I want this running only if I am at home, so this is not turning the light on when I am at the office.

Solution:

Code:
To check if the camera when on or off (sorry, only mac), To test, play around with your camera:

log stream --predicate 'eventMessage contains "Post event kCameraStream"'

This will give you a live log that you can pipe into a script.
log stream --predicate 'eventMessage contains "Post event kCameraStream"' | xargs -I{} ./webHooksCamera.sh "{}"

For this webHooksCamera.sh file:

 ACTION=""$1""
if [[ "$ACTION" == *"kCameraStreamStart"* ]]; then
  curl 'https://cloud.hubitat.com/api/{YourAPIID}/apps/{YourAppID}/devices/{YourDeviceID}/arrived?access_token={YourToken}' -s  > /dev/null
fi
if [[ "$ACTION" == *"kCameraStreamStop"* ]]; then
  curl 'https://cloud.hubitat.com/api/{YourAPIID}/apps/{YourAppID}/devices/{YourDeviceID}/departed?access_token={YourToken}' -s  > /dev/null
fi

This could be nicer if I filter the string properly. But it does the trick.

So, I move webHooksCamera.sh to ~/bin/webHooksCamera.sh So I can test and modify the queries easily.
I create another sh with:

#!/bin/bash
log stream --predicate 'eventMessage contains "Post event kCameraStream"' | xargs  -I{} ~/bin/webHooksCamera.sh "{}" &

Notice I executed in the background &, the app was hanging when I close the computer if not.

And use this method to create an app: How to create simple Mac apps from shell scripts · Mathias Bynens

I got this app and added it to my user login apps in preferences. You can do more fancy but kinda like to see the app there and not forget about it.

Details

  1. I have 2 webcams, so if I had to change between them, the system failed. Since the virtual device gets 2 updates too quickly. So I added this minute delay in the "simple rule," and the problem is solved.

  2. I didn't find the right way to check if the camera is running or not; the methods I found are only good with the integrated camera, but not with external ones. If you only use the default one, check this out: GitHub - sindresorhus/node-is-camera-on: Check if the built-in Mac camera is on

  3. For future requirements, I can make the rule more complicated (I know nothing about the rule machine and check if my phone is at home and light the bulb), so I create this virtual device.

  4. I may create a virtual presence device per camera in the future. You can get the id from the log stream.

Disclaimer
I didn't spend much time doing this, so If anyone has a better method, I'll take it :slight_smile: I was playing around, trying to learn a little more about Hubitat.

ps: Is this topic the right place for this type of post?

Update thread I changed the method to create the app for something more simple.
Update topic I changed the topic from maker API

5 Likes