eslavnov / pylips

Control Philips TVs (2015+) and Ambilight (+ Hue) through their reverse-engineered API (+ MQTT support!)
MIT License
342 stars 60 forks source link

[BUG] Power on won't work on 55PUS7304/12 #55

Closed TheWizard92 closed 4 years ago

TheWizard92 commented 4 years ago

Hello.

In the last version, I see that there is a power_on command, which I was very happy to see implemented.. but it doesn't seem to work on my 55PUS7304/12.

I did multiple tests:

Is there any way to fix this? Or at least start the API after sending a WoL package? (if the API starts up, I can use standby to power on the TV)

eslavnov commented 4 years ago

Hey @TheWizard92, thanks for the feedback!

Sorry to hear that it does not work for you. Could you please change this line to the following:

r = session.post("http://" + str(self.config["TV"]["host"]) +":8008/"+self.available_commands["power"][command]["path"], verify=False, timeout=2)
print(r, r.text)
return r

After making the change, please run the command again and share the output from your terminal - let's see if you are getting any error messages or anything unusual...

TheWizard92 commented 4 years ago

Hey,

I replaced the line with the three you posted and the result is this: <Response [404]>

That doesn't look promising, but if you have other ideas, let me know and I'll test them.

eslavnov commented 4 years ago

That's really strange! Do you have any chromecast/Google cast options in your TV menu? For me it's in Settings=>Android settings=>Device=>Google cast. The command exploits chromecast to power on TV, but its endpoint seems to be missing on your TV...

TheWizard92 commented 4 years ago

The only Chromecast option that I have under Settings -> Android settings -> Device is "Chromecast Android Shell". Clicking on it just says that it's "Chromecast built-in" and the Version number (in this case, 1.42.179832).

