Philips Tv Http Control

This is a small howto on controlling your Philips Tv over HTTP with a Virtual device:
Fibaro Home Center Philips TV
Philips_Tv_Virtual_Device_Fibaro_Home_Center
We have to create a set of buttons as shown on the Right.

These buttons mostly contain the same code. Hower a small part is different as the action we want to accomplish is different.

When you go to the Ip of your TV in your browser at port 1925 for example: (http://192.168.1.20:1925) you see the manual on each action you can perform.

 

First we create a main loop which shows if the TV is ON or OFF in the same way as a regular device by changing the Icon.

The second purpose is getting the volume so we can set the Volume slider that we will create.

(the icons that are used in the code (1003 and 1004) are custom icons added in the Home Center. To see what the iconId is; change the Icon of the virtual device and goto http://HomeCenterIP/api/virtualDevices and copy the ID of the deviceIcon.

MainLoop


TV = Net.FHttp("192.168.1.20",1925)
--fibaro:log("Checking if TV is Online")

--fibaro:sleep(400)
response, status, errorCode = TV:GET("/1/audio/volume")

--fibaro:log(response)
if not (response == nill) then
volume = json.decode(response)
if volume.muted == true then
fibaro:log("muted");
end
--fibaro:log(volume.current);
-- set the current Volume to the Slider (sliderVolume is the ID of your slider)
fibaro:call(46, "setProperty", "ui.sliderVolume.value",volume.current);
end
if errorCode == 0 then
-- fibaro:log(status)
fibaro:sleep(400)
fibaro:call(46, "setProperty", "currentIcon", "1003")
-- fibaro:log("tv is online" )
else
fibaro:call(46, "setProperty", "currentIcon", "1004")
--fibaro:log("tv is offline")
end

NumericKeys

All the numeric keys use the same code as shown below.

key 1 = Digit1

key 2 = Digit2 etc.


TV = Net.FHttp("192.168.1.20",1925)
-- Change the Digit1 for a different channel key.
jsonString = {key="Digit1"}

jsonTable = json.encode(jsonString)
fibaro:log(jsonTable)
response, status, errorCode = TV:POST("/1/input/key?callback=", jsonTable )

fibaro:log(response)

if errorCode == 0

then
fibaro:log(status)
else
fibaro:log("error")
end

Source

To change the source of the TV we use the same code as used for the numeric keys, we only have to change the Url and the jsonString as shown below:
Tv= tv
Hdmi 2 = hdmi2 etc.
Look at the jointspace API refered on the top for all the codes.


jsonString = {id="hdmi2"}

jsonTable = json.encode(jsonString)
fibaro:log(jsonTable)
response, status, errorCode = TV:POST("/1/sources/current?callback=", jsonTable )

Volume

The volume button uses the same code, we only have to change the Url and the jsonString as shown below:


jsonString = {current=_sliderValue_}

jsonTable = json.encode(jsonString)
fibaro:log(jsonTable)
response, status, errorCode = TV:POST("/1/audio/volume?callback=", jsonTable )

De waardering van www.controlliving.nl bij Webwinkel Keurmerk Klantbeoordelingen is 9.4/10 gebaseerd op 22 reviews.