Philips TV Jointspace api

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
georgemaster
Posts: 4
Joined: Mon Jul 27, 2015 6:35 am

Philips TV Jointspace api

Post by georgemaster » Mon Sep 14, 2015 2:25 pm

I have been busy creating the possibility to control a philips TV through "Jointspace api".
Although there were several html based solutions, the Eventghost solution was still not available.

(change the IP address to your own TV)

Here are some examples how to do it:

POST commands

"standby"

python script:

Code: Select all

import httplib
key='{"key": "Standby"}'
h = httplib.HTTPConnection('192.168.178.36:1925')
h.request('POST','/1/input/key', key)

r = h.getresponse()

print r.read()[/quote]


Volume Up

[u]Python script[/u]
[quote]import httplib
key='{"key": "VolumeUp"}'
h = httplib.HTTPConnection('192.168.178.36:1925')
h.request('POST','/1/input/key', key)

r = h.getresponse()

print r.read()

Digit1

Python script

Code: Select all

import httplib
key='{"key": "Digit1"}'
h = httplib.HTTPConnection('192.168.178.36:1925')
h.request('POST','/1/input/key', key)

r = h.getresponse()

print r.read()

Set absolute volume (20)

Python script

Code: Select all

import httplib
key='{"muted":false,"current":20}'
h = httplib.HTTPConnection('192.168.178.36:1925')
h.request('POST','/1/audio/volume', key)

r = h.getresponse()

print r.read()



Select HDMI 1

Python script
"

Code: Select all

import httplib
key='{"id": "hdmi1"}'
h = httplib.HTTPConnection('192.168.178.36:1925')
h.request('POST','/1/sources/current', key)

r = h.getresponse()

print r.read()
print "HDMI 1 selected


Mute On/Of (true or false)

Python script

Code: Select all

import httplib
key='{"muted":true}'
h = httplib.HTTPConnection('192.168.178.36:1925')
h.request('POST','/1/audio/volume', key)

r = h.getresponse()

print r.read()



confirm (ok)

Python script

Code: Select all

import httplib
key='{"key": "Confirm"}'
h = httplib.HTTPConnection('192.168.178.36:1925')
h.request('POST','/1/input/key', key)

r = h.getresponse()

print r.read()



If you want to know the current playing channel (GET command), you will find out that the TV will only return an ID number (looking like this "0-3-10284-0-1536-2099-19422"). Obtaining the corresponding channel info has to be done by a lookup in file, containing the ID, preset, name info etc.
This file has to be created first by importing all the info from the TV at once.

(Create a folder "C:\Eventghost" with "channels.csv" for this script)

Looking like this

Python script

Code: Select all

import httplib
import sys
temp = sys.stdout
h = httplib.HTTPConnection('192.168.178.36:1925')
h.request('GET','/1/channels')
r = h.getresponse()
eg.globals.response=r.read().replace("{","").replace("}","").replace('"','').replace(",","").strip()
import sys
sys.stdout=open("C:\Eventghost\channels.csv","w")
print eg.globals.response
r.close()
sys.stdout=temp
print "Channel info is saved to C:\Eventghost\channels.csv"





Requesting info about the current playing channel, will look something like this (the ID is provided by the TV, the info is taken from "channels.csv"):

Python script

Code: Select all

import httplib
h = httplib.HTTPConnection('192.168.178.36:1925')
h.request('GET','/1/channels/current')
r = h.getresponse()
eg.globals.status=r.read().replace("{","").replace("}","").replace(":","").replace('"','').replace("id","").strip()
f = open("C:\Eventghost\channels.csv", "r")
searchlines = f.readlines()
f.close()
for i, line in enumerate(searchlines):
    if eg.globals.status in line: 
        for l in searchlines[i:i+3]: print l,
        print




Another script example

Get all sources (print to log)

Python script

Code: Select all

import httplib
h = httplib.HTTPConnection('192.168.178.36:1925')
h.request('GET','/1/sources')
r = h.getresponse()
print r.read()




OSD your TV model

Python script

Code: Select all

