eslavnov / pylips

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

Remote power on TV #52

Closed neophob closed 3 years ago

neophob commented 4 years ago

We can control the TV, we can power off the TV but afaik no option today to power the TV on.

Goal here is to find out a way to power on the TV from the network. Here's my summary:

Discovered open port 49153/tcp on 192.168.178.94  << Linux2.6/0.0 UPnP/1.0 PhilipsIntelSDK/1.4 DLNADOC/1.50
Discovered open port 8443/tcp on 192.168.178.94   << HTTPS service, curl request returns empty reply, cert: issuer: C=US; ST=Washington; L=Kirkland; O=Google Inc; OU=Widevine; CN=TPVision TV PH9M_EA_5599 Mediatek MT5599 Cast ICA
Discovered open port 9000/tcp on 192.168.178.94   << unknown
Discovered open port 8009/tcp on 192.168.178.94   << HTTPS service (self signed certificate)
Discovered open port 8008/tcp on 192.168.178.94   << HTTP service, returns 404

so we have different options here to power the TV on:

someone knows more about those ports?

neophob commented 4 years ago

Ok found a solution, I use curl -v http://__IP__:8008/apps/ChromeCast -X POST to power on the TV

eslavnov commented 4 years ago

Hey @neophob, thank you for reporting your solution! Reliably turning the TV's power 'on' has been on my to-do list for quite some time!

I'll test your solution once I am back from my Christmas vacation and if everything is fine, I'll add a custom command to Pylips so that the other can also use it!

Thank you again!

neophob commented 4 years ago

Hi @eslavnov

while the command turns on the TV it looks like the Philips API is not started (port 1925 and 1926) - at least on my TV (58PUS7304).

Would like to know what other observe!

neophob commented 4 years ago

Ok I guess I found a reliable solution, there is an advanced config option with nodeid 2131230736:

curl -k -s --digest --user "<snip>" -X POST "https://__TVIP__:1926/6/menuitems/settings/current" -d '{"nodes":[{"nodeid":2131230736}]}' | jq .
{
  "values": [
    {
      "value": {
        "Nodeid": 2131230736,
        "Controllable": true,
        "Available": true,
        "string_id": "Einschalten mit Chromecast",
        "data": {
          "selected_item": 0,
          "enum_values": [
            {
              "enum_id": 0,
              "controllable": true,
              "available": true,
              "string_id": "org.droidtv.ui.strings.R.string.MAIN_OFF"
            },
            {
              "enum_id": 1,
              "controllable": true,
              "available": true,
              "string_id": "org.droidtv.ui.strings.R.string.MAIN_ON"
            }
          ]
        }
      }
    }
  ],
  "version": 0
}

update this value to ON:

curl -k -s --digest --user "<snpi>" -X POST "https://__TVIP__:1926/6/menuitems/settings/update" -d '{"values":[{"value":{"Nodeid":2131230736, "data": {"selected_item":1}}}]}'

now the TV should power on when chromecast is started. let me know if this works!

eslavnov commented 4 years ago

Added power_on command based on @neophob approach, thank you! Works great so far for me!

busshi commented 4 years ago

I am wondering how you can access the TV’s IP if network interfaces are down due to deep sleep ? In my case this command work great if TV in standby mode but it doesn’t if deep sleep : 404 non reachable... I tried with Alex built-in app and it works perfectly to turn on instantly.

Nastras commented 4 years ago

@eslavnov I have a question and it's that switching on does not work with your script and the Chromecast option on my TV. I have created a debug file with

--command get --path 'menuitems/settings/structure' --verbose True > settings_dump.txt

and I've been reading these figures out. Can you tell me if it should work with your script?

{"node_id":2131230736,"string_id":"org.droidtv.ui.strings.R.string.MAIN_SWITCH_ON_WITH_CHROMECAST","context":"switch_on_with_network","data":{"enums":[{"enum_id":0,"string_id":"org.droidtv.ui.strings.R.string.MAIN_OFF"},{"enum_id":1,"string_id":"org.droidtv.ui.strings.R.string.MAIN_ON"}]},"type":"LIST_NODE"},

The Chromecast option is enabled on the TV.

Thanks a lot!

eslavnov commented 4 years ago

@Nastras,

Power on seems to be behaving strangely for some users, see details here. I am investigating it, hopefully I'll come up with a fix soon.

AcuarioCat commented 4 years ago

I'm trying to figure this for my tv - 65PUS6703 When in standby there is no response to a ping but the Philips remote app can turn it back on. It tries to open a connection to port 2870 (sometimes twice) then sends a "Standby" json to port 1925. In between the tv appears to wake up and starts responding to pings again.

By the way, this version of the tv has Linux and API 6 as its OS and not Android

fniwes commented 4 years ago

I have a Philips 50PUD6654/77 he only way to turn the tv on is using wakeonlan, just that.

But to use wakeonlan you need to know the mac address of the tv. also, i did not try it but this model supports WoWLAN so, should works on wireless too.

@eslavnov May I help you somehow to implement this functionality in the script?

eslavnov commented 4 years ago

@fniwes WoL works really shitty on Philips TVs - it's super-slow and not very reliable, so Pylips won't support this.

eslavnov commented 4 years ago

Latest state of things: For Chromecast-enabled models, using the built-in power_on command is the best option. It might require running allow_power_on first, reinstalling chromecast and/or activating Alexa, although for me it worked without any of these steps.

I am not sure if non-Android TVs support Chromecast, so I have no idea if this works for such models. I also don't know of a reliable enough alternative to turn the TV on from deep sleep without the Chromecast hack, unfortunately.

If power_on does not work for you, please try all the steps above (allow_power_on, etc). If it still does not work, please leave a comment with a result of http://tv_ip:1925/6/system or http://tv_ip:1926/6/system attached. Thank you!

lucasvdh commented 3 years ago

FYI

@eslavnov none of the solutions mentioned above worked for me but I have found that does work (for models running Android).

The solution was installing the Wakelock Revamp app and enabling the "Processor" option. It's not available as an Android TV app so you'd need to install the mobile version from USB or via adb.

Once Wakelock is installed it:

I suspect the Alexa app does something similar, but not quite the same as that didn't work for me. I'm going suggest the Wakelock app as the main solution to this issue on my Homey app.

popy2k14 commented 3 years ago

@lucasvdh Thanks for this nice workaround. A while ago i had Alexa activated, which also deactivated the deep sleep of the TV sets (as mentioned). Sadly, back then, i had an issue that after some days my Denon AVR sound drops out frequently. A reboot solved issue always. Because of that issue, i deactivated Alexa -> activate deep sleep, which also do some "reboot" in the night. This solved the sound issue fro me. Also i installed my IR blasters to switch the TVs on from my smarthome.

Since then a few updates of the TV sets has arrived and now i am testing this workaround...

Just want to say thanks for this, because i dont have to activate Alexa!

TheAndi commented 3 days ago

Did not want to use apps/ChromeCast because it forces me on the App page.

I use this (in Powershell):

python .\pylips-master\pylips.py --command post --path powerstate --body '{"""powerstate""":"""On"""}' python .\pylips-master\pylips.py --command post --path powerstate --body '{"""powerstate""":"""Standby"""}'

Hope it helps someone or might get implemented ;)