DEV Community

Andy Piper
Andy Piper

Posted on

Shortcut to check Cheerlights

I've been playing with the Cheerlights API again lately (I also used it in my Pi Zero Cluster).

What is Cheerlights?

CheerLights is an “Internet of Things” project created by Hans Scharler in 2011 that allows people’s lights all across the world to synchronize to one color set by Twitter. This is a way to connect physical things with social networking experiences.

I thought it might be fun to build a quick Shortcut for iOS/macOS so that I can ask what the colour is currently set to. Why? Firstly, because I can... and secondly, sometimes I might not have another device handy to confirm a result with, if for any reason I want to check my gadget or project is showing the colour I should expect. Honestly though, it's a bit of a stretch, but interesting to experiment with building Shortcuts.

Shortcuts app on macOS showing the workflow for the Cheerlights shortcut

This is super simple - we only want to know the colour by name (in this case, we don't care about the RGB or Hex code values - but in my next post, I'll be doing something with those...). The basic ThingSpeak channel has an HTTP endpoint which returns the text of the colour name.

Try it out at the command line:

$ curl -s https://api.thingspeak.com/channels/1417/field/1/last.txt                                                             purple
Enter fullscreen mode Exit fullscreen mode

No additional processing needed here. To build it step-by-step in Shortcuts:

  1. Get Contents of URL action, configured with the URL https://api.thingspeak.com/channels/1417/field/1/last.txt - this will return a plain text value, as we saw in the command line example. this is all we need to do, but in order for Siri to have a slightly nicer response to us, we can add a few additional steps

  2. Set Variable action, putting the value from the URL into a variable named cheerlights.

  3. Replace Text action, creating a string "Cheerlights are currently set to ZZZ", replacing "ZZZ" with the value of the cheerlights variable.

  4. Show Result action, to display or say the result. It turns out that this is important, otherwise you would need to use the Speak Text action to have the result read out (and this uses a different voice to the regular Siri voice you've chosen).

Clicking the Run button results in a pop-up:

Pop up window showing the text "Cheerlights are currently set to cyan"

Shortcuts sync via iCloud, so now you can ask Siri for the current Cheerlights colour from your Watch, iPhone, HomePod, etc 💡

"Hey Siri, Cheerlights colour"

"Cheerlights are currently set to red"

One final thing you can do is to help Siri with the pronunciation. In iOS Settings, Accessibility -> Spoken Content -> Pronunciations, add a new entry. Enter the phrase as "Cheerlights", then hit the microphone in the Substitution field and say the word. You'll get back a list of phonetic options to tap through to try Siri's response, and you can choose the one you like the best. Nice!

iOS Settings panel showing the Pronunciations value configured here

Cheerlights also has an MQTT interface, and you can set new colours using Twitter. If you are building something that needs a colour or that might be fun to synchronise with other lights, take a look, it's a great API to play with.

If you'd like to chill out with Cheerlights, check out the soothing Twitch channel 🎵

Latest comments (0)