geekofweek / homeassistant

Example Home Assistant Configs
1.37k stars 156 forks source link

Question #16

Closed billraff closed 4 years ago

billraff commented 4 years ago

I've been searching github looking for someone that has integrated a Sonos Port with a Yamaha receiver. I see you have both. I am new to all this and am looking for direction. Let me paste my question as I posted to reddit today:

I am hoping to get some direction on a project I've taken up recently. I purchased a Sonos Port (https://www.home-assistant.io/integrations/sonos/) to use with my Yamaha AVR (https://www.home-assistant.io/integrations/yamaha). When I purchased the Port a couple of weeks ago I had not heard of HA. I thought I could use the 12v Trigger on the Port to turn on my Yamaha and it could then stream music like my other Sonos speakers. Turns out the 12v Trigger on the Yamaha is a trigger out - not in. Everything works manually but I couldn't help but think there should be a way to 'automate' this process. Research lead me to Home Assistant. So for the last three weeks or so I have read up and played with HA. I have it running in a docker on a RPi I had laying around. I was able to get my Yamaha and my Sonos added to the system but that's as far as I am. I have played around with automations and triggers but not found a way to get what I want. So what is it I want? I want the Yamaha to turn on and go to a scene I have created on the Yamaha for the Port to stream to when the Sonos Port starts playing. Using the Developer Tools I can select the service: yamaha.select_scene entity - media_player.yamaha_receiver with the service data - entity_id: media_player.yamaha_receiver scene: 'Sonos' And that will turn on the receiver and set the scene to the one I created on the AVR (cleverly named 'Sonos'). So seems like this is doable but I am stuck on where I go from here. Any thoughts or pointers would be appreciated. I've looked through a lot of HA configurations that are posted on github hoping someone already did this but so far no matches. Thanks for any help.

I'm not an engineer just a retired worker. This would really be all I need HA for. If you could provide any pointers I would appreciate it.

billraff commented 4 years ago

Sorry about the formatting. Something about the copy and paste.

geekofweek commented 4 years ago

Sounds like you need an automation with a trigger. You can trigger on anything you want but easiest might be to setup an input_select you select options from a drop down in the UI. input_boolean would work as well if you just want to toggle it on and off

Here is an example using an input_select to trigger an automation:

Example:

- alias: Yamaha Sonos

  trigger:
    - platform: state
      entity_id: input_select.yamaha_inputs
      to: 'Sonos'

  action:
    - service: yamaha.select_scene
      entity_id: media_player.yamaha_receiver
      scene: 'Sonos'

Not 100% that would work since I haven't tested using the Yamaha scene select. Lot of different ways you can go about doing it but the crux of it is to have something trigger an automation that selects the scene. You can do this with anything, input_boolean, input_select, Sonos state say if Sonos starts playing something turn it on. You can also automate grouping the Sonos together if needed. Pretty much anyway you want to go about doing it. This is less around how Yamaha and Sonos integrates more around writing an automation to fit the need. I utilize the Logitech Harmony Hub that I use to setup the inputs on the Yamaha so I don't use a lot of it natively.

geekofweek commented 4 years ago

Further context is that an input_boolean is just a binary on and off toggle and an input_select is a multi-select option that you can populate with whatever you want. An input_boolean would be the simplest and you could also expose that to say an Amazon Echo and when you turn that on it runs the automation turning the Sonos on. Lots of ways to solve this but what you want to do is absolutely doable.

billraff commented 4 years ago

Thanks for the insight. I feel I may have swam out a little too far and over my head. I was thinking I could add a file in the automations.yaml that contained the lines - trigger:

Doesn't seem to do anything though and I guess the lack of action is not logged anywhere.

geekofweek commented 4 years ago

I think you are on the right track.

I would change your action to not go from paused but just make it to: 'playing' it can also have a state of 'idle'

  trigger:
    - platform: state
      entity_id: media_player.port
      to: 'playing'

