Philips TV kontrollieren Python?
Hey liebe Programmierer Community,
ich schreibe mir gerade ein Skript mit dem ich unseren Philips Fernseher (Kein Android TV) mit Tkinter kontrollieren Kann
https://pastebin.com/DBCv2nkx
Volume Up und Down verändern klappt auch aber ist sehr umständlich.
Der Fernseher benutzt die Joint Space API (Documentation).
Laut dieser sollte ich ganz einfach meinen Input ändern können, aber ich kriege es nicht hin dass post ausgeführt wird.
import requests
x = requests.post('http://192.168.178.9:1925/1/input/key', json={"key": "VolumeDown"})
print(x)
↑ gibt mir zwar aus, <Response [200]> aber die Lautstärke wird nicht verändert.
Könnt ihr mir sagen was ich falsch mache.
LG
1 Antwort
Probier mal:
import requests
x = requests.get('http://192.168.178.9:1925/1/input/key', json={"key": "VolumeDown"})
print(x)
Ich kann es leider nicht ausprobieren, da ich so einen Fernseher nicht habe
Danke für deine Hilfe ich hab's jetzt doch noch geschafft.
Ist etwas umständlich funktioniert aber.
(Nicht wundern wegen der IP ich habe eine neue FritzBox)
import tkinter as tk
import tkinter.font as tkFont
from tkinter import Label
class App:
def __init__(self, root):
# setting title
root.title("TV Control Panel")
# setting window size
width = 356
height = 219
screenwidth = root.winfo_screenwidth()
screenheight = root.winfo_screenheight()
alignstr = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
root.geometry(alignstr)
root.resizable(width=False, height=False)
GButton_419 = tk.Button(root)
GButton_419["anchor"] = "center"
GButton_419["bg"] = "#f0f0f0"
ft = tkFont.Font(family='Times', size=10)
GButton_419["font"] = ft
GButton_419["fg"] = "#000000"
GButton_419["justify"] = "center"
GButton_419["text"] = "Up"
GButton_419.place(x=140, y=110, width=70, height=25)
GButton_419["command"] = self.GButton_419_command
GButton_928 = tk.Button(root)
GButton_928["bg"] = "#f0f0f0"
ft = tkFont.Font(family='Times', size=10)
GButton_928["font"] = ft
GButton_928["fg"] = "#000000"
GButton_928["justify"] = "center"
GButton_928["text"] = "Down"
GButton_928.place(x=140, y=150, width=70, height=25)
GButton_928["command"] = self.GButton_928_command
GLabel_424 = tk.Label(root)
ft = tkFont.Font(family='Times', size=26)
GLabel_424["font"] = ft
GLabel_424["fg"] = "#333333"
GLabel_424["justify"] = "center"
GLabel_424["text"] = "TV Control"
GLabel_424.place(x=90, y=10, width=178, height=51)
GLabel_868: Label = tk.Label(root)
ft = tkFont.Font(family='Times', size=18)
GLabel_868["font"] = ft
GLabel_868["fg"] = "#333333"
GLabel_868["justify"] = "center"
GLabel_868["text"] = "Volume:"
GLabel_868.place(x=130, y=60, width=98, height=33)
def GButton_419_command(self):
import requests
import json
x = requests.get(url='http://192.168.178.27:1925/1/audio/volume')
y = json.loads(x.text)
Vol = (y['current'])
level = Vol + 1
url = 'http://192.168.178.27:1925/1/audio/volume'
volume = {'current': level}
requests.get(url, json=volume)
x = requests.post(url, json=volume)
def GButton_928_command(self):
import requests
import json
x = requests.get(url='http://192.168.178.27:1925/1/audio/volume')
y = json.loads(x.text)
Vol = (y['current'])
level = Vol - 1
url = 'http://192.168.178.27:1925/1/audio/volume'
volume = {'current': level}
requests.get(url, json=volume)
x = requests.post(url, json=volume)
if __name__ == "__main__":
root = tk.Tk()
app = App(root)
root.mainloop()