DEV Community

Cover image for Interactive Halloween decorations with raspberry pi's ๐ŸŽƒ
Caleb Lemoine
Caleb Lemoine

Posted on • Updated on

Interactive Halloween decorations with raspberry pi's ๐ŸŽƒ

Video Demo

Link to demo video

Background

Last year (2020), I decided to do something fun for my neighborhood due to the dark and shitty times that is COVID. I was convinced that kids wouldn't have a normal Halloween for trick or treating. So I built a thing. The idea was to have outdoor lighting with a mobile friendly web app that folks could use and change the colors of my outdoor Halloween lighting to the color/effect of their choice.

I ended up calling the project/site witchonstephendrive.com since I had this pretty slick witch silhouette curtain in the front bedroom window of my house and my street is Stephen Drive of course.

Anyways, here's what it looks like outside of my house with blue/green colors set.

Image descriptionImage description

Mobile app

I put a sign in my front yard to tell folks where to go to on their phones to do the needful. Here's a preview of what the site looks like.

What all does it do?

Lights

I have 5 philips hue lights in the front that are controlled via the app. There are several colors to choose from individually or you can select a rainbow effect or the "flash" effect which turns all of the lights off then back on a few times for a spooky effect.

Sounds

When a user selects presses a button to change the lights, a spooky sound gets played via a google assistant connected speaker.

How does it work?

Backend

I wrote a Go based REST API with lights/sounds endpoints that my front end interacts with.

Image description

Lights

The /colors/:color endpoint interacts with the hue bridge to set color/brightness state using a 3rd party philips hue sdk.

Sounds

The /sounds/:sound endpoint interacts with the google assistant speaker using home assistant.

Sounds are processed using a configurable in-memory queue to ensure sounds aren't interrupted and play all the way through. It would suck to have kids smashing buttons and you would never get to hear a full mp3 play.

Front end

The front end web app for this site is just a vanilla html/css/js that interacts with the REST API, but here's the cool part. Since Go 1.16 started supporting embedding files into the compiled binary, the front end and backend are both served via a single binary which makes deployment of this application super simple.

Hosting

This app is just hosted on a simple raspberry pi 4 in my TV stand running in a docker container. It's ideal to host this on your local network to auto discover the hue bridge. No cloud or kubernetes needed.

All that was needed was to forward port 80/443 from my router to my raspberry pi's local ip address.

Notable Features

  • Schedules
    • Turning lights on/off at configurable times.
    • Setting individual lights back to default colors at configurable times.
    • Bridge IP address renewal at configurable interval to ensure DHCP doesn't change the address
  • Quiet time
    • Sounds supports configurable start and end hours to not play sounds. Don't want to be a ๐Ÿ† to the neighbors by having sounds blaring at all hours of the night.
  • Monitoring
    • Prometheus metrics built-in to monitor color selection usage frequency.
  • Rate limiting
    • I'm using caddy for my web server due to it's awesome automatic certificate functionality using Let's Encrypt behind the scenes. Caddy supports rate limiting via this plugin so I don't have to worry about folks killing my API.
  • IP Geofencing
  • Terraform module to interact with lights/sounds ...because why not.

What's that cool pumpkin under the tree that watches you in the video?

That's my pumpkin-pi project that I also created using another raspberry pi! It uses 2 motion sensors and a servo motor to detect people walking on the sideway and turns the pumpkin towards them to simulate it "watching" you. Check out the repo to see how to build your own!

Here is a video demo close up

Source code

Here's a link to the project if you'd like to deploy your own next year!

Top comments (0)