Philips Android TV component


#41

Thanks to @an20dei the state (on/off) works correctly with my 55POS9002 when I use the component to control my TV. Though, I noticed that if I turn off my TV with the remote control, then the component shows status as unknown and it is impossible to turn on the TV again with the component. Have anyone else noticed the same behaviour?


#42

Maybe this is of interest for some of you:
The current implementation for Philips TVs was hardcoded to use the old API. This will become customizable with the next Home Assistant release. So maybe it might make sense to let the progress you guys are making here flow into the module: https://github.com/danielperna84/ha-philipsjs
Additionally I want to ask if someone would like to become the new maintainer of the module since I don’t own any Philips TVs anymore. Hence I’m probably not the best option to have control of the module.


#43

Hey,

thanks for sharing! I was able to connect to my PUS7101/12 w/o problems. This is what I experienced:

  • @Molodax Off-State is displayed correctly for me, independent of how the TV was turned off.
  • switching on does not work reliable. I have my TV connected via Wifi to my network and activated Wake On Wifi, anyway I can see that when off the TV only connects to my network from time to time. Will try if it works with a cable connection.
  • I cannot set the volume using the input slider in the UI, but the state is received.
  • The service media_player.volume_mute does not work from the developer tools, but the mute button of the UI does work.

Is anyone else observing the same behavior?

I’m still quite new to HA and even more to Pi’s, so this might be a noob question:
How can I call a function defined in the custom component (e.g. sendkey) from an automation or switch?
I would like to try adding some functions (especially basic ambilight control) to the component and have a working (proof-of-concept) py-script for that, but struggle on calling it from HA (Hassbian).


#44

I had the same problem (cannot turn of TV after a while because it gets disconnected from the network) and this is how i fixed it:

  1. You need to have an IR blaster in the same room, otherwise it will not work (i have a Broadlink RM3 Pro)

  2. Create media_player entite as written above, but insert it as a child in an universal media_player. This is my yaml configuration:

customize:
  media_player.phtv:
    hidden: true
  
media_player:
  - platform: philips_2016
    name: phTV
    host: 192.x.x.x
    username: yourusername
    password: yourpassword

  - platform: universal
    name: Philips TV
    children:
      - media_player.phTV
        commands:
        turn_on:
          service: switch.turn_on
          data:
            entity_id: switch.phtvir
switch:
  - platform: broadlink
    host: 192.x.x.x
    mac: 'your:mac'
    timeout: 15

      switches:
        phtvir:
          friendly_name: "Philips TV IR"
          command_on: 'JgAcABweHR07HhweHR0dHhw8HR0dHhweHB4dHhwADQUAAAAAAAAAAAAAAAA='
          command_off: 'JgAaAB0dOx4cHhweHR4cHhw8HR0dHhweOzsdAA0FAAAAAAAAAAAAAAAAAAA='

Using these settings i can fully control my TV remotely (even if it is off and it is out of the network, switching it on using the IR Blaster will turn on the TV and all the media functions will be available after)

Hope it helps :slight_smile:

PS: i have a 55PUS6482 Philips TV


#45

And for you last question:

How can I call a function defined in the custom component (e.g. sendkey) from an automation or switch?
I would like to try adding some functions (especially basic ambilight control) to the component and have a working (proof-of-concept) py-script for that, but struggle on calling it from HA (Hassbian).

You can call the Philips API using CURL commands, for example, this is how i call the Home button (the one that opens Android App menu)
PS: Off command is dummy because i don’t need it but it is required

switch:
  - platform: command_line
    switches:
      philips_home:
        command_on: "curl -X POST --digest --insecure -u philips_tv_username:philips_tv_password https://192.x.x.x:1926/6/input/key -d '{key:Home}'"
        command_off: "curl -X POST --digest http://192.x.x.x:1926/6/input/key -d '{none:none}'" 

You can find other Key values available in this post: Philips Android TV component

Good luck :slight_smile:


#46

@Molodax - check this solution (it works only if you have an IR Blaster): Philips Android TV component


#47

Thanks @an20dei! Not exactly what I was looking for, but this helps me a lot anyway :slight_smile:

Using 192.x.x.x:1926/6/input/key with {key:AmbilightOnOff} just opens the Ambilight Menu on my TV.
I now use this to directly turn on and off my ambilight:

switch:
  - platform: command_line
    switches:
      philips_ambilight:
        command_on: curl -X POST --digest --insecure -u user:password "https://192.x.x.x:1926/ambilight/currentconfiguration" -d '{"styleName":"FOLLOW_VIDEO","isExpert":"false","menuSetting":"STANDARD"}'
        command_off: curl -X POST --digest --insecure -u user:password "https://192.x.x.x:1926/ambilight/power" -d '{"power":"Off"}'

Did anyone find out how to directly turn on/off “Ambilight + Hue” via API? Since it is possible with the Philips App, there should be way to do it…


#48

