home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
74.03k stars 31.06k forks source link

Philips TV integration is disconnected from the TV after approx. 5 mins #64359

Closed alex-levashev closed 2 years ago

alex-levashev commented 2 years ago

The problem

Hi,

My TV model is 48PFT5500/12. After updating to the latest version (2021.12.10) I still experience an issue with TV off in HA after 5 mins. This happens every time. Is there any way to solve it? I can provide logs if needed, but I don't know how to switch then to debug mode.

What version of Home Assistant Core has the issue?

2021.12.10

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

philipsjs

Link to integration documentation on our website

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

probot-home-assistant[bot] commented 2 years ago

philips_js documentation philips_js source (message by IssueLinks)

probot-home-assistant[bot] commented 2 years ago

Hey there @elupus, mind taking a look at this issue as it has been labeled with an integration (philips_js) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)

elupus commented 2 years ago

Please update the description. You said it turns off 5nminutes after you turn of the TV.

This is normal behaviour for the TV. You need wakelock the TV or add WOL commands to wake it again.

Sdahl1234 commented 2 years ago

I am om 2012.12.10 and Home Assistant Os 7.2 I have 4 philips android tv's 3 philips 32PFS6402/12 and 1 philips 55PUS8303/12 If I turn on the TV's the integration detects all 4. After 5 minutes leaving all TV on the integration shows the 3 32" as "turned off" but the 55" is still shown as "turned on". Turning all 4 TV's off on the remote and its still possible to turn all 4 on again with the integration. Turning all 4 TV's off on the remote and on again with the remote the integration detects that all 4 are "turned on" After 5 minutes the 3 32" shows as "turn off" again but not the 55"

beside the deep sleep issue my 55" tv is working fine but my 32" only shows as ON for 5 minutes.

All TV's has to be turned on with the remote once a days because of the deep sleep issue with philips.

alex-levashev commented 2 years ago

Please update the description. You said it turns off 5nminutes after you turn of the TV.

This is normal behaviour for the TV. You need wakelock the TV or add WOL commands to wake it again.

Sorry but it seems not normal to me. Let’s describe it point by point.

  1. I turn the Tv on with a remote.
  2. I look at HA and it’s showing as turned on
  3. I wait for approx. 5 mins and in the HA it’s start showing as Off, but it’s ON in reality.
  4. To make it ON in HA again I have to turn it off and on via remote.

It seems not really working as expected for me.

elupus commented 2 years ago

That does not seem correct no. Can you turn on debug logs.

haphilipsjs: debug homeassistant.components.philips_js: debug

alex-levashev commented 2 years ago

That does not seem correct no. Can you turn on debug logs.

haphilipsjs: debug homeassistant.components.philips_js: debug

These lines should be in configuration yaml, right?

elupus commented 2 years ago

For the logger component: https://www.home-assistant.io/integrations/logger/

You can also turn it on temporarily with the service.

alex-levashev commented 2 years ago

Hey,

Here is a part of the log:

2022-01-20 22:28:26 DEBUG (MainThread) [haphilipsjs] Get succeded: powerstate -> {"powerstate":"On"} 2022-01-20 22:28:26 DEBUG (MainThread) [haphilipsjs] Get succeded: audio/volume -> {"muted":false,"current":20,"min":0,"max":60} 2022-01-20 22:28:26 DEBUG (MainThread) [haphilipsjs] Get succeded: activities/tv -> {"channel":{"ccid":842,"preset":28,"name":"CT24HD"},"channelList":{"id":"1","version":"16"}} 2022-01-20 22:28:26 DEBUG (MainThread) [haphilipsjs] Get succeded: activities/current -> {"component":{"packageName":"com.kinopub","className":"com.kinopub.activity.LaunchActivity"}} 2022-01-20 22:28:26 DEBUG (MainThread) [haphilipsjs] Get succeded: context -> {"level1":"NA","level2":"NA","level3":"NA","data":"NA"} 2022-01-20 22:28:26 DEBUG (MainThread) [haphilipsjs] Get failed: screenstate -> 404 <html> 2022-01-20 22:28:30 INFO (MainThread) [homeassistant.components.automation.ubrat_login_failed] Убрать Login failed : Running automation actions 2022-01-20 22:28:30 INFO (MainThread) [homeassistant.components.automation.ubrat_login_failed] Убрать Login failed : Executing step call service 2022-01-20 22:28:31 DEBUG (MainThread) [haphilipsjs] TV not available: ConnectionFailure(ConnectTimeout(''))

