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:
- RGB bulb
- I will consider my webcam as a device, so I created a virtual device. Virtual Presence. This device will report when I am using my webcam "Webcam Presence?". This way, I will be able to automate more stuff in the future, check stats, and show on.
- I created a new Make API. You only need to expose the new Virtual Device you just created. The bulb is not wanted here. I exposed this API outside because I work under a VPN.
- So from now on, I can use:
- I create a rule with the "simple rule" app associating this Virtual Device and the Bulb. Notice that I add a minute delay to turn off the bulb. I will get into that.
- Now, you need to call this API. If you don't want complications, you may want to use: CameraUsage on the Mac App Store
And you are done. I didn't go through this path; I did something different just to play around. I may reconsider.
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
-
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.
-
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
-
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.
-
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 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