Building a physical volume controller for Home Assistant using ESPHome

Disclosure: This post contains affiliate links. If you click through and make a purchase, I’ll earn a commission, at no additional cost to you. Read my full disclosure here.
Advertisement

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.

Advertisement
A physical volume controller for Home Assistant using ESPHome

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.

Advertisement

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.

Advertisement

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 media_player.volume_up
  • Twisting the rotary encoder counter-clockwise will call media_player.volume_down
  • A single click will call media_player.media_play_pause
  • A double click will call media_player.media_next_track
  • 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!

Advertisement

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.

Advertisement

Integrate your TP-Link router with Home Assistant

The best temperature and humidity sensor for ESPHome

Advertisement
Liam Alexander Colman, the author and maintainer of Home Assistant Guides.

About Liam Alexander Colman

Liam Alexander Colman has been using Home Assistant for various projects for quite some time. What started of with a Raspberry Pi quickly became three Raspberry Pis and eventually a full-blown server. I now use Unraid as my operating system, and Home Assistant happily runs in a Docker container. My personal setup includes many Zigbee devices as well as integrations with existing products such as my Android TV box. Read on to find out more on how I got started with Home Assistant.

Leave a comment

Advertisement
1