Full log is attached:

core.log

elupus commented 2 years ago

Looks like ambilight requests keep on crashing on the TV. Do you have ambilight on your TV? is it in some special mode?

alex-levashev commented 2 years ago

Ambilight is not available on my tv

elupus commented 2 years ago

Ok. Your TV lists the following:

"ambilight": ["LoungeLight"],

While mine lists:

"ambilight": ["LoungeLight", "Hue", "Ambilight", "HueStreaming"],

It seem to support some sort of lounge light, but we should probably disable asking for ambilight data it doesn't list "Ambilight" in that section. No idea if that would solve your issue thou.

If you are able to patch the haphilipsjs component either by finding the python files on your install or cloning repo/modify and pip install the custom version, you can try and remove the following lines:

https://github.com/danielperna84/ha-philipsjs/blob/16e363cde45b9f0c38fbd501560864c620606696/haphilipsjs/__init__.py#L713-L716 https://github.com/danielperna84/ha-philipsjs/blob/16e363cde45b9f0c38fbd501560864c620606696/haphilipsjs/__init__.py#L703-L704

And see if that solves your issue.l

alex-levashev commented 2 years ago

Seems it doesn't solve the issue:

Here is the log, no 404's so far, but still conectiontimeout.

2022-01-22 19:22:42 DEBUG (MainThread) [haphilipsjs] Post succeded: {'current': 15, 'muted': False} -> 2022-01-22 19:22:45 INFO (MainThread) [homeassistant.components.automation.ubrat_login_failed] Убрать Login failed : Running automation actions 2022-01-22 19:22:45 INFO (MainThread) [homeassistant.components.automation.ubrat_login_failed] Убрать Login failed : Executing step call service 2022-01-22 19:22:45 DEBUG (MainThread) [haphilipsjs] Post succeded: {'current': 24, 'muted': False} -> 2022-01-22 19:22:45 DEBUG (MainThread) [haphilipsjs] Get succeded: powerstate -> {"powerstate":"On"} 2022-01-22 19:22:45 DEBUG (MainThread) [haphilipsjs] Get succeded: audio/volume -> {"muted":false,"current":24,"min":0,"max":60} 2022-01-22 19:22:45 DEBUG (MainThread) [haphilipsjs] Get succeded: activities/tv -> {"channel":{"ccid":842,"preset":28,"name":"CT24HD"},"channelList":{"id":"1","version":"16"}} 2022-01-22 19:22:46 DEBUG (MainThread) [haphilipsjs] Get succeded: activities/current -> {"component":{"packageName":"com.ottplay.ottplay","className":"com.ottplay.ottplay.SplashScreenActivity"}} 2022-01-22 19:22:46 DEBUG (MainThread) [haphilipsjs] Get succeded: context -> {"level1":"NA","level2":"NA","level3":"NA","data":"NA"} 2022-01-22 19:22:46 DEBUG (MainThread) [homeassistant.components.philips_js] Finished fetching philips_js data in 1.582 seconds (success: True) 2022-01-22 19:22:52 WARNING (MainThread) [homeassistant.components.camera] Updating xiaomi_cloud_map_extractor camera took longer than the scheduled update interval 0:00:05 2022-01-22 19:23:00 INFO (MainThread) [homeassistant.components.automation.ubrat_login_failed] Убрать Login failed : Running automation actions 2022-01-22 19:23:00 INFO (MainThread) [homeassistant.components.automation.ubrat_login_failed] Убрать Login failed : Executing step call service 2022-01-22 19:23:02 WARNING (MainThread) [homeassistant.components.camera] Updating xiaomi_cloud_map_extractor camera took longer than the scheduled update interval 0:00:05 2022-01-22 19:23:09 WARNING (MainThread) [homeassistant.components.philips_js] Failed to fetch image 2022-01-22 19:23:09 WARNING (MainThread) [homeassistant.components.philips_js] Failed to fetch image 2022-01-22 19:23:09 WARNING (MainThread) [homeassistant.components.philips_js] Failed to fetch image 2022-01-22 19:23:12 WARNING (MainThread) [homeassistant.components.camera] Updating xiaomi_cloud_map_extractor camera took longer than the scheduled update interval 0:00:05 2022-01-22 19:23:14 WARNING (MainThread) [homeassistant.components.philips_js] Failed to fetch image 2022-01-22 19:23:15 INFO (MainThread) [homeassistant.components.automation.ubrat_login_failed] Убрать Login failed : Running automation actions 2022-01-22 19:23:15 INFO (MainThread) [homeassistant.components.automation.ubrat_login_failed] Убрать Login failed : Executing step call service 2022-01-22 19:23:15 WARNING (MainThread) [homeassistant.components.philips_js] Failed to fetch image 2022-01-22 19:23:15 WARNING (MainThread) [homeassistant.components.philips_js] Failed to fetch image 2022-01-22 19:23:19 WARNING (MainThread) [homeassistant.components.philips_js] Failed to fetch image 2022-01-22 19:23:20 WARNING (MainThread) [homeassistant.components.philips_js] Failed to fetch image 2022-01-22 19:23:20 WARNING (MainThread) [homeassistant.components.philips_js] Failed to fetch image 2022-01-22 19:23:22 WARNING (MainThread) [homeassistant.components.camera] Updating xiaomi_cloud_map_extractor camera took longer than the scheduled update interval 0:00:05 2022-01-22 19:23:25 WARNING (MainThread) [homeassistant.components.philips_js] Failed to fetch image 2022-01-22 19:23:25 WARNING (MainThread) [homeassistant.components.philips_js] Failed to fetch image 2022-01-22 19:23:25 WARNING (MainThread) [homeassistant.components.philips_js] Failed to fetch image 2022-01-22 19:23:30 INFO (MainThread) [homeassistant.components.automation.ubrat_login_failed] Убрать Login failed : Running automation actions 2022-01-22 19:23:30 INFO (MainThread) [homeassistant.components.automation.ubrat_login_failed] Убрать Login failed : Executing step call service 2022-01-22 19:23:30 DEBUG (MainThread) [haphilipsjs] TV not available: ConnectionFailure(ConnectTimeout('')) 2022-01-22 19:23:30 DEBUG (MainThread) [homeassistant.components.philips_js] Finished fetching philips_js data in 14.260 seconds (success: True)