import httplib
h = httplib.HTTPConnection('192.168.178.36:1925')
h.request('GET','/1/system/model')
r = h.getresponse()
eg.globals.status=r.read().replace("{","").replace("}","").replace(":","").replace('"','').replace("id","").strip()
eg.plugins.EventGhost.ShowOSD(u'{eg.globals.status}', u'0;-37;0;0;0;700;0;0;0;0;3;2;1;34;Arial', (255, 255, 255), (0, 0, 0), 4, (0, 0), 0, 5.0, True)





OSD current source

Python script

Code: Select all

import httplib
h = httplib.HTTPConnection('192.168.178.36:1925')
h.request('GET','/1/sources/current')
r = h.getresponse()
eg.globals.status=r.read().replace("{","").replace("}","").replace(":","").replace('"','').replace("id","").strip()
eg.plugins.EventGhost.ShowOSD(u'Current Source: {eg.globals.status}', u'0;-37;0;0;0;700;0;0;0;0;3;2;1;34;Arial', (255, 255, 255), (0, 0, 0), 4, (0, 0), 0, 5.0, True)




OSD software version

Python script

Code: Select all

import httplib
h = httplib.HTTPConnection('192.168.178.36:1925')
h.request('GET','/1/system/softwareversion')
r = h.getresponse()
eg.globals.status=r.read().replace("{","").replace("}","").replace(":","").replace('"','').strip()
eg.plugins.EventGhost.ShowOSD(u'{eg.globals.status}', u'0;-37;0;0;0;700;0;0;0;0;3;2;1;34;Arial', (255, 255, 255), (0, 0, 0), 4, (0, 0), 0, 5.0, True)




OSD current volume

Python script

Code: Select all

import httplib
h = httplib.HTTPConnection('192.168.178.36:1925')
h.request('GET','/1/audio/volume')
r = h.getresponse()
eg.globals.status=r.read().replace("{","").replace("}","").replace('"','').replace(",","").strip()
eg.plugins.EventGhost.ShowOSD(u'{eg.globals.status}', u'0;-37;0;0;0;700;0;0;0;0;3;2;1;34;Arial', (255, 255, 255), (0, 0, 0), 4, (0, 0), 0, 5.0, True)