However I do have something else related to Chromecast under Settings -> Wireless and networks -> Wired or Wi-Fi -> Switch on with Chromecast. This should allow the TV to be switched on from a Chromecast app (and it's already turned on).

eslavnov commented 4 years ago

Hmm, could you please try flipping that switch manually to off and back to on? Does the command work now?

Also, have you tried casting something to your TV (just to make sure chromecast is working properly)?

TheWizard92 commented 4 years ago

Flipping that switch did nothing, so I went into "Manage Apps" and I cleared the data for Chromecast app, but this changed nothing. Then I went into the Google Play app, uninstalled the Chromecast app (which just uninstalled the latest update, since Chromecast it's a system app) and now I'm getting <Response [201]> and also my TV turns on when I run power_on command. Went back into Google Play and updated the Chromecast again and it still works (for now).

It seems that it was a Chromecast bug, not a pylips bug.. so I guess I can close this issue now. Thanks a lot for the help and for this awesome tool!

popy2k14 commented 4 years ago

@eslavnov I was really happy to see the power_on command in the latest release. Finally you did it :-)

Sadly for me it does'nt work on my 55PUS9104 and 65PUS8102 when they are in deep standby. It's been the same issue why the philips v6 api power on does not work, my TVs shutting down the network interface after ~5-10 minutes when they are in standby. They are not reachable with ping, so the arent with the philips & chromecast api. Here are the exception when sending power_on and the sets are in deep sleep:

`

pi@rfhem-pi:/usr/bin/pylips_sz $ python3 pylips.py --command power_on Traceback (most recent call last): File "/home/pi/.local/lib/python3.5/site-packages/urllib3/connection.py", line 159, in _new_conn (self._dns_host, self.port), self.timeout, **extra_kw) File "/home/pi/.local/lib/python3.5/site-packages/urllib3/util/connection.py", line 80, in create_connection raise err File "/home/pi/.local/lib/python3.5/site-packages/urllib3/util/connection.py", line 70, in create_connection sock.connect(sa) socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/pi/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 600, in urlopen chunked=chunked) File "/home/pi/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 354, in _make_request conn.request(method, url, **httplib_request_kw) File "/usr/lib/python3.5/http/client.py", line 1107, in request self._send_request(method, url, body, headers) File "/usr/lib/python3.5/http/client.py", line 1152, in _send_request self.endheaders(body) File "/usr/lib/python3.5/http/client.py", line 1103, in endheaders self._send_output(message_body) File "/usr/lib/python3.5/http/client.py", line 934, in _send_output self.send(msg) File "/usr/lib/python3.5/http/client.py", line 877, in send self.connect() File "/home/pi/.local/lib/python3.5/site-packages/urllib3/connection.py", line 181, in connect conn = self._new_conn() File "/home/pi/.local/lib/python3.5/site-packages/urllib3/connection.py", line 164, in _new_conn (self.host, self.timeout)) urllib3.exceptions.ConnectTimeoutError: (<urllib3.connection.HTTPConnection object at 0x76227330>, 'Connection to 192.168.0.7 timed out. (connect timeout=2)')

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/pi/.local/lib/python3.5/site-packages/requests/adapters.py", line 449, in send timeout=timeout File "/home/pi/.local/lib/python3.5/site-packages/urllib3/connectionpool.py", line 638, in urlopen _stacktrace=sys.exc_info()[2]) File "/home/pi/.local/lib/python3.5/site-packages/urllib3/util/retry.py", line 399, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='192.168.0.7', port=8008): Max retries exceeded with url: /apps/ChromeCast (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x76227330>, 'Connection to 192.168.0.7 timed out. (connect timeout=2)'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "pylips.py", line 463, in pylips = Pylips(args.config) File "pylips.py", line 117, in init self.run_command(args.command,body, self.verbose) File "pylips.py", line 321, in run_command return session.post("http://" + str(self.config["TV"]["host"]) +":8008/"+self.available_commands["power"][command]["path"], verify=False, timeout=2) File "/home/pi/.local/lib/python3.5/site-packages/requests/sessions.py", line 581, in post return self.request('POST', url, data=data, json=json, kwargs) File "/home/pi/.local/lib/python3.5/site-packages/requests/sessions.py", line 533, in request resp = self.send(prep, send_kwargs) File "/home/pi/.local/lib/python3.5/site-packages/requests/sessions.py", line 646, in send r = adapter.send(request, **kwargs) File "/home/pi/.local/lib/python3.5/site-packages/requests/adapters.py", line 504, in send raise ConnectTimeout(e, request=request) requests.exceptions.ConnectTimeout: HTTPConnectionPool(host='192.168.0.7', port=8008): Max retries exceeded with url: /apps/ChromeCast (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x76227330>, 'Connection to 192.168.0.7 timed out. (connect timeout=2)')) `

PS.: It works when the tv is shut off and shortly after the command is sent! So seems a deep sleep issue :-(

Thanks for your efforts but it seems my TV sets are requiring my good old IR blasters :-)

busshi commented 4 years ago

Hello I have the same issue with powerOn command. If deep sleep no wake up ! I tried first without sending WOL packet then with magic packet, same issue. Chromecast is well set up, even the WoWLAN option... I use this command to force powerOn in which I have replace IP with TV’s. curl -v http://IP:8008/apps/ChromeCast -X POST

popy2k14 commented 4 years ago

Yeah, also tried with etherwake, but no success sadly.

busshi commented 4 years ago

I tried to turn it on with Alexa and it works even TV is in deep sleep using Alexa’s app in my 7303 series TV. When I remove the Alexa’s app to control via command line it is not working. So I think my TV is able to be turned on back from deep sleep. I tried to find the hidden service menu to disable deep sleep but all the combinaisons to enter this menu don’t work...

popy2k14 commented 4 years ago

Just a quick question to everyone here which are using this approach successfully or not.

How have you connected your tv set to your network? WiFi or wired?

In my case it was always wired -> hey an cable is an cable!

Now i have made the following interresting findings: When you disconnect it from cable and connect it to your WiFi it is ALWAYS reachable with ping. Also after 1 hour!

Here is an powerstate request with pylips after ~1 hour on WiFi in Standby:

pi@rfhem-pi:/usr/bin/pylips_sz $ python3 pylips.py --command powerstate
Sending GET request to https://192.168.0.7:1926/6/powerstate
Request sent!
{"powerstate":"Standby"}

Maybe that's the issue i and others facing here?

busshi commented 4 years ago

I tried both wired and wifi but same issue... Even if I am not using Wifi I abled it on TV settings’. Yesterday I made a lot of tests and one time the TV was reachable 2 hours after being powered off (by wire the Wifi was disabled)...

I also tried with http and https (with credentials) and same result !

popy2k14 commented 4 years ago

You are right :-( As time of reading your post the ping's timed out in my cmd window :-( It's so sad that philips just made it so hard for smarthome users to interact with their sets...

BUT i am currently working on an bash test script which looks promising... Coming back here after i have a test script ready...

busshi commented 4 years ago

As I said previously my alexa device is able to turn the TV on instantly so if I am able to catch the trafic with Wireshark maybe I will find a way to make it works but for now I don’t know how to well use Whireshark because there are a lot of informations. If someone could help me with that...?

If you want I have made a bash script to control my TV I don’t use the python script, I can share it if it helps...

popy2k14 commented 4 years ago

Ah, i overlooked that. That would be really nice to capture the traffic. Can you please explain how you connected Alexa to your TV set? Maybe mine is missing Alexa support...

I can help you with wireshark: Open it, and select the network adapter you want to sniff. Be sure that you are on the same network/switch as your tv/alexa. Then you see the packets. Now set a display filter -> enter the following in the display filter box above the packets window:

eth.addr == 01:02:03:04:05:06 || ip.addr == IP_OF_TV

Sure with the correct mac and ip of your tv.

Good luck

busshi commented 4 years ago

Thanks for the tip I am gonna try this. To connect Alexa, install Alexa in your TV available on the Play Store. Then just follow instructions on the TV to pair your devices. You will see the TV asking you if you want to disable deep sleep to turn it on (this feature works very well instantly). But if you unpair your devices deep sleep come back ! I know there is a hidden service menu in the TV but I was not able to enter it with commands I found on the web...

popy2k14 commented 4 years ago

Cant we just leave the ALexa app on the TV to prevent deep sleep?

busshi commented 4 years ago

Yes you can ! But you will have to give your datas to Amazon and Google instead of being « cloud free » !!!

popy2k14 commented 4 years ago

Ok, i got you! In my case thats not a issue, those companys have all already all my data :-) Using 7 Alexas at my place here. So thats not an issue.

But yeah an "hidden" option to disable deep sleep yould be really really nice.

But i think we are on the wrong track here. When the alexa app disables deep sleep the app can constantly communicate with amazon services in the backgrond -> hence the on/off feature is working instant.

The thing we have to find out is what the alexa app is doing to disable deep sleep...

popy2k14 commented 4 years ago

another idea: install the alexa app but dont enter your credentials ... can you try this?

busshi commented 4 years ago

I already tried this because Alexa’s app is always on mine TV I can’t remove it. I just can remove my login informations. In this case it doesn’t work anymore. I will try with Wireshark opened and begin pairing Alexa and TV to see what happens but I am afraid commands are sent from Alexa to Amazon cloud, then to Google cloud and finally to the TV so I am not sure to find something with this ! Once I have something good with Wireshark I will post here.

popy2k14 commented 4 years ago

Now i have tested the developer option "Stay awake", sadly ethernet also going offline after a few minutes.

busshi commented 4 years ago

I don’t know this option. Is it on the TV settings ? I don’t have any kind option like that ! Just basics options like WoWLAN... My TV is a 50PUS7303

popy2k14 commented 4 years ago

Go into Android setting -> Info -> click multiple times on "Build" until you got a message that you are a developer. Head back into android settings and and at the bottom you have "Developer options".

popy2k14 commented 4 years ago

PS.: i dont have Alexa in play store on my device!?

busshi commented 4 years ago

Ok thanks same trick like a phone...

Alexa is a new feature since a month or two. When I bought the TV a year ago, I saw this app but it was not available in France, just in a few countries. Maybe it is not available in yours or maybe your TV is not compatible !?!

busshi commented 4 years ago

So I just pair again my TV and Alexa while snifing trafics with your filters. I dont’ really understand packets... I only found something when I ask Alexa to turn TV on is that the location is http://IP:49153/nmrDescription.xml... maybe we have something to try with this port ?

When I curl this url I just have informations about TV...

popy2k14 commented 4 years ago

Nice find but just to be sure. Can you please retry the exact same and look if the destination is the same port 49153? If its not we are out of luck and thats an active connect from your tv to an echo. TCP Ports normally change on every connect -> thats why we should retry the same thing.

busshi commented 4 years ago

Just did ! Same location and port : 49153

Another information : there is service NTS : ssdp:byebye (when I turn off) ssdp:alive (when I turn on)

popy2k14 commented 4 years ago

Wow, thats really interesting. Seems alexa is controlling the tv over this 49153 port. I have also found the alexa app on my tv, it was just under the home - apps menu :-) Paired it to alexa and it also asked me regarding deep standby, which i have turned off now.

