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
73.39k stars 30.65k forks source link

Philips TV integration loses connection to TV #57093

Closed Burn-In closed 2 years ago

Burn-In commented 3 years ago

The problem

Everything is working fine for some days. Then, after a standby period of the TV, the integration didn't re-connect to the TV again and shows "Off". At this time the TV is still available under xxx.xxx.xxx.xx:1925/system. A delete and add of the integration didn't work, because "Unknown error occurred" while connecting. But a restart of Home Assistant works repeatable.

Is there anything what i can test or check?

What is version of Home Assistant Core has the issue?

core-2021.9.7

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

Philips TV

Link to integration documentation on our website

https://github.com/home-assistant/core/tree/dev/homeassistant/components/philips_js

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 3 years ago

philips_js documentation philips_js source (message by IssueLinks)

probot-home-assistant[bot] commented 3 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)

dwainscheeren commented 2 years ago

Got some problems here, for some weeks now. Re-installed the Philips integration multiple times then it works 1-2 days then my tv is Off for days while it is On

elupus commented 2 years ago

If a restart solves the problem. It indeed looks like some leak of http sessions. Will see if I can reproduce.

VaillantHassIo commented 2 years ago

Same issue here. Only way to recover from it is to de-install Philips TV Integration and reinstall + reconfigure

elupus commented 2 years ago

Next release should solve this.

VaillantHassIo commented 2 years ago

will it work (API) with the TV in standby as well or do i need to keep the WakeOnWLAN Feature enabled? talkign about release, you mean HA core release?

elupus commented 2 years ago

Fixed by #59723 please reopen after next release if issue persists.

Burn-In commented 2 years ago

Still don't work for version core-2021.11.5.

elupus commented 2 years ago

Sadly. The updated httpcore lib contained a new similar bug :(. https://github.com/encode/httpcore/pull/443

nikrays commented 2 years ago

After updating to 12.21.1 I am experiencing the same problems with Philips TV control, after a while after restarting the TV or HA, the TV becomes unavailable. Did I understand correctly that there is no solution yet?

elupus commented 2 years ago

No sadly no solution yet.

albanco commented 2 years ago

Thanks a lot for all the explorations done so far! Should mueslo's investigations and patch (https://github.com/home-assistant/core/issues/60150) help with this or these are two separate problems?

elupus commented 2 years ago

It should help here. Probably fix it.

albanco commented 2 years ago

It should help here. Probably fix it.

Great! Is it something we can help test with the latest HA 2021.12.1 release, or through another way?

elupus commented 2 years ago

You'd need to patch httpcore with the linked request. Can be tricky to do.

albanco commented 2 years ago

Thanks. I've manually patched connection.py in httpcore. I'll share updates on the component stability after a few days.

albanco commented 2 years ago

After a week, no issue. No ghost connections, hass always manages to connect to TV, no need to reboot hass or the TV, and the TV responds to all commands. Sounds like the httpcore fix does the job! Well done elupus and mueslo. Hope it can be released soon :)

nikrays commented 2 years ago

I understand that there is no fix yet? The latest release 12.4 did not make it

nikrays commented 2 years ago

After a week, no issue. No ghost connections, hass always manages to connect to TV, no need to reboot hass or the TV, and the TV responds to all commands. Sounds like the httpcore fix does the job! Well done elupus and mueslo. Hope it can be released soon :)

Hello, how can I do the same for the first time? What does the needle need to change?

nikrays commented 2 years ago

you already have the httpcore fix ready?

elupus commented 2 years ago

The fix is ready but not merged nor released. Httpcore us not our library, so we dont control it's release schedule. I will close this issue once it's merged.

rossiluis22 commented 2 years ago

Thanks. I've manually patched connection.py in httpcore. I'll share updates on the component stability after a few days.

Hi @albanco , could you explain a little bit how do you manage to manually patch it?

I would like to give it a try before Httpcore merge the changes.

Thanks in advance

albanco commented 2 years ago

