Controlling New Chromecast with Google TV

Ok thanks, but did you use the built in ADB in home assistant or using a dedicated ADB server?

I had forgotten to enable USB debugging :slight_smile:

1 Like

Did somebody try it with the Android TV integration?

If you are talking about this https://www.home-assistant.io/integrations/androidtv/

  • platform: androidtv

Then it uses adb behind the scenes

yeah that’s what I was talking about and I noticed that right after I posted here… So if I want to start using it, all I need is to setup that integration, or I need a separated adb server as well as the device connected to the ethernet cable ?

Can this be done over network? The shield has an option for this in the settings, but the new chromecast does not.

I didn’t find much written on how to integrate the Chromecast with Google TV (released late 2020 with a remote) into HA. I’ll give a summary on how I did it via the Android TV integration. I’m no expert, but just trying to help any other users out who are left wondering if it’s possible.

To integrate via Android TV integration:

  • Ensure the Chromecast has a static IP on your local network (my tip to you)
  • Enable USB debugging, described in google’s development pages, here. Unlike some of my other AndroidTV devices, you can do this via wifi, i.e. you don’t need to use a USB cord at all. It is much easier this way especially since you need to see the screen of the Chromecast to click on a pop up to enable the ADB server to access the Chromecast.
  • Back in HA, Install the ADB (Android Debugging Bridge) add-on. I believe there is a docker container version too. The HA Android TV docs have good details on this. Follow the docs for configuring it, including putting in the IP address of your device.
  • Below is a copy of my configuration.yaml entry for the media_player.
  • I needed to restart for the changes to take effect.
  • On the Chromecast, there will be a pop-up that a device is trying to access the Chromecast via ADB. Tick the “Always allow from this computer” and “ok”.
  • Check HA logs if you are having issues.
# my configuration.yaml entry:
media_player:
   - platform: androidtv 
     host: 192.xxx.xx.xx  # IP of the Chromecast, insert yours here
     port: 5555 # defaults to 5555
     name: "Chromecast with Google TV"
     adb_server_ip: 127.0.0.1 # IP for the HA add on 
     adb_server_port: 5037 # port on the ADB server add on`

Result

The state for “playing” works as it should now (was “unknown” when watching netflix before).

12 Likes

Thank you for your description.
I got it working thnks to the description.

1 Like

Thanks for the write up.

Have you noticed any stuttering? I just set it up and now it seems watching YouTube is stuttering. Every 30 seconds or so the video freezes for a half second then it’s fine. No audio issues. Could just be a coincidence though.

Hi @barroomhero,
I haven’t noticed any stuttering and I’ve watched a dozen or so YouTube videos since I’ve bought it. Definitely no problems with Netflix or Plex, which we watch more often. Not sure what your problem is there.

Must have been a coincidence because, I haven’t seen any since. Thanks for the verification though.

Have you tried calling media_player.select_source with your various sources? I have found that a few “just work” and the rest work “sometimes”. If I use “source: com.netflix.ninja” – it always loads Netflix. But if I use “source: com.amazon.amazonvideo.livingroom”, it almost never loads it.

Any thoughts?

I hope someone can help me with this.
I am trying to send fast ADB commands (as outlined here).
I can send commands successfully when formatted as follows:

#This works flawlessly, albeit slowly.
alias: Send Up command
sequence:
  - service: androidtv.adb_command
    data:
      command: UP
    entity_id: media_player.livingroom_google_tv
mode: single

However, when I try to send the command captured with androidtv.learn_sendevent, I don’t get a response:

# I wish this worked, but it doesn't.
alias: Send Up command
sequence:
  - service: androidtv.adb_command
    data:
      command: 'sendevent /dev/input/event9 4 4 786498 && sendevent /dev/input/event9 1 103 1 && sendevent /dev/input/event9 0 0 0 && sendevent /dev/input/event9 4 4 786498 && sendevent /dev/input/event9 1 103 0 && sendevent /dev/input/event9 0 0 0'
    entity_id: media_player.livingroom_google_tv
mode: single

Has anyone gotten the fast commands to work? I have searched this forum and everywhere on google and I have yet to find a single instance of someone using this. I have both an Nvidia Shield TV and a Chromecast with GoogleTV. Their respectively captured fast commands do not work for either.

I have tried installing the “Android Debug Bridge” Hass addon, thinking that was the issue (As the Chromecast is quite new) but I haven’t seen a difference.

