Philips Android TV component

He nstrelow,

yes, when the TV is off, also no network activity, it takes some time… or indeed I need to press the power on button a couple of times.

About the automation:
I already tried to use the picto.
As pictograms are not allowed (something to do with special chars)in the configuration.yaml this isn’t working for me… Do you know any workarround for this ?

Ahahahhaha, damn I knew it would make problems.
But I feel like it is the cleanest way to show if app/channel in the UI.

I will probably introduce a way by either source: "app:Xxx" or with an additional field.

Thanks for reporting :wink:

Well this makes perfect sense.
Also with the dimming, I think I saw an example with Kodi.
Most people want to dimm, only when they start playing something. Meaning if you are actually in the PLAY or PAUSE state, the lights will be dimmed. I find that a very neat and awesome automation.
Sadly with the Philips TV we have no way yet to check whether it is playing something.

And Universal Player defines ON as “something is being played on the media_player”
Edit: Or as STATE_ON, which is very weird. Probably because most players start with ON → Play → Idle, meaning you stopped watching your movie at Idle.

So we are kinda outta luck here.
Can you show me your basic universal player config? I will test that out and maybe also configure it for me. Maybe I’ll find a config solution or we then have the same problem. :man_shrugging:

something else noticed: when the TV is off… my log file is filled with:

File “/usr/src/app/homeassistant/helpers/entity.py”, line 221, in async_update_ha_state
await self.async_device_update()
File “/usr/src/app/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/src/app/homeassistant/util/init.py”, line 324, in wrapper
result = method(*args, **kwargs)
File “/config/custom_components/media_player/philips_2016.py”, line 230, in update
self._source = self._tv.app_name + ’ ’ + self._tv.channel_name
TypeError: unsupported operand type(s) for +: ‘NoneType’ and ‘str’

Great, will tix

Ahh found something else… when TV is off… en no network… after restart Home assistant initial state is unknown… :wink: It is not changed to OFF :wink:

This might be true but my TV uses the API 6 here is the response from the /system call

{
"menulanguage": "German",
"name": "PhilipsTv",
"country": "Germany",
"serialnumber_encrypted": "",
"softwareversion_encrypted": "yPB1qeUECbsuB+PRHj2iJzD8JK0LEgs4XiGS\/GNzC2g=\n",
"model_encrypted": "ja4z\/OA4AimVFEMrsYExqauFfdPFobuItY1bjHAe45s=\n",
"deviceid_encrypted": "",
"nettvversion": "6.0.0",
"epgsource": "one",
"api_version": {
	"Major": 6,
	"Minor": 1,
	"Patch": 1
},
"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"]
	},
	"systemfeatures": {
		"tvtype": "consumer",
		"content": ["dmr", "dms_tad"],
		"tvsearch": "intent",
		"pairing_type": "digest_auth_pairing",
		"secured_transport": "true"
	}
}

}

Here is my configuration of Universal Player:

media_player:
  - platform: universal
    name: TV
    children:
      - media_player.55pos900212
      - media_player.kodi
      - media_player.philips_tv
    commands:
      turn_on:
        service: switch.turn_on
        data:
          entity_id: switch.tv_on
      turn_off:
        service: media_player.turn_off
        data:
          entity_id: media_player.philips_tv
      volume_up:
        service: media_player.volume_up
        data:
          entity_id: media_player.philips_tv
      volume_down:
        service: media_player.volume_down
        data:
          entity_id: media_player.philips_tv
      volume_mute:
        service: media_player.volume_mute
        data:
          entity_id: media_player.philips_tv
          is_volume_muted: true
      volume_unmute:
        service: media_player.volume_mute
        data:
          entity_id: media_player.philips_tv
          is_volume_muted: true
      volume_set:
        service: media_player.volume_set
        data:
          entity_id: media_player.philips_tv
          volume_level: media_player.philips_tv|volume_level
    attributes:
      is_volume_muted: media_player.philips_tv|is_volume_muted
      volume_level: media_player.philips_tv|volume_level

Using it, I can actually check whether it is playing something on TV via Kodi (installed on the TV) or through cast and make my automation of lights. All these sources are shown in one player in frontend. Therefore, it is crucial to have a power state reported correctly. There is nothing odd how Universal player defines ON since Idle reserved only for those players which are always ON. This, however, cannot be the case for tv.

@nstrelow: I guess i have version 6.1 The paring user and password that was returned was just copied and pasted. I tried the pairing again today and the pairing shows error_is success: Pairing completed. with a user and a password. But still HA is unable to communicate wit the TV.

This was returned by the get command:

“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”}}}pi@hassbian:~ $ ^C

Are there further steps i can take to solve this issue?

@nstrelow: Thanks for helping me out. I now am able to communicate with the tv. Previously the tv was autodiscovered and i think that was blocking my connection from the custom component. The discovery was turned off, but the discovered component was still in HA (but not visible due to my group and view settings). So now i removed the discovered device in the configuration page and after the reboot it is working.
image

again thanks for the help. now i will try to make automations that turn on receiver, tv, correct source etc.

Hmm, I do not think I can help you in any way. You can just try different curl commands and API path from the jointspace website. Maybe something else is working then. Or try resetting stuff?

You could also try the newest version, which is a more stable, but nothing related to your problem :confused:

I don’t like it, you even have the same API version as @mtol20.

I still think something has to be wrong with the pairing. Some wrong character or some pasting issue.

Great, you got it working !!!

Fix was uploaded

Also fixed

I could not reproduce it for myself, but I am trusting you and adding a special case.

Now when the the packageName is ‘NA’. it will try accessing channel information from /activities/tv and use that info.
If there is no info, then N/A - N/A is displayed, but it is still marked as channel.

I see, yeah you are right. The default of the universal player has Idle as off state.
Using a state_template you could try to make it work with philips_tv being idle
Here is the example: Universal media player - Home Assistant

Additionally I have added that the state is only idle, when an App is running. If you have Kodi running as app on the TV, this won’t help you. But it’s a start.

Feel free to change my code btw, you can just replace IDLE by ON

Now I have. You can use the built-in script editor. Just go to Configuration->Scripts and add everything there.
If you do not want to do that you can use the escaped character:
:iphone: = \U0001F4F1
:tv: = \U0001F4FA

Example for YouTube in scripts.yaml:

'1541344661958':
  alias: Start YouTube
  sequence:
  - data:
      entity_id: media_player.tv
      source: "\U0001F4F1 YouTube"
    service: media_player.select_source

Made more changes, mostly bugfixes
You can see all changes here: https://github.com/nstrelow/ha_philips_2016/commits/master
Download: https://github.com/nstrelow/ha_philips_2016/blob/master/philips_2016.py

Have fun :smiley:

I tried the template before but it didn’t work, now I figured out the reason. As for Kodi as an app, I didn’t understand what you mean since I use Kodi media player as a separate component included as a child player in Universal Player. I also don’t have a “normal” tv channels, it goes via tv-box from my provider, so only apps run on my TV.
I, of course, can change your code. It seems to me that it’s better to do everything right from the beginning :wink:

I can’t reproduce the “NA” behaviour anymore. Now i get
{
“component”: {
“packageName”: “org.droidtv.playtv”,
“className”: “org.droidtv.playtv.PlayTvActivity”
}
}

Also i saw that you updated the code to force the state to off after turning off. I saw in other components that they are forcing an update instead of setting state to something that may be wrong. I think it’s a bit more safe like this.