Status always 'off' after upgrading firmware on CCwGTV

After the latest firmware update on my Chromecast with Google TV, home assistant can’t see the status of the device; it always always as ‘off’. I can still still turn it on and off because that’s the only button offered by the UI when it’s off.

I guess this last update introduced Android 12. I don’t know if that has anything to do with it.

Anyone else experiencing this?

1 Like

Same here after upgrading to Android TV 12, and friend has same problem.

The update for Android 12 just popped up on my CCwGTV so naturally I came here to check if anything is broken. Looks to be the case.

Any information about Android 12 - is this a security access issue for the integration or just something that needs to be updated or tweaked?

It’s weird for me because I can turn it on successfully, and it doesn’t show as ‘unavailable’, but I can’t see that I turned it on.

Same here turn off/on works but it’s unavailable.

Same here. Log dump:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 515, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 710, in async_device_update
    raise exc
  File "/usr/src/homeassistant/homeassistant/components/androidtv/media_player.py", line 178, in _adb_exception_catcher
    return await func(self, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/components/androidtv/media_player.py", line 499, in async_update
    ) = await self.aftv.update(self._get_sources)
  File "/usr/local/lib/python3.10/site-packages/androidtv/androidtv/androidtv_async.py", line 123, in update
    ) = await self.get_properties(get_running_apps=get_running_apps, lazy=lazy)
  File "/usr/local/lib/python3.10/site-packages/androidtv/androidtv/androidtv_async.py", line 180, in get_properties
    screen_on, awake, wake_lock_size = await self.screen_on_awake_wake_lock_size()
  File "/usr/local/lib/python3.10/site-packages/androidtv/basetv/basetv_async.py", line 378, in screen_on_awake_wake_lock_size
    output = await self._adb.shell(constants.CMD_SCREEN_ON_AWAKE_WAKE_LOCK_SIZE)
  File "/usr/local/lib/python3.10/site-packages/androidtv/adb_manager/adb_manager_async.py", line 439, in shell
    return await self._adb.shell(cmd)
  File "/usr/local/lib/python3.10/site-packages/adb_shell/adb_device_async.py", line 881, in shell
    return await self._service(b'shell', command.encode('utf8'), transport_timeout_s, read_timeout_s, timeout_s, decode)
  File "/usr/local/lib/python3.10/site-packages/adb_shell/adb_device_async.py", line 749, in _service
    return b''.join([x async for x in self._streaming_command(service, command, transport_timeout_s, read_timeout_s, timeout_s)]).decode('utf8', 'backslashreplace')
  File "/usr/local/lib/python3.10/site-packages/adb_shell/adb_device_async.py", line 749, in <listcomp>
    return b''.join([x async for x in self._streaming_command(service, command, transport_timeout_s, read_timeout_s, timeout_s)]).decode('utf8', 'backslashreplace')
  File "/usr/local/lib/python3.10/site-packages/adb_shell/adb_device_async.py", line 1329, in _streaming_command
    async for data in self._read_until_close(adb_info):
  File "/usr/local/lib/python3.10/site-packages/adb_shell/adb_device_async.py", line 1286, in _read_until_close
    await self._io_manager.send(msg, adb_info)
  File "/usr/local/lib/python3.10/site-packages/adb_shell/adb_device_async.py", line 413, in send
    await self._send(msg, adb_info)
  File "/usr/local/lib/python3.10/site-packages/adb_shell/adb_device_async.py", line 557, in _send
    await self._transport.bulk_write(packed, adb_info.transport_timeout_s)
  File "/usr/local/lib/python3.10/site-packages/adb_shell/transport/tcp_transport_async.py", line 130, in bulk_write
    self._writer.write(data)
AttributeError: 'NoneType' object has no attribute 'write'

Also found it tracked here: Chromecast with Google TV devices updated to Android 12 not working correctly with Android TV integration · Issue #80555 · home-assistant/core · GitHub

One of my CCwGTV devices forcefully updated last night so now I’m stuck with this issue, breaking some automations. Hope that the androidtv python library gets updated soon by someone who knows their stuff.

