Philips Android TV component

i thought these packages were installed via the Philips App gallery… But i thought also some packages were installed with the google play store.

1 Like

I think there is a difference in approche… you Will set the self._tv.on with an True or False.
In the stateC version there is a value: ON, or OFF.

When your television is off, but there is still networkactivity in the TV, the self._tv.on is set to TRUE (as it gets a response with the value OFF in your version)

When the television is turned off for a longer period… also the network stops responding. Then the self._tv.on will be FALSE (as it is the default value in the init section).

EDIT: TESTED IT AGAIN with your latest version
Television is off.
Turn it on with HA.
It is turning on… state from unknown to IDLE
then… turn off television: STATE is still IDLE.
HA keeps television in IDLE status. I can’t turn my television on again… .because it is already on with HA

I think it is a matter of taste what to do here. We have 3 situations:

Offline
Online but Off
Online and On

I currently use in the first two scenario’s off. In the current version it is using idle in the second off in the first and I think nstrelow wants to indicate On with a playing state if i am not mistaken?

This explains it, thx

I see, yeah that’s true, and it’s on my Todo list (@JSON_v62 code already handled it properly, I just didn’t see the problem when I changed it)

Will think about handling that state today and hopefully publish another version later today

Oh and a quick fix for turning on the TV when in Standby but the component reports idle:

Just press the play button :stuck_out_tongue: because sending any key when it is in the screen-off-but-online state turns it on