Hi, I've edited httpcore connection.py file as per mueslo's PR (https://github.com/encode/httpcore/pull/443). It introduces additional exception management. Hope it helps.

nikrays commented 2 years ago

Hi, I've edited httpcore connection.py file as per mueslo's PR (encode/httpcore#443). It introduces additional exception management. Hope it helps.

Hi @albanco, need to make changes according to this patch?

Will it not bother you to share the ready-made solution connection.py, as well as suggest where this file is located?

And by the way, do you still have no problems with the inaccessibility of the TV?

markobel commented 2 years ago

I think is understood the patch on connection.py file. The question is where we can find this file to be manual patch in the local HA installation ?

As it is my understanding it seems that the httpcore is something that HA load from other surces, so how we can modify the file inside the installation ?

Thanks for your great job, it is in any case very helpfull for the whole comunity to improove.

albanco commented 2 years ago

The question is where we can find this file to be manual patch in the local HA installation ? As it is my understanding it seems that the httpcore is something that HA load from other surces, so how we can modify the file inside the installation ?

The path of httpcore may vary from one python installation to another. Most of the time, it will be under the site-packages folder. You can use these commands to find the path in your setup.

cd / find -name 'httpcore'

In my setup, the path is /usr/local/lib/python3.9/site-packages/httpcore

That's what the find command returns.

Will it not bother you to share the ready-made solution connection.py, as well as suggest where this file is located?

Best is to get the connection.py files from mueslo's PR (https://github.com/encode/httpcore/pull/443) . To say all, I've patched manually editing with vim

And by the way, do you still have no problems with the inaccessibility of the TV?

Yes, the TV still works fine :)

markobel commented 2 years ago

Thanks to @albanco I can modify the file with the patch.

I will report if there will be any connection lack.

nikrays commented 2 years ago

Dear, @albanco, the point is that I use hassos, please tell me what steps can I take?

markobel commented 2 years ago

@nikrays I'm don't have experiences with hass.os but i think that you can install the terminal plugin and work with that.

https://community.home-assistant.io/t/community-hass-io-add-on-terminal/33814

markobel commented 2 years ago

After few hours of working with the manual patched files i noted as follow : TV 1 (55OLED854/12) is continuosly working without problem TV 2 (50PUS8556/12) was disconnect but was eanugh to reload the integration to let it working again. Before the patch there was no way to let the TV working again.

Just noted that i do not restart the TV as I working remotely now, i will restart both TS's late when I will be at home and give other reports.

nikrays commented 2 years ago

Another update and without fixing httpcore, why don't they want to fix it? It's not difficult ..

elupus commented 2 years ago

Another update and without fixing httpcore, why don't they want to fix it? It's not difficult ..

So why don't you fix it...

Ps. It is not a library owned by me nor by home assistant. There have been no new release.

nikrays commented 2 years ago

Another update and without fixing httpcore, why don't they want to fix it? It's not difficult ..

So why don't you fix it...

Ps. It is not a library owned by me nor by home assistant. There have been no new release.

I cannot do this, I have hassos, no access to this library

amadeo-alex commented 2 years ago

They've closed encode/httpcore#443 in favour of encode/httpcore#475. I was going to do the changes manually as albanco did but instead I'll do the changes merged in 475 and see if it also fixes our issues.

nikrays commented 2 years ago

They've closed encode/httpcore#443 in favour of encode/httpcore#475. I was going to do the changes manually as albanco did but instead I'll do the changes merged in 475 and see if it also fixes our issues.

but how do you make the AK yourself? what can I do? I've been waiting for a year when the integration with the TV will work normally.

markobel commented 2 years ago

I just install httpcore 0.14.4, and it seems to work properly with the TV as far. I will keep update after some days of running.

amadeo-alex commented 2 years ago

They've closed encode/httpcore#443 in favour of encode/httpcore#475. I was going to do the changes manually as albanco did but instead I'll do the changes merged in 475 and see if it also fixes our issues.

but how do you make the AK yourself? what can I do? I've been waiting for a year when the integration with the TV will work normally.

The normal way is to wait for the fix (if the one proposed by them works, I've already made the changes, we'll see) is to wait for the new version of httpcore lib to be released and then updated by HA project. If you want to do as I did you need to manually edit the files within HA or update the whole httpcore to version with the merged changes (like markobel did).

nikrays commented 2 years ago

They've closed encode/httpcore#443 in favour of encode/httpcore#475. I was going to do the changes manually as albanco did but instead I'll do the changes merged in 475 and see if it also fixes our issues.

but how do you make the AK yourself? what can I do? I've been waiting for a year when the integration with the TV will work normally.

The normal way is to wait for the fix (if the one proposed by them works, I've already made the changes, we'll see) is to wait for the new version of httpcore lib to be released and then updated by HA project. If you want to do as I did you need to manually edit the files within HA or update the whole httpcore to version with the merged changes (like markobel did).

Please give instructions on how to do this on hassos .. I'm just going crazy and can't figure out the correct course of action ..

amadeo-alex commented 2 years ago

They've closed encode/httpcore#443 in favour of encode/httpcore#475. I was going to do the changes manually as albanco did but instead I'll do the changes merged in 475 and see if it also fixes our issues.

but how do you make the AK yourself? what can I do? I've been waiting for a year when the integration with the TV will work normally.

The normal way is to wait for the fix (if the one proposed by them works, I've already made the changes, we'll see) is to wait for the new version of httpcore lib to be released and then updated by HA project. If you want to do as I did you need to manually edit the files within HA or update the whole httpcore to version with the merged changes (like markobel did).

Please give instructions on how to do this on hassos .. I'm just going crazy and can't figure out the correct course of action ..

If by hasos you mean the supervised installation I won't be of much use as I'm from the "HA in docker tribe" ;) (below may be not so good instruction, I'm mostly guessing) You'll need to access HA files somehow (some ssh addon maybe?) and then use above command: find -name 'httpcore' to find the httpcore installation. After that use vim to modify files as in the pull request. OR After gaining access to HA installation via ssh, update the httpcore with pip3 as markobel did.

nikrays commented 2 years ago

They've closed encode/httpcore#443 in favour of encode/httpcore#475. I was going to do the changes manually as albanco did but instead I'll do the changes merged in 475 and see if it also fixes our issues.

but how do you make the AK yourself? what can I do? I've been waiting for a year when the integration with the TV will work normally.

The normal way is to wait for the fix (if the one proposed by them works, I've already made the changes, we'll see) is to wait for the new version of httpcore lib to be released and then updated by HA project. If you want to do as I did you need to manually edit the files within HA or update the whole httpcore to version with the merged changes (like markobel did).

Please give instructions on how to do this on hassos .. I'm just going crazy and can't figure out the correct course of action ..

If by hasos you mean the supervised installation I won't be of much use as I'm from the "HA in docker tribe" ;) (below may be not so good instruction, I'm mostly guessing) You'll need to access HA files somehow (some ssh addon maybe?) and then use above command: find -name 'httpcore' to find the httpcore installation. After that use vim to modify files as in the pull request. OR After gaining access to HA installation via ssh, update the httpcore with pip3 as markobel did.

I'll try and after restarting the server, the changes in the file will be saved, I'm afraid not, since the home assistant os assumes that HA is in docker ..

elupus commented 2 years ago

In Hassos, it might. I press might, be enough to do a "ha core rebuild" to get new dependencies in since i don't think the httpcore is pinned anywhere.

https://www.home-assistant.io/common-tasks/os/

alex-levashev commented 2 years ago

Hey,

Joining this thread too, I run hassio and have the same issue with TV plugin. Can't figure out how to update system manually? Is there any step-by-step guide. I run terminal but there is not httpcore package in my system.

amadeo-alex commented 2 years ago

Small insignificant update: before testing the merged changes in httpcore I've removed PhilipsTV integration to establish a baseline - after a night of the TV being off it successfully responds to ping and requests sent by pylips python library. I'll pair the TV with HA now and observe how it goes.

nikrays commented 2 years ago

share the command to update httpсore via pip3

markobel commented 2 years ago

Try if this can help, I run HA in a docker with QNAP NAS container station.

So from the pc terminal a login SSH to my NAS ssh -p "YOUR ADMIN USER"@"YOUR IP OF THE NAS"

Then log in to the HA container (In My case is "home-assistant-2021.12.8", replace with your container name. docker exec -u 0 -it home-assistant-2021.12.8 bash

From this point you are logged SSH in to your container installation, so you can install the httpcore version you wont.

pip install httpcore-0.14.4

End / Or navigate trough the httpcore folder as @albanco explain to modify the component.

markobel commented 2 years ago

With the last httpcore 0.14.4 I notice that the connection still goes randomly.

I just try to install in both TV the wakelock 3.2.0 app. https://android-apk.org/id/46810985/

In the app set to keep the cpu alive. After this the connection still good without any lack.

nikrays commented 2 years ago

That is, updating to 0.14.4 does not completely solve the problem? The socket leak still persists? I was able to update httpcore via pip and for the changes to take effect I need to restart my raspberry 4? Most interestingly, after rebooting its httpcore returns to the previous version again .. a vicious circle 🤦🏻

amadeo-alex commented 2 years ago

That is, updating to 0.14.4 does not completely solve the problem? The socket leak still persists? I was able to update httpcore via pip and for the changes to take effect I need to restart my raspberry 4? Most interestingly, after rebooting its httpcore returns to the previous version again .. a vicious circle 🤦🏻

Philips TVs have a known problem of jumping into winter sleep without any apparent reason. My suspicion it that is is either due to their faulty software or us fiddling with the REST API with ways that are not supported (the api is basically reverse engineered).

Status update on my tests: httpcore in version 0.14.4, tv without any ECO options and with WoWLAN and Chromecast on enabled - no issues so far (few hours between TV usage sessions)

nikrays commented 2 years ago

That is, updating to 0.14.4 does not completely solve the problem? The socket leak still persists? I was able to update httpcore via pip and for the changes to take effect I need to restart my raspberry 4? Most interestingly, after rebooting its httpcore returns to the previous version again .. a vicious circle 🤦🏻

Philips TVs have a known problem of jumping into winter sleep without any apparent reason. My suspicion it that is is either due to their faulty software or us fiddling with the REST API with ways that are not supported (the api is basically reverse engineered).

Status update on my tests: httpcore in version 0.14.4, tv without any ECO options and with WoWLAN and Chromecast on enabled - no issues so far (few hours between TV usage sessions)

That is, it turns out that it still works... well, I'll have to wait for the OS update ..