Here is my config:
    # NVIDIA SHIELD Integration through Android TV
  - platform: androidtv
    name: Basement NVIDIA Shield
    host: 192.168.1.IP
    apps:
      com.liskovsoft.videomanager.beta: Youtube
      com.spotify.tv.android: Spotify
      com.plexapp.android: Plex
      com.nvidia.tegrazone3: GeForce
      org.dolphinemu.dolphinemu: Dolphin Emulator
      com.google.android.tvlauncher: Home Menu
    state_detection_rules:
      'com.liskovsoft.videomanager.beta': 
        - 'playing':
            'wake_lock_size': 2
        - 'paused':
            'wake_lock_size': 0
      'com.plexapp.android':
        - 'playing':
            'media_session_state': 3
#            'wake_lock_size': 3
        - 'paused':
            'media_session_state': 2
#            'wake_lock_size': 0
        - 'idle'
      'com.nvidia.tegrazone3':
        - 'playing':
            'wake_lock_size': 2
        - 'paused':
            'wake_lock_size': 0 #Even if playing but out of the screen.

#Tried using the ADB server for the googleTV instead of the python. No difference.
- platform: androidtv
    name: Livingroom Google TV
    host: 192.168.1.IP
    adb_server_ip: 127.0.0.1 # IP for the HA add on 
    adb_server_port: 5037 # port on the ADB server add on`
    apps:
      com.liskovsoft.smarttubetv.beta: Youtube
      com.plexapp.android: Plex
      com.spotify.tv.android: Spotify
    state_detection_rules:
      'com.liskovsoft.smarttubetv.beta': 
        - 'playing':
            'wake_lock_size': 0
        - 'paused':
            'wake_lock_size': 2
      'com.plexapp.android':
        - 'playing':
            'media_session_state': 3
        - 'paused':
            'media_session_state': 2
        - 'idle'

and…

Here are my learned events:
    # GoogleTV:
    # Down: sendevent /dev/input/event9 4 4 786499 && sendevent /dev/input/event9 1 108 1 && sendevent /dev/input/event9 0 0 0 && sendevent /dev/input/event9 4 4 786499 && sendevent /dev/input/event9 1 108 0 && sendevent /dev/input/event9 0 0 0
    # Up: sendevent /dev/input/event9 4 4 786498 && sendevent /dev/input/event9 1 103 1 && sendevent /dev/input/event9 0 0 0 && sendevent /dev/input/event9 4 4 786498 && sendevent /dev/input/event9 1 103 0 && sendevent /dev/input/event9 0 0 0
    # Left: sendevent /dev/input/event9 4 4 786500 && sendevent /dev/input/event9 1 105 1 && sendevent /dev/input/event9 0 0 0 && sendevent /dev/input/event9 4 4 786500 && sendevent /dev/input/event9 1 105 0 && sendevent /dev/input/event9 0 0 0
    # Right: sendevent /dev/input/event9 4 4 786501 && sendevent /dev/input/event9 1 106 1 && sendevent /dev/input/event9 0 0 0 && sendevent /dev/input/event9 4 4 786501 && sendevent /dev/input/event9 1 106 0 && sendevent /dev/input/event9 0 0 0
    # Select: sendevent /dev/input/event9 4 4 786497 && sendevent /dev/input/event9 1 353 1 && sendevent /dev/input/event9 0 0 0 && sendevent /dev/input/event9 4 4 786497 && sendevent /dev/input/event9 1 353 0 && sendevent /dev/input/event9 0 0 0
    # Back: sendevent /dev/input/event9 4 4 786980 && sendevent /dev/input/event9 1 158 1 && sendevent /dev/input/event9 0 0 0 && sendevent /dev/input/event9 4 4 786980 && sendevent /dev/input/event9 1 158 0 && sendevent /dev/input/event9 0 0 0
    # Circle: sendevent /dev/input/event9 4 4 786979 && sendevent /dev/input/event9 1 172 1 && sendevent /dev/input/event9 0 0 0 && sendevent /dev/input/event9 4 4 786979 && sendevent /dev/input/event9 1 172 0 && sendevent /dev/input/event9 0 0 0
    # SwitchApp: sendevent /dev/input/event9 4 4 786979 && sendevent /dev/input/event9 1 172 1 && sendevent /dev/input/event9 0 0 0 && sendevent /dev/input/event9 4 4 786979 && sendevent /dev/input/event9 1 172 0 && sendevent /dev/input/event9 0 0 0 && sendevent /dev/input/event9 4 4 786979 && sendevent /dev/input/event9 1 172 1 && sendevent /dev/input/event9 0 0 0 && sendevent /dev/input/event9 4 4 786979 && sendevent /dev/input/event9 1 172 0 && sendevent /dev/input/event9 0 0 0
    # Play/Pause: sendevent /dev/input/event8 4 4 589836 && sendevent /dev/input/event8 1 315 1 && sendevent /dev/input/event8 0 0 0 && sendevent /dev/input/event8 4 4 589836 && sendevent /dev/input/event8 1 315 0 && sendevent /dev/input/event8 0 0 0

    #ShieldTV:
    # Up: sendevent /dev/input/event4 4 4 786498 && sendevent /dev/input/event4 1 103 1 && sendevent /dev/input/event4 0 0 0 && sendevent /dev/input/event4 4 4 786498 && sendevent /dev/input/event4 1 103 0 && sendevent /dev/input/event4 0 0 0
    # UP: sendevent /dev/input/event4 4 4 786498 && sendevent /dev/input/event4 1 103 1 && sendevent /dev/input/event4 0 0 0 && sendevent /dev/input/event4 4 4 786498 && sendevent /dev/input/event4 1 103 0 && sendevent /dev/input/event4 0 0 0
    # Down: sendevent /dev/input/event4 4 4 786499 && sendevent /dev/input/event4 1 108 1 && sendevent /dev/input/event4 0 0 0 && sendevent /dev/input/event4 4 4 786499 && sendevent /dev/input/event4 1 108 0 && sendevent /dev/input/event4 0 0 0
    # Left: sendevent /dev/input/event4 4 4 786500 && sendevent /dev/input/event4 1 105 1 && sendevent /dev/input/event4 0 0 0 && sendevent /dev/input/event4 4 4 786500 && sendevent /dev/input/event4 1 105 0 && sendevent /dev/input/event4 0 0 0
    # Right: sendevent /dev/input/event4 4 4 786501 && sendevent /dev/input/event4 1 106 1 && sendevent /dev/input/event4 0 0 0 && sendevent /dev/input/event4 4 4 786501 && sendevent /dev/input/event4 1 106 0 && sendevent /dev/input/event4 0 0 0
    # Select: sendevent /dev/input/event4 4 4 786497 && sendevent /dev/input/event4 1 353 1 && sendevent /dev/input/event4 0 0 0 && sendevent /dev/input/event4 4 4 786497 && sendevent /dev/input/event4 1 353 0 && sendevent /dev/input/event4 0 0 0
    # Back: sendevent /dev/input/event4 4 4 786980 && sendevent /dev/input/event4 1 158 1 && sendevent /dev/input/event4 0 0 0 && sendevent /dev/input/event4 4 4 786980 && sendevent /dev/input/event4 1 158 0 && sendevent /dev/input/event4 0 0 0
    # Home: sendevent /dev/input/event4 4 4 786979 && sendevent /dev/input/event4 1 172 1 && sendevent /dev/input/event4 0 0 0 && sendevent /dev/input/event4 4 4 786979 && sendevent /dev/input/event4 1 172 0 && sendevent /dev/input/event4 0 0 0
  