Running an ping test now... PS.: Did you tried this? Will the wired interface stayed online? DOes the philips api work longer than 1-2 hours?

I know you did not want to have alexa app running on the tv and communicating with Big A and G, but i think there is some service running when alexa is active which opens this 49153 port and waiting for commands.

Maybe we should login on the tv set and deactivate the philips skill on alexa to leave this service running and maybe use it?

busshi commented 4 years ago

Nope I didn’t try to ping because I am pretty sure it will always works (because it is an official feature). I tried to wake up with Alexa on the morning, it works (I had shut down the evening before)... If you disable the Alexa skill it will not work anymore. If you go on the TV in the Alexa app it ask you to activate again.

popy2k14 commented 4 years ago

Thats sad that they must be paired. Maybe pair it and block traffic from tv <> internet and so keep the service/tv alive?

popy2k14 commented 4 years ago

Or this way:

busshi commented 4 years ago

I cannot do that because all my applications need internet access. I don’t have any box or decoder plugged in the TV.

popy2k14 commented 4 years ago

i dont mean block all traffic, just block alexa traffic to prevent unpairing... but sadly i dont know which ports are used.

PS.: tv set is reachable with ping & philips api is accessable (with pylips) after over an hour :-) so activating alexa did the trick!

Sure just an option to deactivate deep standby would be nice!

