Sunday, April 7, 2019

Smart Bulb to track deployment!

Ok - so you have bought the smart bulb and have got bored of changing its colors from the app.
You may have also used Google Home/Assistant or Alexa and said 'Ok Google! Make the Living Room Pink' - boom the color changes to Pink! Interesting to play with for another couple of days but what next?

You may schedule it with the day cycle or with weather to change color and intensity of brightness but I thought why not use it to track the CRM deployment status and outcome? I already have mail notifications enabled in the custom deployment script which sends alerts when the deployment starts, succeeds or fails.

So my target was to implement the highlighted:

What I had:
  • The smart bulb - bought at Amazon on discounted price
  • The native app of bulb - Apart from the ability of changing colors, etc. and scheduling it didn't provide much so I use io.e(get the app) service to integrate it with ifttt
  • ifttt account - you must register and explore this if you haven't. ifttt stands for 'if this then that'
  • Microsoft Flow - A new service my Microsoft which could help me define multiple conditions, checks which ifttt doesn't has.
Since everyone is talking about IOT and Microsoft Flow, so before starting on this work, I did a quick search and got an implementation almost suiting to my need:

Various possible Solutions:
A) Deployment Script -> call ifttt webhook -> control bulb 
This would need writing/updating code in the deployment script to make POST request to the ifttt webhook. This makes sense but is there a possibility to make the mail notification control bulb color without writing any code?

B) Deployment Script -> Mail notification -> ifttt mail applet -> control bulb
This is possible but needs the mail notifications to be very specific which would need code changes in deployment script which triggers the notification. Also I need to authorize ifttt to use my mail box - not very comfortable with it.

C) Deployment Script -> Mail notification -> Microsoft Flow -> ifttt WebHook -> control bulb
This looks like too many steps but I can avoid more coding.

So lets start.

First sort out the ifff setup.
I have configured my bulb with io.e. Using this app I can control the color of my bulb and more
I have added my io.e account in ifttt - its simple once you open the ifttt app and search for io.e and add your account. 
Now I can trigger my bulb in ifttt using various available triggers (like weather, etc.). Lets configure the webhook trigger:
Open the Url in browser to find how to use the webhook:

I created multiple applets for each color control. There should be a better way to do this with just one applet but that optimization is for later

The applets are really simple:

We can test the webhook using any online service - the color of bulb changes (not sure why the site give me an error message - but it works fine):

The color of bulb changes fine:

Create a new Microsoft Flow to trigger on deployment:

I added very basic conditions since I am new to MS Flow - there would be better way to put it rather than multiple conditions:

Everything is based on email subject here so please ensure that you the required details in subject. The trigger is also simple:

Now I run my deployment which is basically a script to trigger solution imports. The script sends a mail to me when the deployment starts, completes or fails with specific keywords in subject.

Using those keywords, the webhook is invoked with various event names:

And the deployment completed successfully:

This is just a fun project and there are lot of additional things to be taken care of for a robust solution.
Next Steps -> Control brightness of bulb/lighter or darker shades to show the deployment progress, but I definitely need to remove the mail message as trigger in that case. :)