alex-levashev commented 2 years ago

I've checked also case when I just opened some app on the TV, but w/o image fetching: [homeassistant.components.philips_js] Failed to fetch image 2022-01-22 19:23:15 WARNING (MainThread) So there are no such errors, just connection timeout.

elupus commented 2 years ago

Okey. Looks like your TV is disconnecting from the network. I don't really know if this is something we can solve in the integration.

You could potentially log at ADB logs from the TV to see if you can get some hint as to why it disabled the network.

alex-levashev commented 2 years ago

That’s not right. I was watching IP TV while integration disconnects and also I can ping host and access API via browser.

elupus commented 2 years ago

Then it's just killing it's https server.

alex-levashev commented 2 years ago

Then it's just killing it's https server.

Then there would be no access to the api via browser.

elupus commented 2 years ago

You are accessing http, not https. Different servers.

alex-levashev commented 2 years ago

I may be found a root cause. Seems like this is my case. Could you please check if this “hack” is implemented in your code. https://github.com/eslavnov/pylips/issues/49

elupus commented 2 years ago

Don't think so. We allow 4 connections to the server and try to reuse as much as possible.

alex-levashev commented 2 years ago

Is there any way to find a reason logging in via adb? What log should I take a look?

elupus commented 2 years ago

Most things on the tv that is related to this logs have xtv in their log lines. You need to enable debugging in your android tv, and also enable wireless/remote debugging.

alex-levashev commented 2 years ago

Here is the logcat for the TV from the moment it is switches on till connection to the HTTPS API looses. @elupus tv.log could you please take a look? I can't understand the reason of API stopped responding.

alex-levashev commented 2 years ago

