How to Integrate Webex Status Indication with Philips Hue

As you probably know, we recently moved from NJ to Austin, TX. In our new place, my office space is challenging as it’s located next to a very strategic place… the kitchen!

So, yes, you will find me closer to the refrigerator. (I do maintain my running routine, so I should be fine.) However, the kitchen is a central place which means that I am more accessible for my family.

Usually, the following happens…

Yes, I did ask them (many times) to be more mindful/considerable and check if I’m on a call before approaching these super-important questions.

Then I asked my son the following:

Well, he is right. He didn’t know that I was on a video call. So… How can I “better educate” my family to know when I’m on a call and prefer not to be disturbed?

My options:

  1. Ask again (and again) - I will do that, but I need something more immediate…
  2. Use some physical indication every time I’m in a meeting (see ?) - That wouldn’t scale…
  3. Relocate my office space - Then I’ll be far away from the refrigerator ?
  4. Leverage & integrate different technologies - Yes! ?

The Plan

Let’s integrate Webex (status indication) with Philips Hue! That way, they will know (see! ?) my availability status!

Cisco Webex and Philips Hue expose their APIs

As both Webex and Philips Hue expose their APIs, that shouldn’t be complicated. Right?

Well, I found two challenges

  1. Webex Token:
    1. Webex API requires a valid and permanent token
    2. The personal token is limited to 12 hours
    3. The guest user token cannot access the “status” data as it isn’t part of the organization
    4. The integration token (OAuth grant using a web browser) isn’t applicable for a simple script
  2. How can I find out if/when the Webex video is turned on/off during a call? ?

After some quick research, I came up with the following solutions

The Code (Mac OS only) ?‍?

To constantly tail the Mac OS “log stream” log (to track if the video is on/off), and at the same time, run the Webex API code portion, I created a multithreaded python script. One thread is dedicated to tail the “log stream”, while the second thread is dedicated to the Webex API integration code.

Let’s review the code

Step #1 - Import the required python modules.

importrequests from phue import Bridge from threading import Thread from time import sleep import subprocess

Step #2 - Define Webex and Philips Hue variables.

# Webex variables myID = "xxx" url = "https://webexapis.com/v1/people/" + myID token = "xxx" ​ # pHue variables bridgeIpAddress = 'x.x.x.x'

Step #3 - Define the Philips Hue connectivity function (Note: the first connection will require authentication using: “b.connect()”).

def access_lights(bridgeIpAddress): b = Bridge(bridgeIpAddress) # b.connect() light_names = b.get_light_objects('name') return light_names

Step #4 - Define the five availability options/functions.

def active(): lights = access_lights(bridgeIpAddress) for light in ['Office Lightstrip']: lights[light].on = True lights[light].hue = 25500 # Green lights[light].saturation = 254 lights[light].brightness = 254 ​ def call(): lights = access_lights(bridgeIpAddress) for light in ['Office Lightstrip']: lights[light].on = True lights[light].hue = 46920 # Blue lights[light].saturation = 254 lights[light].brightness = 254 ​ def meeting_without_video(): lights = access_lights(bridgeIpAddress) for light in ['Office Lightstrip']: lights[light].on = True lights[light].hue = 7000 # Orange lights[light].saturation = 254 lights[light].brightness = 254 ​ def meeting_with_video(): lights = access_lights(bridgeIpAddress) for light in ['Office Lightstrip']: lights[light].on = True lights[light].hue = 65535 # Red lights[light].saturation = 254 lights[light].brightness = 254 ​ def DoNotDisturb(): lights = access_lights(bridgeIpAddress) for light in ['Office Lightstrip']: lights[light].on = True lights[light].hue = 12750 # Yellow lights[light].saturation = 254 lights[light].brightness = 254

Step #5 - Define the function to check if the is video is on/off.

def func1(): f = open("output.txt", "w") subprocess.call(['/usr/bin/log', 'stream' ,'-info', '-debug', '-predicate' , '(process == "VDCAssistant") and (eventMessage contains "Post event kCameraStream")'], stdout=f) return f

Step #6 - Check the Webex status indication AND the video status to determine the Philips Hue light color.

def func2(): while True: sleep(5) headers = { 'Authorization': 'Bearer ' + token } response = requests.request("GET", url, headers=headers) r_json = response.json() myStatus = r_json["status"] with open("output.txt", "r") as file: result = (list(file)[-1]) if "kCameraStreamStart" in result and myStatus == "meeting": # print("Meeting is ON and Video is ON") meeting_with_video() elif "kCameraStreamStart" not in result and myStatus == "meeting": # print("Meeting is ON and Video is OFF") meeting_without_video() elif "kCameraStreamStart" in result and myStatus == "active": # print("Available") active() elif "kCameraStreamStart" not in result and myStatus == "active": # print("Available") active() elif "kCameraStreamStart" in result and myStatus == "call": # print("On a Call") call() elif "kCameraStreamStart" not in result and myStatus == "call": # print("On a Call") call() elif "kCameraStreamStart" in result and myStatus == "DoNotDisturb": # print("DoNotDisturb") DoNotDisturb() elif "kCameraStreamStart" not in result and myStatus == "DoNotDisturb": # print("DoNotDisturb") DoNotDisturb() ​ if __name__ == '__main__': Thread(target = func1).start() Thread(target = func2).start()

The Demo ?

Final thoughts

Related resources

We’d love to hear what you think. Ask a question or leave a comment below. And stay connected with Cisco DevNet on social!

Twitter @CiscoDevNet | Facebook | LinkedIn

Visit the new Developer Video Channel

Link nội dung: https://chodichvu.vn/status-hue-a79056.html