I love creating cloud-native applications, this not only translates into my field of work but also my projects at home. Projects in which I can simplify processes and apply my knowledge. This also happened with my most recent project: Coldplay. Where I added music to my elevator. How, and why, I'll tell you in this blog.
In 2019 I bought a house with an elevator in it. It goes from the ground floor to the attic. It is actually inside my house. Not an apartment on the 5th floor with a central elevator. This one opens up in my living room! In this blog I'll tell you what I did with it.
Being the tinkerer that I am, I really wanted to do something with this piece of machinery in my house. However, with 2 little kids, a day job, and enough regular things to do in the house I never got around to it. Until…
(Shoutout to my grafanacon 2018 presentation about this actual washing machine)
In October I was having lunch with my colleague/friend Ruan. We were talking about fun projects around the house and together we came up with the idea of adding music to my elevator. It would be a fun thing to show people when they come to visit. It's also something that could be fun to talk about at a conference at some point in the future.
Then, after visiting KubeCon last year, while waiting for my flight in Detroit, I thought I should pitch this idea to talk about at KubeCon in Amsterdam this year.
I ordered a TF Luna lidar sensor and mounted it at the top of the elevator shaft. It's connected to a Raspberry PI with a small program in Rust to take measurements and send them out via NATS.
With an additional component that writes them out to Prometheus, I can now graph the elevator height:
As you can see here, the elevator moves up from about 0cm height to 544cm height and goes back down. And it takes about 54 seconds for this journey, both up and down. If I graph out the speed:
You see that the speed is pretty consistent 10cm/s. Which is actually really slow, but very useful when moving heavy stuff.
The sensor is not without faults though. As you can see in the graph below, the distance varies quite a bit during the day. This jitter probably is related to the temperature, luckily, the TF Luna also reports a temperature.
If I graph the height vs the temperature we get this graph. So there is some correlation, as you can clearly see at around 23.00 and 03.30, but the slow rise between 23.00 and 03.30 is clearly not related to a change in the temperature of the Luna itself.
(note: the quick change in temperature between 29 -> 28 and 28 -> 27 is probably due to the Luna measuring in rounded values, not due to a sudden drop in the ambient temperature of exactly 1 degree).
After getting the measurements, it was time to add some music, after some sidesteps (more on that at Kubecon) I decided on a "duolith", the rust component does the measurements and a go component takes all the measurements from NATS, pushes them to Prometheus, serves a real-time user interface and does some calculations in order to decide if it needs to play music or a floor announcement.
My colleague Patriek really wanted me to elaborate on the whole elevator music/muzak thing, but this wikipedia page probably covers it better than I ever could.
The logic for playing music/announcements is actually pretty easy:
- check if the elevator just started or stopped moving (otherwise, nothing to do)
- If it just stopped:
- If it is on a floor (+- 5cm): stop music & play floor announcement
- if it is between floors: do nothing (continue playing music)
- If it just stopped:
- If it just started: start playing music
The sounds are loaded into memory when the "monolith" starts and are played instantly whenever they are needed. There is a short delay between the elevator starting and stopping movement because the measurements are sent out at most every 500 ms.
Because I now have metrics, it is time to define some alerts!
- If the elevator is stuck between floors for more than 1 minute
- If the elevator moves faster than 15cm (safety margin) in either direction
- If the system reports any value below 0cm or above 544cm for any duration
- If the elevator is moving at a speed lower than 9cm/s but more than 2cm/s
I don't really worry about the elevator failing, but the implication of the elevator being stuck between floors is that someone is in the elevator and not able to get it to a point where they can exit. And the last one is mainly interesting for detecting if the machinery within the elevator is slowly degrading in performance.
If you're also interested in hearing about all the failures of this project, of which there are certainly plenty, come see me talk about this project at Kubecon 2023: Using CNCF Projects for Adding Music and Announcements to My Home Elevator
P.s. It's called Project Coldplay because I wanted up*lifting* music ;)