Is it possible to add another attribute to the custom component? I would like have the Ambilight State as an attribute so I can use it to retrieve the correct state for my Ambilight Switch.

I was able to exchange another attribute (e.g. channel) with the ambilight state, but couldn’t make it to add it as a new attribute.


#49

@DaveHA, try to create a sensor using this method (tried it and it works, it returns the ambilight state(off or on) ):

   - platform: command_line
     command: 'curl -X  GET --digest --insecure -u user:pass https://192.x.x.x:1926/6/ambilight/power'
     name: Ambilight
     value_template: '{{ value_json.power }}'

Then you can create an automation (if this sensor is on, turn on Hue, if off, turn off or whatever you want)

Good luck :slight_smile:


#50

and i also think that you can use the last curl as a state command for your switch… search on the forum eventually how to do it, i think it can be made and in this case there is no need for sensor+automation


#51

From this morning I have started to get this error in the component.
Yesterday evening it was working correctly. Any ideas?

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 222, in async_update_ha_state
    attr = self.state_attributes or {}
  File "/usr/lib/python3.6/site-packages/homeassistant/components/media_player/__init__.py", line 884, in state_attributes
    in ATTR_TO_PROPERTY if getattr(self, attr) is not None
  File "/usr/lib/python3.6/site-packages/homeassistant/components/media_player/__init__.py", line 884, in <dictcomp>
    in ATTR_TO_PROPERTY if getattr(self, attr) is not None
  File "/config/custom_components/media_player/philips_2016.py", line 101, in volume_level
    return self._volume / self._max_volume
TypeError: unsupported operand type(s) for /: 'NoneType' and 'NoneType'

#52

Thanks, the sensor solution with curl works :slight_smile: It’s just quite slow with the updates compared to the 5 sec. of the custom component.

I guess someday I have to dig into the custom component development to see what’s possible.


#53

I can see the same error in my log, but the component still works for me.


#54

Seems that the tv goes offline from time to time and the component begins to flood the log with errors.
After turning on the tv it returned to be silent in logs.


#55

Hi everyone!

Can Soneone help me? I used the script to pair tv, set the component in the right folder and set it in configuration.yaml.
The result? Home Assistant give me an Invalid Config tab in home. What could be? Ty!


#56

Hi all,

I have 55POS9002/12.
I’m running HASSIO on a RPi 3.

Through Putty, I could not find the folder mentioned above:

Nevertheless, I created it and put the script inside.
When trying to run it, it says python is not a command.

What do I need to do to be able to pair the TV?

I also tried the component available in Hassio, but it just says the state of the TV is Unknown.
Through Hassio discovery, and because I have a Google Home and the TV linked to it, I see a media_player for the TV, but only works if the TV is running Youtube or any other Android TV app.

What am I doing wrong?
I’m sorry, maybe I’m just being dumb, but my skills in linux and python and etc. are fairly (to be kind to myself) limited…

Thank you.


#57

Hi, this looks like an open discussion. Is there also a working solution for a 49PUS7xxx and a documentation how to use it? Or is this going to be a module inside the standard home assistant?
Regards


#58

Thank you for this! that works perfectly, how did you find out how to do this? I cant see it on the jointspace API documentation, I ask because I’m trying to set up an automation to switch the ambilights to follow audio, however swapping to {“styleName”:“FOLLOW_AUDIO”} doesn’t seem to work


#59

Hi!
With
curl -X GET --digest --insecure -u user:password https://192.x.x.x:1926/6/ambilight/currentconfiguration
you can get the correct command for the ambilight setting that is currently activated on your TV. So for follow audio you can use one of the following:

{"styleName":"FOLLOW_AUDIO","isExpert":false,"menuSetting":"ENERGY_ADAPTIVE_BRIGHTNESS"}
{"styleName":"FOLLOW_AUDIO","isExpert":false,"menuSetting":"ENERGY_ADAPTIVE_COLORS"}
{"styleName":"FOLLOW_AUDIO","isExpert":false,"menuSetting":"VU_METER"}
{"styleName":"FOLLOW_AUDIO","isExpert":false,"menuSetting":"SPECTUM_ANALYSER"}
{"styleName":"FOLLOW_AUDIO","isExpert":false,"menuSetting":"KNIGHT_RIDER_ALTERNATING"}
{"styleName":"FOLLOW_AUDIO","isExpert":false,"menuSetting":"RANDOM_PIXEL_FLASH"}
{"styleName":"FOLLOW_AUDIO","isExpert":false,"menuSetting":"MODE_RANDOM"}

Have fun :grinning:


#60

I cant thank you enough for sending that over, I now have a fully working input select that can set the ambilights to all of those functions.
Is there a page somewhere with all the available commands/settings you can send over ‘curl’ not shown on the Jointspace API page? or did you figure this out through some other means, I am also intending to add the functionality to change channel, source, and if its possible, open apps, but am struggling with the curl commands. Thanks again for your help

.