Intercepting Google Assistant When Casting to Google Chromecast Audio

Hi everybody, this is my first post here, and I searched for what I am looking for but I cannot seem to find it. I am brand new to Home Assistant, although I have been lurking for probably 2 years now. My Raspberry pi should be here in a couple of days and am very excited to get started.

For my first automation, I am wanting to automatically turn on my stereo via smart plug when I cast music to my chromecast audio. Is there a way to intercept the google cast and automatically turn on the smart outlet when casting to that particular chromecast audio? I have tasker installed on my phone if that is needed, but I would rather not have to go that route if possible.

Side question for those of you who use NodeRed, since I am setting up my HA from scratch, should I start setting up my automations using NodeRed from the start, or use the default yaml HA configuration for this? I have experience using python and modelbuilder (in ArcMap if anyone is familiar) so the idea of flows is fairly comfortable with me.

Thanks everybody!

Yes, you will be able to turn on/off an outlet when casting starts on your Chromecast Audio. You’ll need to setup the Chromecast as a media_player in HA and make sure it has constant power supplied to it (ie. not plugged in to a switched usb outlet on your stereo or tv). Then you can setup an automation that watches for a ‘playing’ state on that media_player and triggers the outlet.

I haven’t used NodeRed, so I can’t answer the 2nd question.

Sure, that sounds like a simple Automation, which is a great place to start. Once both the Chromecast and the Outlet are configured as components in HA, your Automation could be triggered whenever the state of the Chromecast is “playing” or “paused” (or alternatively, not “idle” or “off”). Presumably you’d also want to turn the Outlet off when the Chromecast is not playing, and so begins your journey down the rabbit hole. :grinning:

I’m in the process of converting most of my Automations from .yaml to Node-RED. Having to get NR configured in addition to HA can be a relatively big pain (especially over SSL) so you might want to start with .yaml just to get up and running and get your feet wet. I’ve also found that some of the more complex Automations (that require scripting) are easier to do in .yaml, and in some cases, practically impossible to do in NR. That being said, most Automations (including your example) are much easier to create in NR.

eg:
In .yaml you’d be doing something like this:

automation:
  - alias: "Stereo On"
    initial_state: true
    trigger:
    - platform: state
      entity_id: media_player.chromecast_stereo
      to: "playing"
    action:
      - service: switch.turn_on
        entity_id: switch.stereo

…by obtaining the syntax from the HA documentation then referring to the Developer’s tools > States page in your HA instance to locate the component names and states.

In Node-RED you’d be doing something like this:
4672759813373952
…by choosing from drop-down lists…

NR-domain_select
…
NR-service_select
…

But either way, there are some brilliant people in these forums to help you along.

Welcome, and good luck! :smiley:

1 Like

This should work in your case:

- id: Cast_Music_Family
  alias: Family Music
  trigger:
  - platform: state
    entity_id: media_player.family_room_speaker
    to: playing
    from: idle
  - platform: state
    entity_id: media_player.family_room_speaker
    to: playing
    from: 'off'
  action:
  - service: switch.turn_on
    entity_id: switch.vsx_power

In Nodered its easier with an event node for the media player entity.

1 Like

Hey guys, so I have been butting my head against this ever since I initially posted here. For whatever reason, I cannot get this to work.

This is my code. At first I thought that it was the chromecast audio giving me issues, so I changed triggers to see if that fixed it. Unfortunately, it did not.

The automation runs correctly when I call it through the services tab. On my about tab, I am getting several errors, few of which relate to my automation (I think):

  • Error doing job: SSL error errno:1 reason: WRONG_VERSION_NUMBER Traceback (most recent call last): File “uvloop/sslproto.pyx”, line 504, in uvloop.loop.SSLProtocol.data_received File “uvloop/sslproto.pyx”, line 204, in uvloop.loop._SSLPipe.feed_ssldata File “uvloop/sslproto.pyx”, line 171, in uvloop.loop._SSLPipe.feed_ssldata File “/usr/local/lib/python3.7/ssl.py”, line 763, in do_handshake self._sslobj.do_handshake() ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)
  • Error doing job: SSL handshake failed Traceback (most recent call last): File “uvloop/handles/stream.pyx”, line 609, in uvloop.loop.UVStream._on_eof File “uvloop/sslproto.pyx”, line 171, in uvloop.loop._SSLPipe.feed_ssldata File “/usr/local/lib/python3.7/ssl.py”, line 763, in do_handshake self._sslobj.do_handshake() ssl.SSLError: [SSL: VERSION_TOO_LOW] version too low (_ssl.c:1056)
  • Error doing job: SSL error errno:1 reason: HTTP_REQUEST Traceback (most recent call last): File “uvloop/sslproto.pyx”, line 504, in uvloop.loop.SSLProtocol.data_received File “uvloop/sslproto.pyx”, line 204, in uvloop.loop._SSLPipe.feed_ssldata File “uvloop/sslproto.pyx”, line 171, in uvloop.loop._SSLPipe.feed_ssldata File “/usr/local/lib/python3.7/ssl.py”, line 763, in do_handshake self._sslobj.do_handshake() ssl.SSLError: [SSL: HTTP_REQUEST] http request (_ssl.c:1056)
  • Update of light.led_controller is taking over 10 seconds
  • Error doing job: Fatal error on transport TCPTransport (error status in uv_stream_t.read callback) TimeoutError: [Errno 110] Operation timed out
  • Error doing job: SSL error errno:1 reason: KRB5_S_INIT Traceback (most recent call last): File “uvloop/sslproto.pyx”, line 504, in uvloop.loop.SSLProtocol.data_received File “uvloop/sslproto.pyx”, line 204, in uvloop.loop._SSLPipe.feed_ssldata File “uvloop/sslproto.pyx”, line 189, in uvloop.loop._SSLPipe.feed_ssldata File “/usr/local/lib/python3.7/ssl.py”, line 767, in unwrap return self._sslobj.shutdown() ssl.SSLError: [SSL: KRB5_S_INIT] application data after close notify (_ssl.c:2605)

Okay, so I got it working with NodeRed, but I still have no idea why the yaml method isnt working.

On an unrelated note, I am having difficulties enabling my packages and other !include objects in my config yaml. When I uncomment packages I get this error:

Configuration invalid
Component not found: packages

And when I uncomment my zigbee2mqtt.yaml file I get this error

Configuration invalid
Error loading /config/configuration.yaml: Config file not found: /config/zigbee2mqtt.yaml!

picture of my config here.

First, a silly question: in the link you shared above your automations for the chromecast are commented out. (with a #) Is this because you gave up on it? Or, did you accidentally comment them out? They will of course not run if commented out.

Otherwise, my suggestion would be to remove the “from” check on the state. This isn’t necessary for what you’re doing. I have an almost identical automation and only use “to” conditions for my state.

Also, check the formatting on your action. Note that mine is 3 lines (data, entity_id, service) but yours is only 2 (service, entity_id). Besides having the right items in the right order, also pay close attention to the indents when you adjust it.

id: '1536397612175'
  alias: netflix
  trigger:
  - entity_id: media_player.domescast
    platform: state
    to: playing
  action:
  - data:
      entity_id: media_player.marantzamp
    service: media_player.turn_on
  - data:
      entity_id: media_player.sharp_aquos_tv
    service: media_player.turn_on

Thanks for your help! I did comment the code about the chromecast out because I couldn’t get it to work, and thought maybe it was the chromecast that was the problem. So I commented it out, and tried to use the led controller to trigger it instead.

In your node red flow, what would you add to automatically turn it off after 5 minutes of no activity?