Automating Chromecast audio and AVR input select - home assistant for the win

For me the killer use for google home is playing audio to chromecast audio. In the past I’ve wired audio to rooms with volume controls, set up harmony hub/remotes, and used chromecast to make what were for ME easy to use options for audio. “Click this button on the harmony remote to pick the right zone, then get your phone and chromecast to it” - seemed easy. But frankly, not easy enough for the family.

The google home devices really made it so much easier. Except for a few annoying things - you typically have to know the names of specific outputs, and if using an AVR with a chromecast attached - UGH people are listening to audio on google home when there’s a nice audio setup in the same room. What is wrong with people, don’t they CARE?

No, my wife and kid don’t care about that. But let’s face it, I watch movies and get weird about sitting in the sweet spot. When I was single, a marker of a serious relationship was fixing their TV video setup (omg, you have it in stretch mode - or omg, you are using RCA cables instead of s-video … I’m old). So, dammit that is not good enough for me.

With google home’s new (to me) “preferred speaker” option, harmony hub, and home assistant I’ve finally made my life complete. Alright, maybe that’s a stretch.

It’s simple, but here’s a software solution for things that otherwise would require some annoying hardware work (voltage triggered inputs?)

First, I set the google home preferred speaker to my chromecast plugged into my AVR. My google home is named living_room_home. My harmony hub has a cleverly named “Music” activity that sets the AVR input to the chromecast.

This automation detects my chromecast audio (called living_room_speaker) changing to the play state. If the harmony hub is already in the music activity, well, ok don’t do anything. If the harmony hub remote state is PowerOff (meaning no one’s using the TV/AVR because god forbid you use the original remote and not the harmony, are you an ANIMAL?), then run a script living_room_music that starts the Music activity. Otherwise, warn people what is up.

The automation:

- id: living_room_cast
  alias: Living Room Cast
  trigger:
    platform: state
    entity_id: media_player.living_room_speaker
    to: 'playing'
  condition:
    condition: template
    value_template: '{{ states.remote.harmony_hub.attributes.current_activity != "Music" }}'
  action:
    - service: script.turn_on
      data_template:
        entity_id: >-
          {% if states.remote.harmony_hub.attributes.current_activity == "PowerOff" %}
          script.living_room_music
          {% else %}
          script.warn_living_room_music
          {% endif %}

Script ‘living_room_music’

living_room_music:
  alias: Living Room Music
  sequence:
    - service: remote.turn_on
      entity_id: remote.harmony_hub
      data:
        activity: 'Music'

Warning script. What’s the point of this eh? Well, I could just always force the input over the chromecast, and if you live alone, go for it! But if not, it’s nice to be nice. Plus the robot google tts english to english translate voice is creepy and entertaining.

warn_living_room_music:
  alias: Warn Living Room Music
  sequence:
    - service: tts.google_say
      entity_id: media_player.living_room_home
      data:
        message: 'Press the music button on remote to play music.'

Finally, I just added this last automation but have not tested it. If I tell the google home to play music but then never actually listen to it I want to stop the stream. If we’re in that state for 7 minutes, turn the stupid thing off.

- id: unused_living_room_cast
  alias: Unused living room cast
  trigger:
    platform: state
    entity_id: media_player.living_room_speaker
    to: 'playing'
    for:
      minutes: 7
  condition:
    condition: template
    value_template: '{{ states.remote.harmony_hub.attributes.current_activity != "Music" }}'
  action:
    - service: media_player.turn_off
      entity_id: media_player.living_room_speaker

Is this a life changing event? No. But very satisfying.

I do the same thing but removed the Logitech Harmony out of the setup because no one in my house uses the Harmony remote. Luckily, my Onkyo receiver works with the HA/Onkyo component pretty well and hasn’t failed me so far as a substitute.

If you have a HDMI CEC-enabled TV and receiver that works well (some don’t), then you can get rid of the Logitech Harmony entirely, or keep it as a backup. It’s awesome using the Chromecast 4k, telling Google Home to turn off the Chromecast and having it turn off the TV and receiver with it.

i like your config.

Dont know if you could help me out though? I have similar setup but no harmony remotes.

What i want to achieve is to have a few single buttons on my HADashboard that do the following.

Music Living Room
turn on - onkyo amp zone 1 to power on
turn on - onkyo zone 1 to CD/SACD input
turn on - onkyo zone 1 to set volume level

Music Zone 3 (Other Room)
turn on - onkyo amp zone 3 to power on
turn on - onkyo zone 3 to CD/SACD input
turn on - broadlink IR command - Turn on Sony Reciever
set - broadlink IR command - Set volume Level

Also need to include Turn Off commands for the power options.

Dont know how to do this using one button under HA, is it a script an automation or something else…? I realise i’ll need the proper entities and IR commands but would like to know the basics first if you could help?

Thakns

Good Work

just did something similar… My setup supports HDMI CEC though, so it was much easier to set it up even without a logitech harmony… But some things, like my xbox, need IR to be turned on. So I have a tiny broadlink that controls that.

I have template switches that watch the states of the HDMI devices, or the xbox component to see wheather the xbox is turned on or off. So even if I use the normal remote HA will know what is turned on or off. This is really cool, because when my girlfriend or any other random person turns on any device, e.g. the receiver, everything else will turn on and set to the right input (although the receiver does not support HDMI CEC).

By the way, naming the google devices according to the rooms they are located helps a lot. Saying “play xyz in the livingroom” results in playing xyz on my device “livingroom” which is a no brainer to work with for everyone involved :wink:

Unless I don’t understand - I think you just want to make an input_boolean for each button you’d like in the frontend. Then set your automations to trigger on the input_boolean.

Regarding HDMI CEC - it indeed is cool (unless the TV stinks at it, which happens as you say) - but I’m using a chromecast audio. So HDMI-CEC isn’t helpful there, no HDMI.

But similarly - it’s awesome to tell google home to turn off something and have homeassistant to use harmony (or CEC or whatever) to orchesrate it all and shut a bunch of stuff off.