Shortcut to check Cheerlights
Tags: cheerlights, shortcuts, ios
Published: 2022-02-06 17:03:17

I've been playing with the [Cheerlights API](https://cheerlights.com/cheerlights-api/) again lately (I also used it in [my Pi Zero Cluster](https://dev.to/andypiper/building-a-compact-pi-cluster-1pia)). 

### What is Cheerlights?

> CheerLights is an “Internet of Things” project created by [Hans Scharler](http://www.nothans.com/) 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jpjzrykj9d6994zpuv9z.png)

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](https://dev.to/andypiper/making-a-cheerdot-with-micropython-3ocf), I'll be doing something with those...). The basic [ThingSpeak channel](https://thingspeak.com/channels/1417) has an HTTP endpoint which returns the text of the colour name.

Try it out at the command line:

```text
$ curl -s https://api.thingspeak.com/channels/1417/field/1/last.txt                                                             purple
```

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"](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/38yiscirlr51d25ksh1m.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pj090jqe76r9lzzt8vxn.jpeg)

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](https://www.twitch.tv/cheerlights) 🎵