Here at Citrix, we’re working hard to bring awesome workspace IoT solutions to our customers, leveraging our Octoblu Integration of Everything platform in many cases. But, just like our people, Octoblu can play hard as well as work hard, and the holiday season gives it a good opportunity to let its hair down and have some geeky fun.

Last Christmas, I used Octoblu to automate an illuminated tree topper on the Christmas tree in the Citrix office in Cambridge, UK. Fun, but why stop at just the top of the tree? Could Octoblu add some fun to the entire tree? Can we go beyond the tree and automate an entire Christmas party? Well, it turns out all of this is possible. Here’s how.

Internet-connect Christmas tree lights

Painting the LEDs greenI wasn’t interested in just turning on and off entire lights strings or even groups of lights – I wanted to be able to turn any light to any colour, independently of the other lights. This meant using individually-addressable LEDs – sets of LED lights that can be connected to a microcontroller of some kind and have each LED separately controllable for colour and brightness. These LEDs are now readily available in many form-factors including wired together in long strings similar in style to traditional tree lights. I chose to chain together two strings of 50 LEDs based on the industry-standard WS2811 LED driver. Unfortunately the particular sets I bought came with red, white and blue wires which, although patriotic, doesn’t look great on a green Christmas tree and therefore a coat of green acrylic paint on the wires and LED bodies was necessary.

WS2811 LEDs are driven by a single control wire chained from light to light, with 5v power and ground going to every light. There are many open-source tools and libraries available to drive these LEDs, I wanted to use them with a Raspberry Pi directly so I used the popular and excellent rpi_ws281x library and the rpi-ws281x-native NPM library so that I could use it from Node.js in an Octoblu connector. The electronics were very straightforward. The input end of the LED string (the female header in this case) connects directly to the Raspberry Pi’s GPIO pins using pin 18 (any PWM-capable pin will do – 18 is the default for the library) and ground. The LEDs can draw quite a bit of power so I connected the 5v line to the LED strings to a separate 5V power supply unit. The Raspberry Pi’s GPIO pin is a 3.3v output and the lights assume 5v – for me this turned out not to be a problem however some manufacturers’ LEDs will need this signal to be level-shifted (Adafruit has a good tutorial on this).

Another gotcha to be careful to avoid: the rpi_ws281x library uses the Pi’s PWM hardware – the same hardware used by the Pi’s onboard audio output. If something tries to use the audio while we’re trying to control LEDs there can be all manner of weird LED and audio behaviour. The library’s README has some details on one way to avoid this.

Christmas tree with coloured LEDsThe next step was to hack up an Octoblu connector to allow Octoblu flows (automation programs running on the platform) to control the LEDs. This is a Node.js service that runs on the Raspberry Pi and makes a connection into the Octoblu mesh network. If you’re playing along at home and want to try out this connector then please go ahead but you’ll need to create a generic device, grab the UUID and token, populate meshblu.json and run the connector from the command line – you’ll probably need to have a bit of Octoblu experience to do this, but see the appendix below for some pointers.

I added a number of patterns to the connector – Octoblu can choose a pattern by sending a message to the connector. One pattern is a virtual VU meter displaying the sound level from a microphone attached to a USB sound card plugged into the Pi. Because the lights are placed on the tree from bottom to top this makes the light creep further up the tree as the sound level increases.

Getting the party going

OK, I now have an Internet-connected Christmas tree but that’s no fun on it own. The next step was to join it with some other IoT gadgets and have Octoblu integrate them all. The goal here was to have a single command to start the Christmas party: to turn off the main room lighting and traditional tree lights, to turn on other festive lights, to put the LEDs into VU mode, and to start the music from a playlist. This was to be complemented by a single command to put it all back to normal afterwards: killing the music, turning the main room lights on and stopping the VU display on the tree LEDs.

Firstly, I added control of two LightwaveRF switchable power socket units (these are similar in style to Belkin Wemo). One of these controls the traditional lights on the Christmas tree and the other controls some lights on a garland draped across the fireplace. I also hooked up the LightwaveRF main ceiling light and table lamps.

Next, I added control of the Kodi media player – this lets Octoblu call the Kodi API to start the Christmas party playlist or to stop the player. This is done with a Kodi add-on that connects into Octoblu.

Bringing it all together in an Octoblu flow is simply a matter of connecting input stimuli via “compose” nodes that form suitable messages (e.g. which mode the LEDs should be in or what state the LightwaveRF sockets and lamps should be in) to the three things driving the physical devices via connectors.

The two triggers, “start party” and “stop party,” can be called through the Octoblu web interface but more interestingly they also appear as URLs that can be sent HTTPS POST requests to trigger them. This meant I could allow voice commands via Amazon Echo to initiate the start and stop actions. I used the Alexa Smart Home Skill API to create an adapter which adds a “device” named “Christmas Party” that Alexa can manage. (For more on using Amazon Echo with Octoblu see here.) This means I can say “Alexa, turn on Christmas party” and the AWS Lambda script created as a Smart Home Skill adapter will send a HTTPS POST to the “start party” trigger.

A bit of holiday fun, but it does show that Octoblu can be used to integrate and automate just about anything!

Appendix: using the Octoblu WS2811 connector

Ocotblu thing swtupIf you want to try this out yourself, here’s how. Official Octoblu connectors can be setup via an interactive wizard however my connector is incomplete and not published as a fully-fledged connector so needs a bit of manual setup. The follow steps assume the Raspberry Pi has a working node/npm environment.

  1. Copy the connector code into a directory on the Raspberry Pi
  2. Run “npm install rpi-ws281x-native meshblu@1.34.1 tinycolor2 microphone vu-meter” to fetch the dependencies (if you get an error “error: ‘REPLACE_INVALID_UTF8’ is not a member of ‘v8::String’” see here for a workaround)
  3. Log in to Octoblu, navigate to “Things” and “All Things” and find and click on “Generic Device” (in the “Other” section)
  4. On the page that appears click on “Connect Generic Device” and then enter a name for the device (you can leave “type” blank)
  5. Click “Connect Generic Device”
  6. Find the new device in “My Things” and click on it
  7. Copy and record the UUID
  8. Click “Generate Token” and copy and record the displayed token
  9. Click “Save”
  10. In the connector directory on the Pi, create a file named meshblu.json containing the above UUID and token in the following form:


Setting LED mode in OctobluYou should now be able to run the connector from the command line using “sudo node ws2811.js” (“sudo” is needed because the library needs root permissions to access the PWM hardware). With any luck you should now be able to refresh the “My LED” thing page in Octoblu and see it now showing a green “online” indicator. To use the connector in a flow enable “Use incoming message” and send it a message with key “mode” and value being one of the allowed modes such as “vu” or “colorwheel.”

Blog Banners -- FOOTER-2