(My German is not that good so I hope English is ok for you guys)
Since a couple of weeks I own a Sony AG9 TV which can be controlled via rest API / JSON RPC, so now during the holidays the time has come to have IP Symcon doing at least some basic stuff like switching the TV on and off i.e. when the alarm system is activated / de-activated.
In order to do that I tried to build some basic scripts. As the examples of Sony are in javascript I tried to ‚convert‘ it to php using several examples also from this forum but I can’t seem to get it right.
The javascript example from sony switches the input to HDMI 2. See the JS code underneath:
var xhr = new XMLHttpRequest();
xhr.open(‚POST‘, ‚http://192.168.0.1/sony/avContent‘);
xhr.setRequestHeader(‚X-Auth-PSK‘, ‚1234‘);
xhr.send(JSON.stringify(
{method: „setPlayContent“,
version: „1.0“,
id: 1,
params: [{uri: „extInput:hdmi?port=2“}]}
));
However I get an error message w.r.t. the first line of code (line 21):
parse error: syntax error, unexpected ‚=‘ in C:\ProgramData\Symcon\scripts\45885.ips.php on line 21
I’ve searched through the forum but I cannot get rid of the error …
I would ‚more than appreciate‘ your help.
Many thanks in advance!
$HTTP = new XMLHttpRequest();
$HTTP.open("POST","192.168.1.118/sony/avContent",true);
var $rpc = JSON.stringify({"method":"setPlayContent", "version":"1.0", "id":"1", "params":"[{uri: "extInput:hdmi?port=2"}]";
$HTTP.setRequestHeader("X-Auth-PSK", "1234");
$HTTP.send($rpc);
Unlike last time the error now shifts to line 23:
var $rpc = JSON.stringify({„method“:„setPlayContent“, „version“:„1.0“, „id“:„1“, „params“:"[{uri: „extInput:hdmi?port=2“}]";
The error code:
Parse error: syntax error, unexpected ‚var‘ (T_VAR), expecting end of file in C:\ProgramData\Symcon\scripts\45885.ips.php on line 23
I’ll take a look at the sony module. But you can imagine that I need to get this working now
You can also use the STV_* (i.e. STV_SetPowerStatus) functions.
You can check with
STV_ReadApplicationList(int $InstanceID):string
the list of callable apps reported by the Sony API. But make sure that the Sony is switched on.:). The test function „Update application list“ also updates the list of applications.