3 minutes
GitHub Webhooks With Azure Functions and SmartThings
Ever since I saw Martin WoodWard’s Brian the Build Bunny for Team Foundation Server over 12 years ago, I’ve been fascinated by creating signals for continuous integration builds. Following on from my last post, where I walk through creating and setting up a GitHub Webhook with Azure Functions, the next logical step was to integrate this to SmartThings for complete home automation.
SmartThings has a new REST API, which I’ve created and released a SmartThings NET library, which gives you the ability to interrogate your SmartThings home automation ecosystem entirely using dotnet. This makes it very easy to invoke SmartThings devices from a C# Azure Function, simply by adding the SmartThings NET NuGet package.
Having an Azure Function run as a GitHub webhook gives you limitless home automation capability for your build statuses. For example you could set off the house alarm, turn off the TV or open the blinds when the builds breaks. Then dim the lights and play chilled music when the build succeeds.
Architecture
It all starts with a commit to a repo, which triggers the workflow. This will start the build process, then on completion, invoke the webhook with an HTTP POST of the check suites status. The SmartThings Azure Function checks the build success/failure and then executes the corresponding SmartThings scene using the SmartThings NET library.
Setup
To set this up, first read GitHub Webhooks with C# Azure Functions, then follow the additional steps in the repo here: https://github.com/daltskin/GitHubWebhookSmartThings
GitHub CI - End to End Demo
In the following video, I’m using a Philips Hue light bulb, connected through SmartThings. The GitHub repo has been configured with a workflow and has a GitHub webhook for Check suites
enabled - calling the published Azure Function endpoint. So any commit will trigger the workflow, which in turn will invoke the webhook (Azure Function) and then execute the relevant SmartThings scene.
Here, I make a breaking change directly to the GitHub repo via the portal, by removing the using
statement within a class file and committing the change. This runs the CI build, which then fails (as expected). I then flip quickly to the Azure Portal, watching the live log of the published Azure Function endpoint. The function gets invoked by GitHub with the check suites payload. The function then executes the broken build scene within SmartThings, turning the robot light red. I then go back to the GitHub portal, edit the class file, re-introducing the using
statement and commit the change. This time the Azure Function now runs the success build scene - turning the Robot light green.
azure functionssmartthingshomeautomationsmarthomegithubgithub actionsgithub workflowswebhooksc#csharpcontinousintegrationcicicd
431 Words
2020-08-16 19:54 +0100