Which component to use for simple audio-volume control?

Consider an external audio amplifier (analog audio in, analog audio out) that accepts on/off/volume-control setting via I2C. The ESPHome Custom Output component to operate its volume setting works fine. The ESP is not involved in the audio stream at all. It only “turns the volume knob” and operates the on/off switch of the amplifier.

That Custom Output is used in a ‘monochromatic light’ component.
This presents a ‘light’ entity to HA, so setting its “brightness” changes the amplifier’s volume.
Works great, except …

HA sees it as a light, but it’s not really a light.
(Neither is it an audio player, but it has a volume control like an audio player would.)

Is there an ESPHome component that would present itself to HA as an entity that controls a generic quantity (e.g. volume) control, without having to pretend it’s a light?

A ‘Template Number’ component seems promising, in that HA represents it in the UI with a slider to control its level. But then on/off would have to be a separate [switch] entity.

I think to use it in HA you could use a universal media player Universal Media Player - Home Assistant

Thanks! That’s a promising path.

Downside of this approach: The Universal Media Player does not accept templates for its Attributes.
So I can’t have it draw volume_level from the 'light’s brightness/255.
Easily spec’d as a template, but attributes (for some mysterious reason) can be defined only in terms of entity|attribute, and no math (e.g. /255) can be included.
So, it’s a bust, at least until UMP is redone to allow templating for attributes, or I add an extra entity to the ESPHome device that publishes ‘brightness’ as a 0-1 float. I may try that.

Ok sorry if I led you up a garden path. At the risk of doing so again, there is a mqtt media player in custom components somewhere.

Oh, I think your suggestion was definitely the right path. My beef is about HA’s implementation of UMP. It feels … unfinished.
I thought I must be doing something wrong, and looked again at the docs and searched here and it looks like at least one other person ran into the same wall.
It seems incomplete to not accept templates in all parts of an integration that that appears to be intended to be customizable in all ways.

I did finally make it work.
Instead of trying to map the ESP’s ‘light’ into the UMP, I added and exposed a Number (for volume) and a Switch on the ESP and those work fine as entities that UMP can reference and control. So now it looks like a MP in HA.
Thanks again for pointing me down this path. I had searched in HA’s ‘Media Player’ collection many times for something that might adapt to this use, but had never noticed UMP before.

1 Like

Glad it worked for you. :slight_smile: