Philips Android TV component

@elupus:
The problem seems to be resolved. I downloaded your branch and have setup your PR as custom component. The integration never worked longer than a hour after switching to standby before. Now, regardless of having Wakelock not installed, the TV is still connected to the integration after several hours. If tomorrow morning the situation doesn’t change / the TV once switched on can be again connected to the component without reboot, I will add a comment to the PR pointing out that this is the solution. Thank you so much for your great work! Really appreciate it!

Unfortunately this approach to select HDMI channel is not working on my TV. In the logs I see a 401 Bad request. I have a 55PUS7101 model, which is running android 8.0 Oreo. Could this be android version related and just a limitation of my TV? Unfortunately there are no new updates for the TV to upgrade to a more recent version of Android TV.

A 401 would indicate the endpoint for intent is not there. Can you start any application from the media browser?

Yes I can start for example YouTube app from the media browser without any problem. Also play store etc no issues at all.

Sorry. 401 is unauthorized. Where did you get that number? Is it in home assistant logs? Or did you just try it manually with curl?

I am sorry meant 400 bad request.
Also see my post from some time ago, which did not get any response. Here are some more details.

I also tried with curl getting the same response

I’ve been using this component and the ambilight component for a while now, but since updating Home Assistant, it isn’t working anymore.

I’m getting these errors when checking the config:

Platform error media_player.philips_android_tv - Integration 'philips_android_tv' not found.
Platform error light.philips_ambilight - Integration 'philips_ambilight' not found.

The logs says this:

2021-06-05 13:26:09 WARNING (SyncWorker_3) [homeassistant.loader] We found a custom integration philips_ambilight which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant

2021-06-05 13:26:09 ERROR (SyncWorker_3) [homeassistant.loader] The custom integration 'philips_ambilight' does not have a valid version key (None) in the manifest file and was blocked from loading. See https://developers.home-assistant.io/blog/2021/01/29/custom-integration-changes#versions for more details

2021-06-05 13:26:09 WARNING (SyncWorker_2) [homeassistant.loader] We found a custom integration philips_android_tv which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant

2021-06-05 13:26:09 ERROR (SyncWorker_2) [homeassistant.loader] The custom integration 'philips_android_tv' does not have a valid version key (None) in the manifest file and was blocked from loading. See https://developers.home-assistant.io/blog/2021/01/29/custom-integration-changes#versions for more details

Do we need to wait for an update for the version key? Of can I fix it myself?

Does anyone have the same problem? Philips integration and protocol errors.

Logger: homeassistant
Source: components/philips_js/__init__.py:134
First occurred: 9:39:45 (4 occurrences)
Last logged: 9:46:46

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/anyio/streams/tls.py", line 102, in _call_sslobject_method
    result = func(*args)
  File "/usr/local/lib/python3.8/ssl.py", line 888, in read
    v = self._sslobj.read(len)
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:2629)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/httpcore/_backends/anyio.py", line 59, in read
    return await self.stream.receive(n)
  File "/usr/local/lib/python3.8/site-packages/anyio/streams/tls.py", line 152, in receive
    data = await self._call_sslobject_method(self._ssl_object.read, max_bytes)
  File "/usr/local/lib/python3.8/site-packages/anyio/streams/tls.py", line 121, in _call_sslobject_method
    raise BrokenResourceError from exc
anyio.BrokenResourceError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/httpx/_transports/default.py", line 61, in map_httpcore_exceptions
    yield
  File "/usr/local/lib/python3.8/site-packages/httpx/_transports/default.py", line 277, in handle_async_request
    ) = await self._pool.handle_async_request(
  File "/usr/local/lib/python3.8/site-packages/httpcore/_async/connection_pool.py", line 237, in handle_async_request
    response = await connection.handle_async_request(
  File "/usr/local/lib/python3.8/site-packages/httpcore/_async/connection.py", line 148, in handle_async_request
    return await self.connection.handle_async_request(
  File "/usr/local/lib/python3.8/site-packages/httpcore/_async/http11.py", line 128, in handle_async_request
    ) = await self._receive_response(timeout)
  File "/usr/local/lib/python3.8/site-packages/httpcore/_async/http11.py", line 189, in _receive_response
    event = await self._receive_event(timeout)
  File "/usr/local/lib/python3.8/site-packages/httpcore/_async/http11.py", line 225, in _receive_event
    data = await self.socket.read(self.READ_NUM_BYTES, timeout)
  File "/usr/local/lib/python3.8/site-packages/httpcore/_backends/anyio.py", line 63, in read
    raise ReadError from exc
httpcore.ReadError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/haphilipsjs/__init__.py", line 504, in postReq
    resp = await self.session.post(self._url(path), json=data, timeout=timeout)
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1747, in post
    return await self.request(
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1426, in request
    response = await self.send(
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1511, in send
    response = await self._send_handling_auth(
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1546, in _send_handling_auth
    response = await self._send_handling_redirects(
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1580, in _send_handling_redirects
    response = await self._send_single_request(request, timeout)
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1621, in _send_single_request
    ) = await transport.handle_async_request(
  File "/usr/local/lib/python3.8/site-packages/httpx/_transports/default.py", line 272, in handle_async_request
    (
  File "/usr/local/lib/python3.8/contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/local/lib/python3.8/site-packages/httpx/_transports/default.py", line 78, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ReadError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/philips_js/__init__.py", line 134, in _notify_task
    res = await self.api.notifyChange(130)
  File "/usr/local/lib/python3.8/site-packages/haphilipsjs/__init__.py", line 1197, in notifyChange
    result = await self.postReq("notifychange", data=data, timeout=timeout_ctx)
  File "/usr/local/lib/python3.8/site-packages/haphilipsjs/__init__.py", line 522, in postReq
    raise GeneralFailure(err) from err
haphilipsjs.GeneralFailure

More than 100X appears in 2 hours of watching TV

I still lose connection after the newest updates.
Also somehow once in a while the ambilight now turns on and immediately turns off again.

edit: I know the reason why now. When I turn off the Ambilight even though it’s already off, the light turns on and immidiately off again.

Hi man, Was this the fix?

I don’t know if you changed anything in the back but the integration doesn’t lose connection for me anymore after days and I even restarted my tv in between.

@elupus is it possible to see the state of an app? e.g. playing, paused, stopped, idle, etc.

It doesn’t use notifications unless you opt into it from config entry options.

So it’s slower to react to changes.

No playing state doesn’t work for apps at all. The current intent data from the API is utterly unreliable.

1 Like

ah that’s too bad because your integration reacts so much faster than the Android ADB integration.
Anyway I’m really glad the connection is stable now. Thanks for your work!

If it’s possible for the ambilight integration to not turn on the light during a turn off call (even though it’s already off) then that would be perfect for me.

The ambilight solution in the tv is stupidly buggy. Maybe controlling it over the menu:s is less buggy. Might be worth a shot.

1 Like

sometimes I’m wondering what the development department of Philips TVs looks like.

1 Like

How is your Philips TV integration working?

For the last month or so, this integration only works for like 20-30 min after I restart HA. After that i loose “connection”. Don’t know if this started with 2021.7 or 2021.8.
Are there more people that experience this behaviour, or is something wrong with my system?

@Kardesken same problem

Hello, I also have a problem when I integrate Philips TV, everything works for about 4 days, then the TV is already in HA offline. It will only help to turn off the TV from 230. The problem will probably be with the API,
the original mobile application is still functional, only HA will lose communication.

does anyone have the same problem?

Very similar experience when TV becomes randomly unavailable in HA and can be fixed by only restarting HA or the TV itself.
Also, it seems that in such case the official component gives an error “TV unavailable” during an attempt e.g. turn on/off ambilight or the TV itself. This error breaks further execution of any automation or script that called such command.
Previously I used custom Philips TV component that didn’t have all features from the official one but was reliable in terms of keeping connection with TV and reporting on/off status.

I only need to report the ON / OF status

manual how do i do it?

I have temporarily disabled the official Philips TV integration, as it is too unreliable for any automation at the moment.

So I’ve returned back to the custom integration for now. This will give me an reliable feedback on the On/Off status of the TV.