Blog

Status Lights

09/06/2020
Is this completely overkill? Yes and no
Notification Light - This is showing there is an unread Teams notification

Notification Light - This is showing there is an unread Teams notification

Status Lights - showing that both me and my partner are not on the phone, or have our statuses set to busy

Status Lights - showing that both me and my partner are not on the phone, or have our statuses set to busy

Door Light - showing that my status in teams is Available

Door Light - showing that my status in teams is Available

So those who know me know I love Hue lights to show status. This all started for me back in 2015 when my previous employer, Zengenti, decided to start Lockdown (which in retrospect feels like a bad name now), and my project was "Build Status Lights", which involved hooking into our Continuous Integration server and showing the current status to a bunch of Hue lights installed in the celing of the Dev office. Red for a broken build, Amber for a building build, throbbing Amber for a build running unit tests, throbbing Green for a build deploying to our test environment, and solid Green when a build is built, succeeded all unit tests and deployed.

You can see a short video on Lockdown 2015 which includes my project here: 

So yeah, I love any excuse to use a Hue light to display a status.

Both me and my partner work from home, and so it's common for us to pop into the others office with a cup of tea or something, or send an short message via Alexa etc. Because we both do calls with our work, this could lead to an embarrassing situation if someone walks in on the other during a meeting, or sends an alert on Alexa during a meeting etc. So a system which I have slowly built up over time helps us solve this problem once and for all.

We both have two Trådfri colour lights in our offices (they aren't perfect but they are sooo cheap compared to Hue - which I do use elsewhere too), the left light showing the status of the person's office it is, so they know what they're "broadcasting", and the right light showing the status of the other person's office.

This has also been expanded to a light outside my office (not my partners office... yet), also mirroring this status. For a long time I used Zigbee buttons to control this light, pressing it when starting a call, and pressing it again when coming off a call. This also handles Sonos, so that if a song is playing in my office, and my office only, it pauses the music, if it's being broadcasted elsewhere, like my partners office for instance, then it will ungroup me from the playing music, so as not to interrupt my partners music, and vica versa.

While this works perfectly, I've always longed for a more automated solution, because occasionally we forget to press our buttons and the status lights don't match. That can't do!

Years ago, I had this working with Skype. Skype used to have a local API, so a program could hook into the local API and get information on the current state, if on a call etc. But Microsoft in their infinite wisdom removed this years ago, and then with the switch to Teams, this wasn't brought back. Inspired by Hanselman's blog, I tried the new Presence API on Microsoft Graph, checking the status every 2 seconds. This worked, but there was a bit of a lag, and it's quite heavy constantly pinging Microsoft's servers every 2 seconds (Microsoft please make this a PUSH API, where you can register for events and then they get pushed to you via a callback URL or something). When answering the phone the music played on the call for a second or two before stopping - not ideal!

So I discovered that Teams logs some useful information, such as Status, if you're on a call etc. So I developed a program which monitors the logs and parses them to get a good indication of the current state of Teams. So I know if there's New Activity / Unread messages (will come in handy later in this post), if a call is Pending/Active/None, and what state I'm in, Available, Busy etc. So this enables me, through NodeRed and Home Assistant to parse what my program sends it, and then automagically update the lights depending on a combination on if I'm busy and don't want to be disturbed, or if I'm on a call etc and changes the light accordingly. Perfect.

But I couldn't stop there, so I went one step further. Being a remote worker, our communication tools are very important. Because I use multiple screens (and no speakers), I would sometimes miss the Toast notification for Emails or IMs on Teams, so I added yet another Trådfri bulb, for notifications. This uses the New Activity / Unread messages I mentioned earlier to set the light to Purple if there's a teams message I haven't yet read.

We use Outlook for Email, and I wanted a way to get the unread status out of Outlook too. I finally realised that this was trivial to do with a VSTO plugin. A simple app, that installs into Outlook, listens to events triggered from new email or changed email, then counts the unread emails if more than 0, send a true to NodeRed and Home Assistant, and if 0 send a false. This means that if I have unread mail, the light shows blue. If I have unread Teams messages and unread Emails, then the bulb alternates between blue and purple every 30 seconds or so until I read the messages.

Zoomed out view of work related NodeRed workflows

Zoomed out view of work related NodeRed workflows

Is this completely overkill? Yes and no. There's no doubt these lights do definitely add some value to our working lives, helping us navigate working from home, and in my case allowing me to glance at the state of my emails and teams. It has definitely made a massive improvement to my working day, I now hate to see the light on so make sure I read emails and teams as quickly as possible. But yes, this is a passion project of mine, I love playing with Hue lights and coming up with elaborate over engineered solutions for simple day to day issues, it's fun!

I've open sourced the code for both my outlook addin, and my teams log monitor over on GitHub, so feel free to clone and play around with if you want to.

Follow my listening habits... live!

22/05/2020

Have you ever thought, you know, I wonder what Brett Jenkins is listening to right this very second? Of course you have...

So this is one of those things that I did, just because I can, rather than to solve any particular purpose. I thought I'd do a write up on how I've personally approached it, and tell you a little about how my home automation system works along the way. 

So I've been using Home Assistant now for a number of years, before that I used openHAB, I switched because openHAB made a lot of changes moving to v2 which was going to cause me to make a bunch of changes, so I thought I'd use the opportunity to try the new kid on the block, Home Assistant, which I still use to this day, running on a docker container in my Linux docker host vm in the garage. 

So Home Assistant talks to all my home devices, including my sonos devices. For my automations I use a program called NodeRed, which is amazing. It provides a drag and drop experience which actually is extremely powerful, far more powerful in my experience than Home Assistants YAML based automations, as you can easily write complex logic by making loops, writing javascript, creating subflows (like methods / functions) that can be reused elsewhere etc. 

So back to the topic at hand. What I do is when Home Assistant registers a change in music on my office sonos, a NodeRed automation runs and fires off a REST put request to this server, hosted on AWS. This site is using Umbraco and using my native language of C#, so it's trivial to add a WebAPI controller to take that request (limited to my IP for security), which is an JSON object, parse it to a C# object, and then I store that value in the runtime cache. Currently this site is running on a single server, and I don't care about persistence if the site crashes, so it's the perfect solution for now. Of course, if I ever decide to run a couple of servers, I'll have to move it either to a database or a 2nd level cache, but I'll cross that bridge when I come to it. 

Then on the UI side, I'm using vue to render the markup and I use SignalR in order to push the changes to the browser (it will send the currently playing song on connection), SignalR is so fast that I find that sometimes the text changes on the website before the first note has played on the song! It's also so much nicer and more efficient having the server push the changes rather than polling for changes every X seconds.

I had a slight problem in that I wanted the vue component to output different markup in different places depending on mobile/desktop. At first I attempted to tackle this problem with the age old user agent sniffing technique, which is always rubbish. Luckily I found vue-mq, which uses media queries, the same way you can do in CSS, creating truly responsive vue components!

Simples. 

It was a good exercise. Even though I use Vue daily in my day job, I've never personally had to set it up and integrate it into an existing website, using webpack and typescript which was made harder by npm installing beta versions of software which broke everything slightly smiling face, but got there in the end, and it was a great learning experience. I also enjoyed working with SignalR, which I've never had a chance to play with before, and loved how easy it was to use and how efficient it is.

Anyways, I digress. This was an interesting little project that has added a rather pointless feature to my website, my partner likes it though, so can't be all bad!

RSS Feed Logo