I think this part is related to the error: W/System.err( 4890): AJAYK reuse called
W/System.err( 4890): Amit:IP Address of PTA device 192.168.2.254:47654 W/System.err( 4890): Amit:Handshake status is NOT_HANDSHAKINGinbound outbound state arefalsefalse W/System.err( 4890): Amit:Exception in setting modeCan not change mode after handshake: engineState == READY W/System.err( 4890): Amit:Handshake Exception and status is NOT_HANDSHAKINGClient/server mode must be set before handshake W/System.err( 4890): Amit:Session Creation time1643218648000true[B@3319d590 W/System.err( 4890): Amit : unwrap returned an exception javax.net.ssl.SSLProtocolException: Read error: ssl=0xaf448e00: Failure in SSL library, usually a protocol error W/System.err( 4890): error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number (external/openssl/ssl/s3_pkt.c:345 0xabb14fbd:0x00000000) V/TPAPI_RESERVE( 1083): getAll->Ins[0]_HWIns[0] result: Freq=498000, Std=0, BW=3, Constel=10, SQI=100, SSI=91, Ber=0, Uncorrs=0, Rarch=0, Stream=1, Symbol=0, Lock=1 E/EpgProvider( 2753): query function called E/sectionMonitor:pumphandler( 2753): TotalSec: 3396 ,totalDuplicateSec: 54654 insertion rate 0:0/sec duplication rate 0:0/sec totalSectionReceivedFromplf 61745 W/System.err( 4890): AJAYK reuse called
W/System.err( 4890): Amit:IP Address of PTA device 192.168.2.254:47656 W/System.err( 4890): Amit:Handshake status is NOT_HANDSHAKINGinbound outbound state arefalsefalse W/System.err( 4890): Amit:Exception in setting modeCan not change mode after handshake: engineState == READY W/System.err( 4890): Amit:Handshake Exception and status is NOT_HANDSHAKINGClient/server mode must be set before handshake W/System.err( 4890): Amit:Session Creation time1643218660000true[B@190d4e8e W/System.err( 4890): Amit : unwrap returned an exception javax.net.ssl.SSLProtocolException: Read error: ssl=0xaf449000: Failure in SSL library, usually a protocol error W/System.err( 4890): error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number (external/openssl/ssl/s3_pkt.c:345 0xabb14fbd:0x00000000) E/BC_PLAYER( 1083): bcplayer: curr time @ 833.922466604 userType 6 outputPath 0

elupus commented 2 years ago

Yes, that does look a bit suspicious.

alex-levashev commented 2 years ago

Is there anything I can do to make integration works?

elupus commented 2 years ago

I really don't know to be honest. I've had issues with session re-use in the past. Maybe that is what crashes your TV. But the log doesn't really reveal anything. It complains about wrong TLS ptocol version, but since you do get data for a little while it make no sense.

alex-levashev commented 2 years ago

So how else could I help in order for this to be solved, I can do some testing, can gather logs, just let me know, I'd like this integrations to work.

alex-levashev commented 2 years ago

Here is what I've found on stackoverflow, may be it'll helps:

I found the solution for it by analyzing the data packets using wireshark. What I found is that while making a secure connection, android was falling back to SSLv3 from TLSv1 . It is a bug in android versions < 4.4 , and it can be solved by removing the SSLv3 protocol from Enabled Protocols list. I made a custom socketFactory class called NoSSLv3SocketFactory.java. Use this to make a socketfactory.

https://stackoverflow.com/questions/29916962/javax-net-ssl-sslhandshakeexception-javax-net-ssl-sslprotocolexception-ssl-han

elupus commented 2 years ago

Well that is about when the tv would make a connection, and it's a fix on the tv. Nothing too usefully for us.

I really don't know of a solution at this moment.

alex-levashev commented 2 years ago

Just for info: https://github.com/nstrelow/ha_philips_android_tv this addon works fine w/o crashes.

elupus commented 2 years ago

Ok. Strange. Do you have notifications enable in integration settings? If you do, disable them.

That integration reads so much less data each update. But would be nice to know why it works.

BFipsen commented 2 years ago

Hi, suddenly I got the same error with my 55PUS9104 After approx. 5 minutes the status changes to off in HA even though the TV is still on. I am om 2012.12.10 and Home Assistant Os 7.2 Any suggestions for a solution?

elupus commented 2 years ago

No. The only thing i could think of that might help could be a network capture netdump of the traffic. But i can't help you get that .

alex-levashev commented 2 years ago

I've ended up with using custom integration mentioned above. @elupus if you have any guide how and what should be captured, I'm ready to help.

popy2k14 commented 2 years ago

Here are my workarounds regarding the deep sleep issue i had on my android TVs.

My two options:

Sdahl1234 commented 2 years ago

I ended up doing as @alex-levashev and used the custom component on 3 of my TV's and its work without crashes. I also tried the android-tv integration but it also drops the connection. Still got 1 TV using the integrated component as it has no problems.

boltgolt commented 2 years ago

Just confirming, sadly nstrelow/ha_philips_android_tv works perfectly with my TV. The component that is in Home Assistant by default had the same issue of disconnecting after 3-5 minutes for me

elupus commented 2 years ago

Would be nice if somebody could debug why it goes to a disconnected state. Like said. This component does more than the custom component.

It's important to say of you have notification events on. What errors do you get in log.

boltgolt commented 2 years ago

As far as i can tell there are no errors until the HTTPS port stops responding and all handshakes start to fail. This is not just for this component, 4 minutes after i configured the component the tv stopped responding to any host trying to connect until i restarted the tv.

Maybe the fact that this component does more overloads or crashes the tv in some way?

elupus commented 2 years ago

@boltgolt can you turn on debug logs for haphilipsjs? My guess is the tv is rejecting some requests. Also could you upload diagnostic data? https://www.home-assistant.io/integrations/diagnostics/

Drag and drop the file into the comment field here.

popy2k14 commented 2 years ago

Guys, that's no crashes! Had android TV philips tv sets and that's normal behaviour. After you but them in standby about ~10 minutes after that, the are shutting down the network interface. Also be aware that they are doing some reboot at night ~04:;00 o clock to keep things stable. -> that's a real shit, why not find the bugs and keep your product this way stable-> but that's another story. Just wanted to let you know, if you have automations which triggers on tv on/off, be aware of this! Also struggled with this a lot!

Here is what you can do to stop at least the deep standby and shutting down the network interface:

PS.: i also have one android TV (which i will sell soon) and running the integration. I did not enable alexa, so deep standby is active. I use an ESP IR blaster to wake my tv set. But i did not noticed that issue you have.

PS.PS.: Also Wake on lan does'nt work in thisdeep standby state. This is one reason i switched to an LG OLED + Nvidia Shield. On the LG the WOL just works!

good luck

boltgolt commented 2 years ago

No that's not it.

The tv is on and playing content, but 4 minutes after configuring the component with the one-time-code from the tv it stops responding. It's still playing and responding to requests on the unsecured port, but will not respond to HTTPS until a forced reboot (or possibly the 4am reboot you mentioned, did not test that)

popy2k14 commented 2 years ago

ok, that sounds different. Did you tried factory reset and is the firmware up to date?

elupus commented 2 years ago

No that's not it.

The tv is on and playing content, but 4 minutes after configuring the component with the one-time-code from the tv it stops responding. It's still playing and responding to requests on the unsecured port, but will not respond to HTTPS until a forced reboot (or possibly the 4am reboot you mentioned, did not test that)

Does it respond if you restart home assistant (please retest)? We've had issues with leaked https connections in older revisions. It could very well still be cases where we leak connections.

LocoLoco83 commented 2 years ago

Hi, I have te problem that I can remote the TV (42PFK6549/12) after about 20 seconds. Turning te TV off and on, I can remote it again for about 20 seconds. Strange thing is. that the original Philips Remote app also don't work. But the app "PhilRemote" works fine. Also after the 20 seconds.

Any suggestions for a solution?

Nismonx commented 2 years ago

Probably unrelated but have had lots of issues with hass showing TV off and often I wasn't able to do anything with it, even if I was using on demand TV or Netflix.... What worked for me was to set a static IP address in the tv and reserved the address in my router. Been OK for several weeks now.

Old philips TV 50PUS6753/12 API6 on WiFi.

Worth a try 🤷🏻‍♂️

Editted to fix spelling

elupus commented 2 years ago

There was also some fixes hidden in 2022.6 with an httpx upgrade that could have been a good thing for when having events on. So... Can we get some reports back when people are on 2022.6 if you still have issues.

Would be sooo nice if we can close this issue (even if we find some other unrelated issues that get openend.). So please ve specific in what type of issue you are still experiencing if any.

LocoLoco83 commented 2 years ago

For me it’s working again, after update to 2022.6. Tnx alot.