FYI this Android 12 update also resets your chosen Screensaver (I use a custom gallery app). You have to use ADB to force your chosen screensaver app again

same here.

same here :slightly_frowning_face:

@OC_Nice @SomeoneSinister @jdbrookes @Sabellwind @siklosi @SteveDinn

Workaround Fix
Ok, so Im in the same boat as you all. For whatever reason my Shield TV is still running, though I believe its running Android 12 as well.

The link sabellwind posted pointed me in the right direction, but I was unsure how to gain access to the directory listed so I can edit the line in constants.py. For what its worth Im running HA on Debian Supervised.

So my work around was to download the 3rd party custom component someone wrote when android11 released and caused its own set of problems.
I then edited the constants.py file in the custom component restarted HA and my Android12 based Chomecast (Google TV) is working in HA again.

Start by downloading the custom component

Navigate to your config folder for your instance of HA, it should be in your user shares.
If you have a “Custom Components” folder already open it, if not create one.
In this folder, create a new folder called “androidtv” and open it.
You should now be in the following directory.
\config\custom_components\androidtv\

Open the zip file you downloaded for HA-androidtv11.
Open the HA-androidtv11-main folder in the zip.
Extract the contents of this folder into \config\custom_components\androidtv
Now in the extracted contents open the “androidtv11hack” folder and double click on constants.py
config\custom_components\androidtv\androidtv11hack\constants.py
In this file scroll down to line 179
The entry should be as follows

#: Determine if the device is on
CMD_SCREEN_ON = (
    "(dumpsys power | grep 'Display Power' | grep -q 'state=ON' || dumpsys power | grep -q 'mScreenOn=true')"
)

Replace this with the following.

#: Determine if the device is on
CMD_SCREEN_ON = (
    "(dumpsys power | grep 'Display Power' | grep -q 'state=ON' || dumpsys power | grep -q 'mScreenOn=true' || dumpsys display | grep -q 'mScreenState=ON')"
)

Save the file.
Restart HA

It should be working again.

It seems they are getting close to fixing this issue, there is a bug that causes the device to show as off that pops up randomly right now, but it only lasts for about 3 seconds before it goes back to showing the correct state. To work around this set any automations that are based on the off state for these devices to show as “off” for at least 4 seconds before running the automation.

Keep an eye on the update logs for HA.
When they finally release a fix for this all you have to do is delete the “androidtv” folder in Custom Components, restart HA, and the it will go back to using the built in version.

Hope this helps

1 Like

Thanks for your detailed post Bill.
I stumbled on to the same information you provided. I was aware of the changes I needed to make but as I am running HASSOS I didn’t have access to the files I was required to edit.
I did also stumble across the andriod11 hack, but for some wierd reason I assumed it relied on the AndriodTV integration to function so i ignored it.

Anyway thanks for the information, I was almost about to try and make the jump from HassOS but I don’t have much of an understanding of dockers/containers, so am still reluctant to try.

Still an issue in 2022.11.4
For those running HASSOS here are the steps I went through as a temp fix.

Requires ‘SSH & Web Terminal’ installed from HACS

Go to SSH & Web Terminal Addon
Disable Protection mode
Start Addon
Launch web console and run below commands:

docker exec -it $(docker ps -f name=homeassistant -q) bash
cd /usr/local/lib/python3.10/site-packages/androidtv
vi constants.py

Find the below in the vi text editor:

#: Determine if the device is on
CMD_SCREEN_ON = (
    "(dumpsys power | grep 'Display Power' | grep -q 'state=ON' || dumpsys power | grep -q 'mScreenOn=true')"
)

Press the ‘a’ key to enter append mode in VI and replace with this:

#: Determine if the device is on
CMD_SCREEN_ON = (
    "(dumpsys power | grep 'Display Power' | grep -q 'state=ON' || dumpsys power | grep -q 'mScreenOn=true' || dumpsys display | grep -q 'mScreenState=ON')"
)

Save file (press escape key and type ‘wq’ without quotes and press enter)
type exit
type exit
You should now be disconnected from the terminal session.
Stop the SSH & Web Terminal Addon
Enable Protection mode
Dev tools and restart HA.

3 Likes