Simple automation, giving me issues

Hello, trying to set up a simple automation and I’m getting errors… Can you gurus please find the mistake? Tearing my hair out. It basically should turn on Sonos Kitchen speakers and set them to “Audio Component: Family Room” source once a specific activity happens with the Harmony remote.

  • alias: Turn on Kitchen Speakers
    trigger:
    • platform: state
      entity_id: remote.family_room_harmony
      activity: ‘Family Room TV with Kitchen’
      action:
    • service: media_player.select_source
      data:
      entity_id: media_player.kitchen
      source: “Audio Component: Family Room”

Please post YAML properly so we can read it.

But, at the very least, it looks like you’re using the state trigger incorrectly.

- alias: Turn on Kitchen Speakers
  trigger:
    - platform: state
      entity_id: remote.family_room_harmony
      activity: 'Family Room TV with Kitchen'
  action:
    - service: media_player.select_source
      data:
        entity_id: media_player.kitchen
        source: "Audio Component: Family Room"

Thanks!

The state trigger does not have an activity parameter. I would assume for this it should be to. Is that what the state of remote.family_room_harmony is? I don’t use the remote component. Maybe you should be using an event trigger instead???

changing activity to to: fixed it. Thanks!

1 Like

Hmmm. Actually it didn’t fix it. HA doesn’t seem to detect when harmony switches to that particular activity. Is there a better way to do this?

According to the documentation, the entity’s activity is reported in an attribute called current_activity. Therefore the automation’s trigger should monitor that attribute and not the entity’s state. We can use a Template Trigger for this:

- alias: Turn on Kitchen Speakers
  trigger:
    platform: template
    value_template: "{{ is_state_attr('remote.family_room_harmony', 'current_activity', 'Family Room TV with Kitchen') }}"
  action:
    - service: media_player.select_source
      data:
        entity_id: media_player.kitchen
        source: "Audio Component: Family Room"

Thank you. So that made the trigger work perfectly, but now the issue is the action doesn’t really change the Sonos source. Leaving the way it is in the example, it does nothing. Changing it to Line-in changes to Kitchen line in, which I don’t want. I want the Kitchen Sonos to be set to Family Room Line-in. The Sonos app supports this. I also made the Family Room Line-in as the only Favorite Line-in source.

Any further thoughts?

According to the the documentation for Media Player, the select_source service is platform dependent. I’ve searched the forum for ‘sonos select_source’ and found several examples (confirming you can use select_source with Sonos). Therefore all I can offer is that you ensure the value you’ve supplied for source is correct.

If I’ve understood this post correctly, your media_player.kitchen entity should have an attribute named source_list. Use the values in this attribute for setting source.

I agree. See below. Pardon the silly other sources, I blame my daughters.

“volume_level”: 0.64,
“is_volume_muted”: false,
“media_content_type”: “music”,
“media_artist”: “Line-in”,
“source”: “Line-in”,
“source_list”: [
“.favorites.”,
“'80s Pop”,
“1989”,
“1989”,
“25”,
“80s Smash Hits”,
“Audio Component: Family Room”,
“Bounce Your Boobies (A Patriotic Song)”,
“Can’t Help Falling In Love”,
“Descendants 2 (OriginaTV Movie Soundtrack)”,
“Dream”,
“Earth [Clean]”,
“Earth [Explicit]”,
“Everybody’s Free (To Wear Sunscreen) [Geographic’s Factor 15 Plus Mix]”,
“Mamma Mia! Here We Go Again (Original Motion Picture Soundtrack)”,
“Mamma Mia! The Movie Soundtrack”,
“Moana (Original Motion Picture Soundtrack/Deluxe Edition)”,
“New Rules”,
“One More Light”,
“reputation”,
“The Day Before You Came”,
“The Platinum Collection”,
“ZOMBIES (Original TV Movie Soundtrack)”,
“Line-in”
],
“shuffle”: false,
“sonos_group”: [
“media_player.kitchen”
],
“friendly_name”: “Kitchen”,
“supported_features”: 64063

Sonos recently changed alot of the services and they are placed under ‘sonos.xxxx’. Check the services tab and see if select source was moved to that platform for sonos media players. I doubt it was, but it’s possible.

The sources above are from media_player and match my Sonos.

I just tested, Line-In favorites are not currently supported and actually crash the integration for me.

It should be possible to fix, I will try to do that for version 0.95.

Thank you so much, that would be fantastic.

PR#24565 made it for the 0.95 beta that should be out in a few days.

1 Like