Dynamically selecting playlist to stream on Sonos using Alexa SmartHome skill

Using purely the haaska or NabuCasa smart home skill, can I say something like “Alexa, play [Spotify Playlist] on [Sonos speaker name]” or “Alexa, play [Spotify Playlist] in [Room Name]” (which should play on the Sonos speaker and not Alexa itself)?

I just integrated Alexa into my HA setup using haaska. Before, I had the Sonos skill enabled on Alexa. With my new integration, I removed the Sonos skill thinking that I can replace it completely with the haaska Smart Home skill. After playing around with the new setup, I learned that the Smart Home skill is limited in the ways you can ask Alexa do things. There are two main features I am missing right now: to tell Alexa which song/playlist etc. to play and on which speaker. Is this truly a limitation or am I missing a step in my configuration (see below)?

My workaround so far has been to use scenes (scripts), but that means I have to hard code every combination I want to trigger and calling these scenes are awkward (“turn on…” rather than “play…”).

Here is the configuration I am currently using:

configuration.yaml (note that I set up the Sonos devices as SPEAKER, not TV - correct?)

sonos:
  media_player:
    hosts: 
      - 192.168.1.xx
      - 192.168.1.yy

alexa:
  smart_home:
    filter:
      include_entities:
        - group.speakers
        - group.all_lights
        - script.alexa_morning_radio
        - script.alexa_kitchen_radio
        - script.alexa_workout
        - script.watch_atv
        - script.watch_tv
        - script.turnoff_tv
      include_domains:
        - light
        - media_player
    entity_config:
      light.schlafzimmer:
        name: Schlafzimmerlicht
        description: all bedroom lights
      light.buro:
        name: Bürolicht
        description: Alle Lichter im Büro
      media_player.schlafzimmer_sonos:
        name: Sonos Schlafzimmer
        description: Sonos speaker in bedroom
        display_categories: SPEAKER
      media_player.bad_sonos:
        name: Sonos Bad
        description: Sonos speaker in bathroom
        display_categories: SPEAKER
      media_player.buro_sonos:
        name: Sonos Büro
        description: Sonos speaker in office
        display_categories: SPEAKER
      media_player.wohnzimmer_sonos:
        name: Sonos Wohnzimmer
        description: Sonos speaker in livingroom
        display_categories: SPEAKER

scripts.yaml (I consider these workarounds since I have to create one scene for each playlist I want to play through Alexa)

alexa_morning_radio:
  alias: "Morgenradio"
  sequence:
  - service: media_player.select_source
    data:
      entity_id: media_player.schlafzimmer_sonos
      source: 'SRF 4 News'
  - service: media_player.volume_set
    data:
      entity_id: media_player.schlafzimmer_sonos
      volume_level: 0.1
      
alexa_kitchen_radio:
  alias: "Küchenradio"
  sequence:
  - service: media_player.select_source
    data:
      entity_id: media_player.wohnzimmer_sonos
      source: 'SRF 4 News'
  - service: media_player.volume_set
    data:
      entity_id: media_player.wohnzimmer_sonos
      volume_level: 0.3

I have not set up any groups inside Alexa.

Thanks for any suggestions that might improve my current setup.

Hey there @davosian! I’m one of the maintainers of haaska. One important thing to note is that haaska/the NabuCasa smarthome skill share the same functions - the only difference is how they’re setup. One is easier, the other (haaska) is harder.

That being said, there are only certain things that Smart Home Skills can do with the Alexa Voice Service, and, well, as you’ve found, it’s pretty limited. It’s not that we don’t want to do more, it’s that there are only certain functions even allowed for smart home skills.

I don’t have Sonos equipment, but from what I read, I would recommend you re-enable the Sonos skill, as that will give you the control you’re looking for.


Advanced details…

If you’re a little more interested in what the Smart Home Skill can do, you can see here: Alexa Smart Home | Understand the Smart Home Skill API

Roughly, these things are supported:

In the case of a Speaker, it is classified as an “Entertainment device”. Devices in that class support the following:

Operation Capability Interface
Turn things on and off Alexa.PowerController
Change the channel on a device Alexa.ChannelController
Change the equalizer settings such as adjusting a band, or changing the equalizer mode. Alexa-EqualizerController
Change the input of a playback device Alexa.InputController
Control the playback of device; fast forward, rewind and pause Alexa.PlaybackController
Change the volume in incremental steps Alexa.StepSpeaker
Change the volume to anywhere on a continuous range Alexa.Speaker
Indicate an error has occurred Alexa.ErrorResponse

Note that while you can change the input of a playback device, that’s not the same as the source. It would be similar to changing from a built in input (like “AV1”), to “Aux In”, or on a TV, going from “HDMI 1” to “HDMI 2”, and so on. The reason you can do this with your script workaround, is because to Alexa, that’s just a switch that it can turn on/off like a light. It’s Home Assistant, with the smarter, more capable integration with the Sonos API that can then actually send out the command to play a specific source.

The Sonos skill, being written to handle sources and look ups (like a proper integration), would have this capability, which is why they created it :slight_smile:

Hey @anthonylavado,
thanks a lot for all the insight you shared with me. Highly appreciated!

Unfortunately, you concisely confirmed my initial doubts around the limited feature set provided by the smarthome skill. While it clearly brings some degree of freedom to my SmartHome setup, it fails to deliver on my goal of having a solution that remains 100% local with very few exceptions (Alexa being one of them). Enabling vendor skills (as opposed to your opensource haaska skill) goes against my idealistic goal.

The Alexa API is developing at a high pace, so getting more features for the smart home skill is definitively possible (and coming soon in some ways: New Alexa Smart Home Flexible Building Block APIs : Alexa Blogs), but even better would be an opensource voice solution that does not depend on a single vendor. I did see some of those ideas materializing at crowdfunding platforms, but none of them seem to have achieved a high enough level of polish yet, so I guess I will go with your suggestion of re-enabling select skills (besides Sonos, I am having the same challenges with Harmony). I will note though, that controlling lights is working quite well using a smarthome skill, making skills like Hue unnecessary.

Do I understand you correctly, that switching my Sonos speakers from type SPEAKER to type TV will not give me any benefit? I am thinking that me using the German version of Alexa, I might not yet have full access to all available skill options in the first place:

Smart home skills for entertainment devices

When you create a skill for entertainment devices, you need to make sure you receive messages for the entertainment device control in the Smart Home Skill API. To do this, select v3 , and one of the English language options in the developer console when you create your skill.
Understand Smart Home Entertainment Skills | Alexa Skills Kit

I will keep experimenting with a mix of haaska and vendor skills to find the golden grail. Thanks again!

1 Like

@davosian - Thank you for writing back! You are correct, switching the Sonos from type “Speaker” to type “TV” will have no benefit.

I should add, as a note for you, it is possible to have local voice control to a limited extent - you could combine a Raspberry Pi with something like the respeaker, but as you mentioned, it’s not that easy to set up (plus you must handle all the different ways that you could say a command).

For IR, if you haven’t looked at it, perhaps a Broadlink unit might work for you too.

It is a balancing act - trying to keep local control, but getting the benefit of the “cloud” :smile:

For IR, I am actually using Logitech Harmony and besides the requirement on a cloud setup it is working well for me. Enabling the Harmony skill gives me a lot of power over my entertainment devices.

As far as voice control goes, I am hoping for Mozilla’s voice ui effort to succeed.