Hope someone has some insight into this, it is quite frustrating.

I’ve been struggling with this same thing. Have you figured anything out yet?

Unfortunately not yet. I can sidestep the issue by sending commands through my SamsungTV integration, and those seem fast enough, but I’d prefer to have the google integration work.

On discord someone mentioned that those commands only work when the remote is actively connected to the chromecast. Otherwise when the remote falls asleep, those commands apparently stop working. I was not able to replicate this, though. No matter if my remote had just been used or not, the Adb commands don’t work. So no progress there.

Yeah. I don’t think the remote being inactive is the problem. I’m getting nowhere with this though. Hopefully some clever person will be kind enough to let us know when they figure it out.

1 Like

That’s because sendevent command doesn’t work on CCwGTV. You’ll get “Permission denied” error when trying to do that.

Please try this script I created: https://github.com/redphx/hassio-cookbook/tree/main/scripts/androidtv_press_buttons

2 Likes

Will usb debugging work with usb hub or any other usb device connected? On mibox s it is impossible. When turning on usb debugging usb power is cut off so it is not possible to use for example usb ethernet adapter at the same time. I would like to know before I buy it as I want to add ethernet connection (hub).

Thanks @redphx, I will have to try that out! If you wouldnt mind, I’d love an explanation for how your script works.

As for your question @Wojtas, I assume you want to connect a USB hub to the “Chromecast with Google TV” and youre wondering if you’d be able to still use USB debugging? I imagine yes, because currently I have no USB connected to the device, and yet despite that, I am getting all the network debugging features. So I imagine adding a USB device/hub will not change that.

1 Like

Basically it combines multiple buttons into one command instead of sending command buttons one by one.

Had the same problem. I tried with adb server and adb-python but both didn’t stop freezing.
I think disabling the screencap at androidtv integration fixes the problem.