Today we shall be taking a look at a project built and programmed by GitHub user adamaze. It is, as the title of this article might suggest, a simple, physical volume controller for any media entity in Home Assistant. Because this project uses ESPHome, it can be integrated with Home Assistant easily and by doing so, you will be able to use it to control the volume of any media player you have connected to Home Assistant.
I’m always looking for new ESPHome projects to tackle, and I’m assuming because you are reading this article, that you are too. That is why I’m launching a new series of featured ESPHome projects. These aren’t projects I have built and coded, but are instead products of the great Home Assistant and ESPHome community.
What you will need for this ESPHome project
As with many ESPHome projects, a D1 mini board powers this one. In turn, the ESP8266 microchip controls the D1 mini. Attached to it is a rotary encoder with a push button , which will control the volume up and down. Make sure you go for a free-spinning rotary encoder. That way, the controller doesn’t have to be in sync with Home Assistant.
The most expensive part of this build will be the 3D printer. If you don’t own one already, you will have to purchase one. But it’s not like this will be the only project you’ll use it for. A popular 3D printer is the Ender 3 Pro. I suggest you read some reviews before deciding which 3D printer to go with.
Other than that you will need a soldering iron, solder wire, and a few isolated wires. To power and connect to the ESP8266, you will need a Micro-USB cable and optionally a power supply.
How the physical volume controller functions
If you use the code provided by adamaze, this volume controller does much more than just control the volume of a smart speaker. In fact, there are five functions in total:
- Twisting the rotary encoder clockwise will call
- Twisting the rotary encoder counter-clockwise will call
- A single click will call
- A double click will call
- A long-press will call a script to start playing a specific Spotify playlist.
What I like about this project is that it demonstrates perfectly how easy ESPHome projects can be. There are only 105 lines of YAML needed for all of these functions. And you won’t have to set up any automation or script in Home Assistant either!
How to build the physical volume controller
As mentioned, the case of this project is 3D printed. Kindly enough, adamaze has provided the .stl files in his GitHub repository. The rotary encoder has to be soldered to the ESP8266 board using four wires, two for the rotary encoder, one for the button, and one for ground. It can then be attached to the lid of the case. The D1 mini ESP8266 board nicely sits in the bottom portion of the case and is powered using the Micro-USB input.
Adjusting the code
The code provided assumes that you have your Wi-Fi SSID and password stored in the
secrets.yaml file. If this is not the case, or you use different descriptors, you will have to adjust that part of the code.
Next, you’ll want to adjust the speaker this device shall control. The code uses a speaker called media_player.kitchen_speakers but yours might obviously vary. You might also want to change the name of this node and the individual IDs. This code makes use of the
homeassistant.service action. Using it, an ESPHome device can execute Home Assistant commands. What this means for you is that you won’t have to set up any automation or script for the volume control. You can also fully adjust the long-press function to your liking.