So with the new version i still got this failure

Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py”, line 221, in async_update_ha_state
await self.async_device_update()
File “/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py”, line 349, in async_device_update
await self.hass.async_add_job(self.update)
File “/usr/local/lib/python3.6/concurrent/futures/thread.py”, line 56, in run
result = self.fn(*self.args, **self.kwargs)
File “/usr/local/lib/python3.6/site-packages/homeassistant/util/init.py”, line 324, in wrapper
result = method(*args, **kwargs)
File “/config/custom_components/media_player/philips_2016.py”, line 225, in update
self._tv.update()
File “/config/custom_components/media_player/philips_2016.py”, line 305, in update
self.getChannelList()
File “/config/custom_components/media_player/philips_2016.py”, line 343, in getChannelList
r = self._getReq(‘channeldb/tv/channelLists/all’)
File “/config/custom_components/media_player/philips_2016.py”, line 279, in _getReq
return json.loads(resp.text)
File “/usr/local/lib/python3.6/json/init.py”, line 354, in loads
return _default_decoder.decode(s)
File “/usr/local/lib/python3.6/json/decoder.py”, line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File “/usr/local/lib/python3.6/json/decoder.py”, line 357, in raw_decode
raise JSONDecodeError(“Expecting value”, s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

1 Like

Hi I’m new to the party and i like to try and connect my philips 49pus850312 to hass.io with home assistent 0.81.0. In this thread Philips.py was mentioned to start the pairing process. So far i have tried to do this directly from the ssh console :
core-ssh:~# python3 /config/philips.py --host 192.168.0.6 pair
core-ssh:~# /config/philips.py --host 192.168.0.6 pair

also tried to create a switch to start the script from the interface.
s = “Python syntax highlighting”
switch:
platform: command_line
switches:
pair_philips_tv:
command_on: python3 /config/python_scripts/philips.py --host 192.168.0.6 pair
command_off: python3 /config/python_scripts/philips.py --host 192.168.0.6 pair

All attempts have failed. i even installed python on windows with some dependent modules. there i get stuck on No module named ‘Crypto’.

Help is welcome

The script needs to be executed only once to get a username and password combo.

When executing it, you should be greeted with “Starting pairing request. Enter onscreen passcode”, where you have to enter the PIN then displayed on your TV screen. And have the Android TV Launcher open to be sure.
After entering the PIN you get a username/password combo you can use for all other requests.

The original repo with the script: https://github.com/suborb/philips_android_tv

The device you execute this script from doesn’t matter. To make it work you have to install the needed packages. This is done by going into the directory of the repo and doing pip install -r requirements.txt. Should also work on windows. Have fun

Hmmm, I cannot see why this shouldn’t work. Try repairing it and specifying a new user/password in the config.

Somehow the TV is returning something other than JSON (probably HTML). This can be the case when the command channeldb/tv/channelLists/all is not know by the TV or the authentication fails, in which case pairing again might fix it.

Hi, thanks for the responce. I was aware i only have to pair once and i was using the py file in the repo like you suggested. The pip install -r requirements.txt was new for me. but it seems it is also new for hassio. I got the error :
-bash: pip: command not found

So went over to my windows box again and tried it there. Result:
Command “c:\users\user\appdata\local\programs\python\python37-32\python.exe -u -c “import setuptools, tokenize;file=‘C:\Users\martin\AppData\Local\Temp\pip-install-hvoop69i\pycrypto\setup.py’;f=getattr(tokenize, ‘open’, open)(file);code=f.read().replace(’\r\n’, ‘\n’);f.close();exec(compile(code, file, ‘exec’))” install --record C:\Users\martin\AppData\Local\Temp\pip-record-l59pts7l\install-record.txt --single-version-externally-managed --compile” failed with error code 1 in C:\Users\user\AppData\Local\Temp\pip-install-hvoop69i\pycrypto\

am i doing something that is not allowed on hassio and only allowed on hassbian? The windows part was a last resort. I hope to do everything with the Pi.

Windows requires Microsoft Visual C++ Build Tools to be installed, which is a hassle. You could also try using Ubuntu on Windows Subsystem for Linux.

I don’t know your setup. If you have HassOS, it may be more difficult to install python correctly.
In my homeassistant docker container pip and python3 -m pip are working.

So go and figure out how to use install the requirements using pip, either on windows or your PI. You will figure it out I am sure of it :wink:

does anyone know how to fireup a http get command using the commandline in HA.
trying to get the powerstate with
requests.get(“https://ipaddress:1926/6/powerstate”)… but get error about x server …

I tried repairing but had no luck with it my tv modelnumber is: 40PFK6580/12

As far as I could find out, your model is from 2015. You might have more luck using the official Philips TV component or something else as this component is for 2016+ models.

I think this: Philips TV - Home Assistant
Probably with api version 5, but really it’s for you to find out :wink:

New Version
Repo: https://github.com/nstrelow/ha_philips_2016
(Pro tip: You could build a script to git pull the newest changes)


(Play Movies and TV is my only TV channel :see_no_evil:)

  • Fixed on state: Now the TV is only shown as on when the screen is on (powerstate is on).
  • Now both channels and apps are switchable on source select
  • Better handling of launching System Apps, launching Settings shortcuts now works

Notes: When sending WakeOnLAN to the Wifi Mac of the TV the API is powered on. At that state (saved in the variable api_online) the TV can be talked to via the API. This could enable directly launching an App, because the TV starts when POST request is received. I have no good idea on how this could be used yet, suggestions welcome.

To make clear if it is an app or a TV channel you are choosing I am using the icons :iphone: for apps and :tv: for TV channels. This gives a clear overview, but also distinguishes between e.g. the Play Movies app and channel.

It is possible to create automations using the media_player.select_source service. When using this to launch an app or channel, be sure to include the icon (:iphone: or :tv:), a space and then the name of the app, as shown in the source list.
Example for YouTube:

{
  "entity_id": "media_player.tv",
  "source":"📱 YouTube"
}

Hope you all have unicode emoji support :man_technologist:

I installed the latest version. I have a philips POS9002 and i get this error once in 10sec:

2018-11-01 16:47:12 ERROR (MainThread) [homeassistant.helpers.entity] Update for media_player.philips_tv fails
Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py”, line 221, in async_update_ha_state
await self.async_device_update()
File “/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py”, line 349, in async_device_update
await self.hass.async_add_executor_job(self.update)
File “/usr/local/lib/python3.6/concurrent/futures/thread.py”, line 56, in run
result = self.fn(*self.args, **self.kwargs)
File “/usr/local/lib/python3.6/site-packages/homeassistant/util/init.py”, line 324, in wrapper
result = method(*args, **kwargs)
File “/config/custom_components/media_player/philips_2016.py”, line 229, in update
self._source_list = self._tv.app_source_list + self._tv.channel_source_list
TypeError: unsupported operand type(s) for +: ‘NoneType’ and ‘NoneType’

Okay, bad error handling from my side there. Uploaded a new version, which should not throw an error if there are no apps and channels: https://github.com/nstrelow/ha_philips_2016/blob/master/philips_2016.py

More concerning is the part that both /channeldb/tv/channelLists/all and /applications is not working for you.
Does the 2017 model have a new api, which does not support these commands? You can try the commands yourself and report back.

Interesting for me would be what API version you have:
Could you execute the /system command and post your results?

curl -X GET --digest --insecure -u user:password https://<ip address>:1926/6/system

And remove the serialnumbers and device ids, just to be safe :wink:

{
    "notifyChange": "http",
    "menulanguage": "English",
    "name": "43PUS6401/12",
[...]
    "nettvversion": "8.1.0",
    "epgsource": "one",
    "api_version": {
        "Major": 6,
        "Minor": 2,
        "Patch": 0
    },
    "featuring": {
        "jsonfeatures": {
            "editfavorites": [
                "TVChannels",
                "SatChannels"
            ],
            "recordings": [
                "List",
                "Schedule",
                "Manage"
            ],
            "ambilight": [
                "LoungeLight",
                "Hue",
                "Ambilight"
            ],
            "menuitems": [
                "Setup_Menu"
            ],
            "textentry": [
                "context_based",
                "initial_string_available",
                "editor_info_available"
            ],
            "applications": [
                "TV_Apps",
                "TV_Games",
                "TV_Settings"
            ],
            "pointer": [
                "not_available"
            ],
            "inputkey": [
                "key"
            ],
            "activities": [
                "intent"
            ],
            "channels": [
                "preset_string"
            ],
            "mappings": [
                "server_mapping"
            ]
        },
        "systemfeatures": {
            "tvtype": "consumer",
            "content": [
                "dmr",
                "dms_tad"
            ],
            "tvsearch": "intent",
            "pairing_type": "digest_auth_pairing",
            "secured_transport": "true"
        }
    }
}

I will add the new version and try the commands in few hours. Meanwhile here is the response from the /system call

{
"notifyChange": "http",
"menulanguage": "English",
"name": "Living room TV",
"country": "Romania",
"serialnumber_encrypted": "...",
"model_encrypted": "AR/NnwD3PqegI6MODoohu2+XxlVqMYiSkTo4xUXyOO4=\n",
"deviceid_encrypted": "...",
"nettvversion": "",
"epgsource": "one",
"api_version": {
    "Major": 6,
    "Minor": 1,
    "Patch": 0
},
"featuring": {
    "jsonfeatures": {
        "editfavorites": [
            "TVChannels",
            "SatChannels"
        ],
        "recordings": [
            "List",
            "Schedule",
            "Manage"
        ],
        "ambilight": [
            "LoungeLight",
            "Hue",
            "Ambilight"
        ],
        "menuitems": [
            "Setup_Menu"
        ],
        "textentry": [
            "context_based",
            "initial_string_available",
            "editor_info_available"
        ],
        "applications": [
            "TV_Apps",
            "TV_Games",
            "TV_Settings"
        ],
        "pointer": [
            "not_available"
        ],
        "inputkey": [
            "key"
        ],
        "activities": [
            "intent"
        ],
        "channels": [
            "preset_string"
        ],
        "mappings": [
            "server_mapping"
        ]
    },
    "systemfeatures": {
        "tvtype": "consumer",
        "content": [
            "dmr",
            "pvr"
        ],
        "tvsearch": "intent",
        "pairing_type": "digest_auth_pairing",
        "secured_transport": "true",
        "companion_screen": "true"
    }
}

}

Thanks, i got rid of HASSOS and i installed hassbian. Now i wass able to pair my tv. I picked up the latest file from github. One hour old, so thans for being so active on this subject. It shows up now in the main view. I’m unable to controll the TV.
image

The logfile shows the following errors. Is there still a pairing issue?

Update for media_player.tv fails
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py”, line 221, in async_update_ha_state
await self.async_device_update()
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py”, line 349, in async_device_update
await self.hass.async_add_executor_job(self.update)
File “/usr/lib/python3.5/asyncio/futures.py”, line 380, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.5/asyncio/tasks.py”, line 304, in _wakeup
future.result()
File “/usr/lib/python3.5/asyncio/futures.py”, line 293, in result
raise self._exception
File “/usr/lib/python3.5/concurrent/futures/thread.py”, line 55, in run
result = self.fn(*self.args, **self.kwargs)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/util/init.py”, line 324, in wrapper
result = method(*args, **kwargs)
File “/home/homeassistant/.homeassistant/custom_components/media_player/philips_2016.py”, line 226, in update
self._tv.update()
File “/home/homeassistant/.homeassistant/custom_components/media_player/philips_2016.py”, line 303, in update
self.getState()
File “/home/homeassistant/.homeassistant/custom_components/media_player/philips_2016.py”, line 373, in getState
r = self._getReq(‘powerstate’)
File “/home/homeassistant/.homeassistant/custom_components/media_player/philips_2016.py”, line 280, in _getReq
return json.loads(resp.text)
File “/usr/lib/python3.5/json/init.py”, line 319, in loads
return _default_decoder.decode(s)
File “/usr/lib/python3.5/json/decoder.py”, line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File “/usr/lib/python3.5/json/decoder.py”, line 357, in raw_decode
raise JSONDecodeError(“Expecting value”, s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Thank for the work on this.

wow great work… still the on/off is not working completely correctly… but …really thank you sooo much.

Ik tried to make a script:

SBS6:
alias: SBS6
sequence:
- service: media_player.turn_on
data:
entity_id:media_player.philips_tv
- service: media_player.select_source
data:
entity_id: media_player.philips_tv
source: SBS6

But this isn’t working. Looks like de select source is not working?
do you know what is going wrong ?