Simple speaker control that looks like a media_player/speaker to HA

Looking for ideas on the best way to build the ESPHome software to make an ESP-controlled amplifier look like a media_player to HA (with just 3 controls: on/off/volume).
(note: This is NOT about ESP handling the media stream, just controlling the amp the way it can control shutters, lamps, garage doors, etc. The ESP will control the amp via an I2C bus).

I’ve built custom components before, so would not be uncomfortable with that here, but am unclear how to cause it to present itself to HA as a “media_player / Speakers” (there’s even a device_class for that).

The closest existing component is “DFPlayer” which is an actual media player daughter card.
I suppose I could customise that and strip out every function except on/off/volume.
Or, perhaps make it as a custom dimmable monochromatic light. (i.e. it would present almost the same controls: on/off/brightness) but I’d prefer to do this in a way that HA perceives as a Media Player, not a light.

Could it be as simple as a lambda in the Monochromatic Light component that changes the reported device_class?

Wifi is probably not a good solution for this purpose.
It will use a lot of power so it needs to wired, or wireless and needs to wake up before you can use it.

I would suggest get a zigbee dimmer and just create automations based on the movements/clicks.
Like the IKEA Symfonisk volume control.

The amp will have its own power supply, speakers, and a line-level audio feed.
All I’m looking to do is have the ESP control the amp.

The amp is a class-D amp with an I2C-controlled volume. A piece of cake for an ESP to vary the volume on it. Just send it the proper I2C commands. That part is easy for me.

I just want to know how to make the ESP appear as the proper kind of device to HomeAssistant, so HA ‘sees’ it as being some kind of uber-simplistic media_player.

1 Like

Ok. Misunderstood you then. I thought it was to control a different amplifier.

Please have a look at media_player.template: https://github.com/Sennevds/media_player.template

2 Likes

Thanks. That seems like it would be handy for defining a new player in Home Assistant.
I was really hoping this could all be done in ESPHome, though.
e.g. by having it report itself to HA as an object HA already understands, similar to the way nn ESPHome monochromatic light component does.
There’s just no ESPHome component for media_player. (maybe there should be?)

I’m afraid ESPHome doesn’t have this functionality so far.
btw: What is the class-D amp with an I2C-controlled volume that you are using?

The ESPHome component DFPlayer does seem to already include the feature I’m looking for: Making itself visible to HA as a media_player.
The device I’ll be using is: Stereo 20W Class D Audio Amplifier - MAX9744 : ID 1752 : $19.95 : Adafruit Industries, Unique & fun DIY electronics and kits
It will drive some speakers on the patio, and we’d like to be able to control their on/off/volume using HA (and, e.g. Google Assistant via HA)

I may just use the class(es) underlying the existing DFPlayer component in a Custom Component of my own.
The only part(s) I need are the ones that tell HA that it’s a media player or speaker, which is a device_class HA already understands.

I don’t think that dfplayer presents itself to HA as a media player.

Ah, you are correct. I inferred that it would from its description. But it doesn’t.
I guess I shall trod some fresh ground here, and have to somehow figure out how to make it do so.
(or, I’ll just give up and pretend it’s a monochromatic dimmable light) :wink:

I think exposing the volume and then using media player template is a good solution.

1 Like

Also I don’t know if you are interested, but you can run squeezelite on an esp32. Complete media player :slight_smile:

Thanks, but no, I don’t want the ESP to be handling the media at all. It should treat the amplifier more like a cover or a servo. Just a thing to be reduced or intensified opened/closed, widened/narrowed, etc.
I just want the ESP to expose the ability to effect on/off/volume controls to HA. The media are generated elsewhere and supplied to the amplifier via analog copper signals as line level (0-1v) analog signals.

1 Like

Understood, it was just a random idea :slight_smile:

1 Like

The tack I’m thinking I’ll take for now is:

  1. define it all as a monochromatic light, and use custom outputs to have “dimming” control the volume, and on/off do the obvious things. That way, it’ll at least be physically tested, and hopefully usable. Only the UI semantics will be weird. (“Hey Google, dim the backyard speakers”)

  2. In parallel with those controls, I’ll experiment with added code that exposes the same controls in ways that will [attempt to] emulate a media_player (like an imaginary ESP-based Chromecast) so that ‘Volume’ is portrayed as such in HA.

That way, I’ll be able to use it, and figure out how to make it semantically prettier at the same time.

Interesting topic. :slight_smile: :+1:

Have you asked in the ESPHome Github repository? There may be more technical advanced (in ESPHome) people, that may have an idea. :slight_smile:

In any case, let us know what you come up with. I find the idea tempting, to control a kind of non-smart device. :slight_smile:

I have not, mainly due to believing that it wouldn’t be the right place to ask (this not being a bug-like thing). But I’ll go check it out. Perhaps I’ll figure out how to simplify the question for brevity first.
Thanks for the idea.

Perhaps frame it as a feature request?

1 Like

I think it at least qualifies as a feature request, doesn’t it? :slight_smile: I mean we have all kinds of devices in ESPHome, from sensors to climate controls to a sous-vide stick for cooking. Taking a “media_player” into this portfolio would make sense, IMHO. :slight_smile:

You’d get my vote for sure! :slight_smile: :+1:

EDIT: once again, to late to the feature request party :rofl: :rofl: :rofl:

1 Like

I think a number component? Number Component — ESPHome

1 Like