Google Meet - On Air Light Automation
How and why I set up my desk lamp to turn on automatically whenever I'm in a virtual meeting.
These days I tend to spend a lot of my time in Google Meet meetings. I recently created some automated tools to address a couple of problems.
The problems:
- I work from home (even before COVID-19). I have a wife and 5 kids. My office has glass doors. My family often wonders when it is safe to come to talk to me, or when I’m in a meeting. I need a reliable way to let them know when I’m in an online meeting.
- I have a window in my office that lets in a lot of light. Due to the placement of my workstation, my face is often too dark to see in webcam videos.
I’ve tried a few options to solve both of these issues. With number 1, I’ve tried using the door (open vs. shut) to indicate meetings. I’ve tried using a remote-controlled LED light to indicate it. Both had problems. I forget to open or close the door or turn the light on and off. Then there were the battery problems with the lights. My kids kept playing with them, etc.
With number 2, I’ve tried some camera lights to help light up my face. But the latest one I tried wasn’t bright enough, and the batteries would die within 30 minutes.
Now, for a better solution… I’ve been using this for only a day so far, but already I’m liking it much better. It could use some refining, but right now, it works.
Here is a high-level flowchart of how things work:
Hardware needed:
- Smart Plug
- Lamp (I bought \$7 lamp at Walmart)
Getting Tab URLs
I found this AppleScript online that will return all the URLs from all the tabs that are open from various browser windows. I use Brave Browser, so I have modified the script accordingly.
1# shows all urls open in Brave2set urlList to ""34if application "Brave Browser" is running then5 tell application "Brave Browser"6 set window_list to every window7 repeat with the_window in window_list8 set tab_list to every tab in the_window9 repeat with the_tab in tab_list10 set the_url to the URL of the_tab11 set urlList to urlList & the_url & "\n"12 end repeat13 end repeat14 end tell15end if
Bash Script
I had a few iterations of this script. I started in Python, then moved to node.js. Finally, I decided to just write something more simple in bash.
1#!/bin/bash23# be sure to set global env var IFTTT_MAKER_KEY4export MEET_ON_AIR=new56function get_tabs () {7 local tabs=$(osascript tabs.osa)8 # echo $tabs9 local pattern="https:\/\/meet\.google\.com"10 if [[ $tabs =~ $pattern ]] ; then11 echo "found"12 else13 echo "nomeet"14 fi15}1617function check_meet () {18 local found=$(get_tabs)19 local trigger=02021 if [[ $found == "found" ]] ; then22 if [[ $MEET_ON_AIR != "on" ]] ; then23 echo "Turning on the light"24 MEET_ON_AIR=on25 trigger=126 fi27 else28 if [[ $MEET_ON_AIR != "off" ]] ; then29 echo "Triggering light out"30 MEET_ON_AIR=off31 trigger=132 fi33 fi3435 if [[ $trigger == 1 ]] ; then36 local url="https://maker.ifttt.com/trigger/meet-$MEET_ON_AIR/with/key/$IFTTT_MAKER_KEY"37 curl -X POST $url38 fi39}4041while :;42 do43 check_meet44 sleep 545done
Keeping It Running
I created a launchd script. I started with this nice tool and eventually bought a nifty little app called LauchControl that helped me better understand launchd. Here is my plist.
1<?xml version="1.0" encoding="UTF-8"?>2<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">3<plist version="1.0">4<dict>5 <key>EnvironmentVariables</key>6 <dict>7 <key>IFTTT_MAKER_KEY</key>8 <string>[MAKER_KEY_HERE]</string>9 </dict>10 <key>KeepAlive</key>11 <dict/>12 <key>Label</key>13 <string>com.redseam.launchd.meet-on-air</string>14 <key>Program</key>15 <string>[FULL_PATH_TO]/meet-on-air.sh</string>16 <key>RunAtLoad</key>17 <true/>18 <key>WorkingDirectory</key>19 <string>[PATH_TO_DIR_WITH_APPLESCRIPT]</string>20</dict>21</plist>
IFTTT Automation
Part of the reason I switched from Python to Node was that I was looking for a way to control a Smart Life plug I had available. There was a node API wrapper for it. As I started going down that rabbit hole I realized it would be much easier to just use IFTTT.
I already had an IFTTT account with a maker webhook configured, so I just used that. Basically, once you have an account, you can go to https://ifttt.com/maker_webhooks/settings and it will show you the URL your webhook key. You can then go to https://maker.ifttt.com/use/ to test it out. The {event} key string that you use in the URL will be the one you use to trigger off of in your IFTTT Applet.
IFTTT Applets
The Applet is pretty straight forward. You will need to make sure you are connected to the Smart Life service. Basically, there are two Applets. The first one looks for the web request event name meet-on and turns on my outlet. The second one looks for the event meet-off and turns off the outlet.
That’s it!
Now, when I open a Google Meet window or tab, within a few seconds my lamp turns on. When I close the tab, the lamp turns off.
Hardware Update
I found this ON AIR light on eBay for about 30 bucks. I hot-glued some clips to the top of my monitor and mounted it for fun look.