busshi commented 4 years ago

Yes I looked into the developper menu but I didn’t find something useful... I am gonna look for the hidden service menu into the TV... I found a lot of combinaisons to go in it but it is not working (I have the original remote)...

busshi commented 4 years ago

So today after a dozen hours, the TV powerstate was still in Standby mode... I will see if it is still working in a few days... To get this, I paired Alexa and TV in the TV app and in the Alexa skill. Then I just deactivate the skill in Alexa app. It seems to leave the TV in standby...

popy2k14 commented 4 years ago

That sounds very promising!!!! Thanks a lot for this finding.

Also in my case the tv is reachable in standby today with phylips after activating the alexa skill yesterday. Because i want to use the skill i will leave it on.

@eslavnov can you please add a note to the readme that on android tvs to get a stable pylips (jointspace) interaction also in standby, you have to activate & pair alexa to the tv set. When you dont need alexa functionality just deactivate the skill afterwards in the alexa smartphone app. Otherwise leave it on.

With this changes i am able to control 2x tv sets with pylips (command standby and so on) after half a day. Also @busshi is able to control it after a few hours.

Credits goes to @busshi

eslavnov commented 4 years ago

Thanks guys for the information, this is very helpful! I'll have to do some additional research because I don't have Alexa on my TV but I am still able to wake from deep sleep... I'll have to investigate what's going on... But as a workaround this is really nice, thank you again, guys!

popy2k14 commented 4 years ago

@eslavnov On our sets we have tried everything and when the TV is in standby the ethernet interface and wifi is switched off after while.

Which TV set do you have?

Anyway, using this workaround now and finally can get rid of my IR blasters and RPIs.