Looking into it further yamaha.select_scene is the wrong service to call as it is a Source and not a Scene.

    - service: media_player.select_source
      entity_id: media_player.yamaha_receiver
      data:
        source: 'Sonos'

I've never used scenes with my Receiver but just setting the Input Source should get what you want, if your scene is setup for Sonos you can call that like this:

    - service: yamaha.select_scene
      entity_id: media_player.yamaha_receiver
      data:
        source: 'Sonos'

I tested and published my config on GitHub, should do what you are after. I'll probably change it to use the Logitech Harmony input_select because it reconfigures the entire setup with the tv, etc. You can ignore my condition if you like, I always check that someone is home before firing an automation.

        ##########################################################
        ## Turn on Surround Sound Receiver When Sonos Port Playing
        ##########################################################

- alias: Media - Turn on Surround Sound Receiver When Sonos Port Playing
  id: 'media_turn_on_surround_sound_receiver_when_sonos_port_playing'

  trigger:
    - platform: state
      entity_id: media_player.sonos_surround_sound
      to: 'playing'

  condition:
    - condition: state
      entity_id: group.household
      state: 'home'

  action:
    - service: media_player.turn_on
      entity_id: media_player.surround_sound_receiver
    - delay: '00:00:05'
    - service: media_player.select_source
      entity_id: media_player.surround_sound_receiver
      data:
        source: 'Sonos'
billraff commented 4 years ago

Thanks again for the information. I tried adding the following lines directly to the configuration.yaml file. I don't anticipate mine growing past this use case so figured keep it simple.

trigger:

It saves properly and shows no syntax errors. However, when I run the configuration checker it reports -

Invalid configuration

Component error: trigger - Integration 'trigger' not found. Component error: action - Integration 'action' not found.

If I still drank now would be the time I'd pour a tall one ;)

geekofweek commented 4 years ago

Formatting is very important in YAML, including white space and indention. VERY Important. It might be better to use the GUI based automation builder until you get that part down. VS Code will show proper syntax if you use that. If you have a syntax error it would keep all automations from loading.

I also think the new default is that automations live in automations.yaml and not the configurations.yaml file. But I'm pretty confident you could build this with the GUI as it's pretty simple. All of the spacing I have in the above example will work if it is formatted exactly like that. Make sure you update the entity names to whatever yours are.

geekofweek commented 4 years ago

Automation Editor

geekofweek commented 4 years ago

Example:

automation-1 automation-2

This will create, or append, to automations.yaml the following. Note that the spacing there is very important, but all of that can be done via the GUI without even bothering with the YAML.

- id: '1604604076651'
  alias: Test - Turn on Surround Sound Receiver When Sonos Port Playing
  description: ''
  trigger:
  - platform: state
    entity_id: media_player.sonos_surround_sound
    to: playing
  condition: []
  action:
  - service: media_player.turn_on
    data: {}
    entity_id: media_player.surround_sound_receiver
  - service: media_player.select_source
    data:
      source: Sonos
    entity_id: media_player.surround_sound_receiver
  mode: single
billraff commented 4 years ago

This was the kind of hand holding I was needing. It is alive! I can’t thank you enough! I wish you all the best!

-bill

On Nov 5, 2020, at 1:24 PM, geekofweek notifications@github.com wrote:

Example:

https://user-images.githubusercontent.com/18582973/98286666-f22d1500-1f69-11eb-8487-42b95efb45de.png https://user-images.githubusercontent.com/18582973/98286682-f78a5f80-1f69-11eb-8b4a-72d6692e862a.png This will create, or append, to automations.yaml the following. Note that the spacing there is very important, but all of that can be done via the GUI without even bothering with the YAML.

grussell73 commented 3 years ago

I solved this by building a device that uses the Sonos Port 12v trigger to send IR codes to turn on or off the Amp. https://hackaday.io/project/176520-esp32-sonos-port-12v-trigger-control-amp