Philips Android TV

It works, perfect. Now looking for message display or audio :yum:

No idea about sending messages or sounds through adb directly. I suspect that may require a custom app to be installed which you then call through adb to display/play whatever.

Unfortunately I was not able to root my TV (strongly depends on model and firmware version and I didn’t find a app or step-by-step, which work for my model) so installing a custom app doesn’t work and those on the App store doesn’t support my TV model :frowning:

PS: I have also a wakeup script for Apple TV if that’s interesting to you.

Hi, I created a GitHub repository to share the latest version:

1 Like

Hi Markus,
first of all, thanks a lot for opening the github for this. I’m relative new in unsing the OpenHAB. Could you explain the using of the file more detailed?

My first Problem is using the .sh file. Is it right that it is necessary using a Linux System to run this ?

Thank you for a few more Informations.

Best regards from Germany
Marco

Hi Marco,

yes, it’s a Linux bash script. In genetal it should be portable to Windows with a little effort. In this case you need ADB compiled for Windows and change the syntax of the script.

You could run the script within an openHAB rule by executing the command line and passing the parameters or as part of the item definition using the exec plugin.

Cheers, Markus

@markus7017 big thanks for sharing your archievements.

Just tried myself today to get my 55PUS7101 integrated to openhab - stumbled over your solution aswell as the other one using the new API which replaced jointspace. (https://github.com/suborb/philips_android_tv)

As a programmer I actually prefered the API approach, but sadly the available KEY commands are very limited.

Your shell script worked like a charme and rescued me there :smile: big thanks for that.

Conclusion: I think your approach should work with all newer Philips TV Models.

Good to know that you get some more charme on your TV :wink:

I suppose the script works with all Android based Philips TVs (in fact the ADB hack is not Philips specific). There is also a good chance that it does work with other Android based TVs, the key codes are defined by Android not by Philips. This might be the basis to build an AndroidTV binding…

Indeed, thanks 2 ur scrript. :slight_smile:

But I must admit some days later, that ADB is damn unreliable. :wink:

Beside the fact that each TV model would need different “sleep”-statements for timing (e.g. to let the TV turn on before key inputs are invoked), adb is pretty buggy. At least for me.

If the TV turns off for example, adb is still listing the TV under connected devices. If then an adb command is executed, in my case it was retrieving the device status, it blocks the whole process. Couldnt find any “refresh device list” command for ADB.

First I used ping as a workaround for the device power status, but since my raspi is near the TV, I rather use CEC via HDMI. Thats also a lot faster then using wake-on-lan.

Hi,

couldn’t confirm this problem happens frequently, but saw it a few times. I’m using the script since several weeks and didn’t had a functional problem. Maybe this also depends on the adb build?

However, could you give some more information on “CEC via HDMI” - I know what it is, but don’t know how to use it in a bash script. My raspi is even near the TV, so… :wink:

Hey markus, good to hear that adb is not bugging you :wink:

First of all you need to install the needed libs (I did that on a raspberry pi 3):

sudo apt-get install cec-utils

after that you should be able to control the connected TV via HDMI (CEC must be enabled of course).

You might need to add openhab to the user group video:
sudo usermod -a -G video openhab

Try it out:
on -> echo on 0 | cec-client -s -d 1
off -> echo standby 0 | cec-client -s -d 1
check power status -> echo pow 0 | cec-client -s -d 1

For the “off” Command I still use adb. But power on and checking the device power status is done via CEC.

I adjusted these two functions in the bash script:

function device_status {
	e "Check device status with CEC..."
	if echo pow 0 | cec-client -s -d 1 | grep -q 'power status: on'; then
	  dev_status="ON"
	else
	  dev_status="OFF"
	  adb_disconnect #Note that I disconnect here due to my problems with adb
	fi
	e "Device Status=$dev_status"
}

and also the tv_on function:

function tv_on {
   	device_status
	if [ "$dev_status" == "OFF" ]
	then
	  echo on 0 | cec-client -s -d 1
	  sleep 2 #Adjust this if needed!
	  device_status
	  if [ "$dev_status" == "ON" ]
	  then
	   adb_connect
	  fi
	fi
}

Is that enough information? :slight_smile:

looks good, give it a try

according to https://blog.gordonturner.com/2016/12/14/using-cec-client-on-a-raspberry-pi/ it should also possible to select the HDMI source, this would even spit off the annoying selection with home+down+down…enter. Did you tried that already?

Hope you had success?

No I didnt try anything else, as my main intention is to start applications like Netflix and so on. I never have to change the input since I only use one hdmi source with my AVR denon (PS4 etc. is connected to it).

Right now I am working on a Tado Binding, but might be a challenge to create an adb binding afterwards! :slight_smile:

Cheers

Not yet verified (started with a fresh install, which needs some more work). Acc. to the page it should be also possible to display a message on the screen, this might be interesting for status notifications / alarms.:yum:

I like to see a Tado binding. However, I had one of those thermostats, but doesn’t support the heating system (too old).:face_with_raised_eyebrow:
Don’t waste the time with an ADB binding - it’s even a shame that Philips doesn’t have any suitable API after removing jointSpace.

I don’t have any notification use cases yet, but I will try that out this week and post my results here! Would be awesome. :slight_smile:

Too bad you can’t use Tado at your home. I also can’t use thermostats, but the Radiator thermostats. Thats what I build the binding for, but actually the handling should be the same. (Needs to be tested from someone)

After a second thought about the adb binding, you’re right. Adb itself is not meant for any production usage anyway…
Like you said, it’s frustrating that philips is only offering this half-hearted API. :neutral_face:

@bennYx0x I found the time to include cec handling (use_cec=1 toggles btw. cec and adb handling). I found a useful page to generate cec-util command strings: https://blog.gordonturner.com/2016/12/14/using-cec-client-on-a-raspberry-pi/

I found out that it also allows to select a specific HDMI device. I use this to switch the TV to the HDMI for the AVR. Using

sudo echo "scan" | cec-client RPI -s -d 1

opening a connection to the CEC adapter...
requesting CEC bus information ...
CEC bus information
===================
device #0: TV
address:       0.0.0.0
active source: no
vendor:        Unknown
osd string:    TV
CEC version:   1.4
power status:  standby
language:      ???


device #1: Recorder 1
address:       1.2.0.0
active source: no
vendor:        Samsung
osd string:    BD-HDD Combo
CEC version:   1.3a
power status:  standby
language:      ger


device #2: Recorder 2
address:       4.0.0.0
active source: no
vendor:        Pulse Eight
osd string:    CECTester
CEC version:   1.4
power status:  on
language:      eng


device #4: Playback 1
address:       1.4.0.0
active source: no
vendor:        Unknown
osd string:    Fire TV stick
CEC version:   1.4
power status:  on
language:      ???


device #5: Audio
address:       1.0.0.0
active source: no
vendor:        Marantz
osd string:    NR1506
CEC version:   1.4
power status:  standby
language:      ???


currently active source: unknown (-1)

you can find the HDMI address, in my case “1.0.0.0” for the NR1506. Use cec-client to send a command switching to the corresponding HDMI device:

echo "tx 2F:82:01:00" | cec-client RPI -s -d 1

This works as expected on the command line. However, nothing happens most times if I include the line into the script:

...
	"avr")
		dev_on
		if [ "$use_cec" == "1" ]; then
			e "Switch HDMI to address $hdmi_address_avr"
			echo "tx 2F:82:$hdmi_address_avr" | cec-client $cec_port -s -d 1
		else
			adb -s $uri shell "input keyevent 178 && input keyevent 122 && input keyevent 122 && input keyevent 122 && input keyevent 20 && input keyevent 20 && input keyevent 20 && input keyevent 20 && input keyevent 20 && input keyevent 66"
		fi;;
...

sometimes works after executing the script twice - strange.

Any idea? Did you had several problems when playing with cec-client?

Hey Markus!

I’m not switching channels since everything runs over my AVR on HDMI2. Therefore I am not using the command, BUT I also experienced your problem.

E.g. when starting the TV via CEC, sometimes nothing happends. I recognized, that after the TV gets Initial power (I always completely turn off my multiple plug), it takes some time until it responds to such commands.

I didn’t dive deeper into this, but I remember that I also have from time to time the situation, that I have to fire a command twice.

hmm, I don’t power off the TV, just standby. How long does it take for you to run cec-client, mine always takes about 3-5sec to open the bus - seems strange to me. Some kind of comm problems on the bus may result in loosing commands. Sometimes is works issuing the command twice, sometimes nothing happens after 5 times. This is anoying, because it would solve my problem very smart rather than navigating the menus using adb sendkey.

Hey Markus,

even though its a long time ago we talked about this: I finally found the time for writing a binding:

Cheers

Hi, in between I replaced the Philips by a Sony so I can’t help you with testing . sorry.