Say, you want to select a specific channel directly (this has to be done with the ID (fingerprint). Which you can find in the channels.csv list.

This will look something like this. (POST command)

Python script

Code: Select all

import httplib
channel = '{"id":"0-3-10156-0-1536-2098-19401"}'
h = httplib.HTTPConnection('192.168.178.36:1925')
h.request('POST','/1/channels/current', channel)
r = h.getresponse()
print r.read()
print "NPO 1 HD selected"

To get (OSD) the current playing channel ID:

Python script

Code: Select all

import httplib
h = httplib.HTTPConnection('192.168.178.36:1925')
h.request('GET','/1/channels/current')
r = h.getresponse()
eg.globals.status=r.read().replace("{","").replace("}","").replace(":","").replace('"','').strip()
eg.plugins.EventGhost.ShowOSD(u'{eg.globals.status}', u'0;-37;0;0;0;700;0;0;0;0;3;2;1;34;Arial', (255, 255, 255), (0, 0, 0), 4, (0, 0), 0, 5.0, True)
print eg.globals.status


You can also print all channel info to the LOG

Python script

Code: Select all

import httplib
h = httplib.HTTPConnection('192.168.178.36:1925')
h.request('GET','/1/channels')
r = h.getresponse()
print r.read()



Select TV (source)
Python script

Code: Select all

import httplib
key='{"id": "tv"}'
h = httplib.HTTPConnection('192.168.178.36:1925')
h.request('POST','/1/sources/current', key)

r = h.getresponse()

print r.read()
print "TV selected"



I have been struggling with the multiple digit input, to select a specific channel. Because Python scripting is not my strongest point, somebody else will do it better for sure.
Using a "triggerevent" in a html based remote control, this was the best I could think of:

Python script

Code: Select all

import sys
input=eg.event.suffix.replace("digit","")

if input == "EnterInput":
    print "Enter Ok"
    f = open('c:\eventghost\channelinput.txt', 'w')
    f.write("")
    f.close()
    import httplib
    try:
        h = httplib.HTTPConnection('192.168.178.36:1925')
        h.request('POST','/1/input/key', key1)
        h = httplib.HTTPConnection('192.168.178.36:1925')
        h.request('POST','/1/input/key', key2)
        h = httplib.HTTPConnection('192.168.178.36:1925')
        h.request('POST','/1/input/key', key3)
        h = httplib.HTTPConnection('192.168.178.36:1925')
        h.request('POST','/1/input/key', key4)
        #r = h.getresponse()          #will return a "bad request" when less than 4 digits are entered, but works ok. . .
        #print r.read()
        eg.plugins.EventGhost.TriggerEvent(u'Show.Channel.Info', 10.0)
    except:
        pass
    value1=""
    value2=""
    value3=""
    value4=""
if input == "ClearInput":
    print "Clear file"
    f = open('c:\eventghost\channelinput.txt', 'w')
    f.write("")
    f.close()
    value1=""
    value2=""
    value3=""
    value4=""

    

if input.isdigit():
    f = open('c:\eventghost\channelinput.txt', 'a');
    f.write(input)

f = open('c:\eventghost\channelinput.txt', 'r')

digits= f.read(4)
eg.globals.digits=digits

try:
    value1=eg.globals.digits[0]
    value2=eg.globals.digits[1]
    value3=eg.globals.digits[2]
    value4=eg.globals.digits[3]
except:
    pass


try:
    key1='{"key": "Digit'+value1+ '"}' 
    key2='{"key": "Digit'+value2+ '"}' 
    key3='{"key": "Digit'+value3+ '"}' 
    key4='{"key": "Digit'+value4+ '"}' 
except:
    pass

try:
    print key1
    print key2
    print key3
    print key4
except:
    pass


# format:  key='{"key": "Digit6"}'


All Jointspace api info is found on the web page of your TV, url : "http://<ip-address-tv>:1925"




Last but not least I have attached a sample eventghost config file.

Success
Attachments
Philips Jointspace api.xml
(17.1 KiB) Downloaded 229 times

georgemaster
Posts: 4
Joined: Mon Jul 27, 2015 6:35 am

Re: Philips TV Jointspace api

Post by georgemaster » Mon Sep 14, 2015 6:29 pm

Correction on first python script, something went wrong when submitting it. . .

Standby

Python script

Code: Select all

import httplib
key='{"key": "Standby"}'
h = httplib.HTTPConnection('192.168.178.36:1925')
h.request('POST','/1/input/key', key)

r = h.getresponse()

print r.read()




Volume Up

Python script

Code: Select all

import httplib
key='{"key": "VolumeUp"}'
h = httplib.HTTPConnection('192.168.178.36:1925')
h.request('POST','/1/input/key', key)

r = h.getresponse()

print r.read()

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Philips TV Jointspace api

Post by krambriw » Wed Sep 16, 2015 6:59 am

Dear georgemaster,
It is great to see your efforts,

However, I think (and this I understand is not obvious) you should have put those postings with python samples into the 'Coding Corner'. Once you eventually have a plugin ready for launch, you can post it with descriptions in the 'Plugin Support' section

Hope you understand, we just need to keep the boards reasonable structured

Best regards, Walter


PS Moderator, try to see if you can move this thread to 'Coding Corner'....

skribb
Experienced User
Posts: 228
Joined: Thu Feb 12, 2015 7:22 pm
Location: Win7 64bit

Re: Philips TV Jointspace api

Post by skribb » Fri Jan 03, 2020 12:06 am

This is for STANDBY on Philips PUS6754

Code: Select all

import httplib
key='{"key": "Standby"}'
h = httplib.HTTPConnection('192.168.xxx.xxx:1925')
h.request('POST','/6/input/key', key)

r = h.getresponse()

print r.read()
Automation is life.

Win7 64bit
EG: v0.5.0-rc4

Post Reply