Skip to content

Latest commit

 

History

History
95 lines (53 loc) · 6.2 KB

README.md

File metadata and controls

95 lines (53 loc) · 6.2 KB

Smart Xmas

Sparkle Status

A simple project showing you how to easily control smart devices in your home from GitHub Actions and put a bit of ✨ into your repos.

YouTube video tutorial

Prerequisites

  • Smart power strip [UK] [US]
  • IFTTT.com account
  • Thing to power - i.e. fairy lights, the gaudier and over the top the better

(Optional) If you want to trigger sound with you lights then:

Configuration

First of all set up your smart power strip using instructions from your vendor. Lots of the inexpensive unbranded smart devices are OEM devices making using of the Tuya cloud network. (The 'Smart Life' application used by many of these is a particularly common front-end to the Tuya API). Regardless of the provider, look for compatibility with IFTTT as that is how we are going to drive it.

Nearly all the applications will allow you to configure scenes or automation that happens on a trigger or when manually triggered (i.e. 'tap to run'). I created a scene called TreeAnimate which simply switches on all the power to the power strip, waits 30 seconds and then switches it all off again. However depending on your smart device you can do a lot more if you wanted, for example adjust the color of your RGB lighting, switch on a lava lamp or confetti filled leaf-blower etc.

Smartlife Scene Configuration

If you want a sound to accompany your activity then the easiest way to do this is to hook up an inexpensive sound-board from Adafruit. It's a simple device that shows up as a mass storage device when you connect it to your computer. You upload files using a particular naming convention and then they play when the trigger pin is connected to ground.

Smartlife Scene Configuration

See the Adafruit product tutorial for more information. For our purposes we'll just wire tigger pin 0 so that it's permanently connected to ground and that way it will automatically start playing the sound as soon as there is power to the device.

If Kevin had access to these imagine what a different movie Home Alone would have been - wonder how Disney if going to address that in the reboot?.

Animated Gif of Home Alone movie

IFTTT Configuration

Next up, we need to configure IFTTT to set off our TreeAnimate scene when it recieves a webhook.

The reason we're using IFTTT is that most smart device manufacturers already integrate with it. If you are wanting to configure a Tuya.com based smart device from code directly then take a look at the tuyapi project maintained by Max Ison - however that relies on being in the same network at the device itself and we want to be able to trigger your device from GitHub's Action servers running in the cloud.

  1. Create an account with IFTTT then follow your manufacturers instructions for configuring and authenticating your smart service with IFTTT.

  2. Next, create your IFTTT workflow. For the this trigger select Webhooks, then 'recieve web request' and give your event a name. I rather unimaginative called mine do_hook

IFTTT Trigger

  1. For the that action, select your smart device vendor and then select the scene you wish to activate. In my case TreeAnimate

IFTTT Action

  1. Next you'll need the URL (with key) that we need to trigger the webhook. Go to the Maker Webhooks service and select 'Documentation' in the top right land side. IFTTT webhooks are triggered using the following URL pattern:
https://maker.ifttt.com/trigger/{EVENT}/with/key/{KEY}

In our example, the event is do_hook. We want copy the key value and store it as a repository secret in our repo.

IFTTT Action

GitHub Action Configuration

  1. The in GitHub project you want to automate, go to 'Settings', then 'Secrets' and 'Add a new secret' For the key name use IFTTT_KEY and paste the key value from IFTTT.

  2. Then in the project select 'Actions' and select 'New worfflow'.

  3. In the top right hand side, select 'Set up a workflow yourself'. Name the file something meaningful (I called mine sparkle.yml). The workflow itself is very simple. It simply uses curl to trigger the webhook when someone stars the repo in GitHub.

name: sparkle

on: [watch]

jobs:
 sparkle:

   runs-on: ubuntu-latest

   steps:
   - name: Call IFTTT to trigger lights
     run: curl -X POST https://maker.ifttt.com/trigger/do_hook/with/key/${{ secrets.IFTTT_KEY }}

Hit commit and you are ready to go.

Extensions

While I did this one for fun just because I wanted a bit of holiday sparkle to cheer up a gloomy evening, you can use the same mechanism to trigger anything. With the use of conditional workflow steps you coudld easily turn the lights red and sound an alert when the build fails. Or maybe something less stressful and turn down the lights and play some nice gentle music anytime someone leaves a sparkly heart in response to your pull request. You can easily get the scenes to trigger multiple devices all around your office.