Controlling musicassistant from ESPhome

I have an interesting problem. I have a sendspin renderer, which works just fine from MA. It’s running ESHome. This lives on top of the kitchen cupboards, in an inaccessible location. I’d like to have a touch interface I can control it with, but that will have to live on a second device.

I’m trying to configure such a second device, but I’m really struggling with the correct incantations. I’ve got volume control working using some lvgl yaml as follows:

        - button:
            [...]
            on_press:
              then:
                - homeassistant.action:
                    action: media_player.volume_up
                    data:
                      entity_id: media_player.kitchen_audio_kitchen_audio_player

However, this only seems to work for volume control. After some trial and error, I discovered I can start/stop/pause using something like:

        - button:
            [...]
            on_press:
              then:
                - homeassistant.service:
                    service: media_player.media_play
                    data:
                      entity_id: media_player.kitchen_audio_kitchen_audio_player

I don’t understand why I have to use homeassistant.service here, but I can sync volume using homeassistant.action. Sure, it works, but I like to understand why it works (and why alternatives don’t work).

However, this all works. What has completely evaded me is the ability to skip to the next/previous track, and to select a radio station.

For skipping to previous/next, I’ve tried every possible variation on the working examples for volume and play/pause, substituting variously next, media_next_track, and every other related incantation I can find in any documentation, and nothing seems to have any effect. I can bodge this by using a template switch on the renderer device, exposing this to HA, and triggering this via an action on my controller. This works, but is really hacky and I feel like I shouldn’t need to do this. What am I missing?

For selecting a radio station, I’m using the URI from MA, something like:

- button:
[...]
  on_press:
    then:
      - homeassistant.service:
          service: music_assistant.play_media
          data:
            media_content_id: library://radio/10
            entity_id: media_player.kitchen_audio_kitchen_audio_player
            enqueue: play

I’ve tried all the things, including:

  • Using homeassistant.action instead.
  • Emptying the queue first using media_player.clear_playlist first (which was ignored)
  • Using media_id rather than media_content_id.
  • Using alternative URIs (different stations, different providers).
  • Specifying (or not) media_type: radio. Also tried music and track.

In all cases, it’s just completely ignored. I’ve checked the action is being triggered by adding other actions before and after which have observable effect, so it’s not that.

Any suggestions for how I can persuade my ESPHome device to set a radio station playing very welcome - I’ve spent hours on it and I’m at the end of my rope with it.

I’ve at least partially solved this, in case it helps anyone else.

It seems there are two entities that are created by MA for a player. The one I was using was the media player entity that is associated with the esphome player. In my case, this was media_player.kitchen_audio_kitchen_audio.

To select some new media to play, however, this entity just ignores you. Rather, you need the parent entity that is directly part of the MA integration rather than the esphome one associated with the player. In my case, this media player is media_player.kitchen_audio.

Thus the following will allow me to select a radio station:

            on_press:
              then:
                - homeassistant.action:
                    action: music_assistant.play_media
                    data:
                      entity_id: media_player.kitchen_audio
                      media_id: library://radio/10

Still not understanding why skipping to the next/previous track is being ignored, but at least I have a kludge that works for that.