Page 1 of 3
LUA script for Sony Bravia TV
Posted: Sunday 04 October 2015 20:23
by StefanPuntNL
Hi there,
I want to share with you my LUA scripts for turning on/off a Sony Bravia TV. I created and tested this with a KDL-50W815B model, but i'm sure this will work with lots of other network connected Sony Bravia models.
My solution consists of two scripts. The first one is a time script that updates the status in Domoticz when the TV was turned on or off via another remote. The second script is a device script that can actually turn the television on and off.
The scripts are made for Domoticz on the Raspberry Pi, but may also work on other Linux/Unix distros.
Prerequisites:
- Create a virtual switch (On/Off) named "TV"
- Create a user variable (integer) named "TVOnlyStatusUpdate", with value 0
- Install etherwake (sudo apt-get install etherwake)
- Enable remote start on your TV: [Settings] → [Network] → [Home Network Setup] → [Remote Start] → [On]
- Enable pre-shared key on your TV: [Settings] → [Network] → [Home Network Setup] → [IP Control] → [Authentication] → [Normal and Pre-Shared Key]
- Set pre-shared key on your TV: [Settings] → [Network] → [Home Network Setup] → [IP Control] → [Pre-Shared Key] → [sony]
- Give your TV a static IP address, or make a DHCP reservation for a specific IP address in your router.
- Determine the MAC address of your TV: [Settings] → [Network] → [Network Setup] → [View Network Status]
The virtual switch will, obviously, be used in the interface to control the device and see the status. The user variable is to determine whether the device has been switched on or off via the timed script. If that is the case, the device script doesn't have to actually switch on/off the device. In that case only the status in Domoticz has to be updated.
What you need to adjust in the scripts:
- In script 2, set the MAC address of your TV. Update the following to match the MAC address: 'etherwake ab:12:34:5678'.
- In both scripts set the url to match the IP address of your TV.
- I used 'sony' as pre-shared key in this example, but you can define your own pre-shared key. When you do so, make sure to update this in both scripts. (headervalue = 'sony')
1: script_time_tvstatus.lua
Code: Select all
function getPowerStatus()
local url = 'http://10.101.0.50/sony/system'
local headername = 'X-Auth-PSK'
local headervalue = 'sony'
local jsonbodygetstatus = '{\\"id\\":2,\\"method\\":\\"getPowerStatus\\",\\"version\\":\\"1.0\\",\\"params\\":[]}'
local runcommand = 'curl -v -H \"Content-Type:application/json\" -H \"' .. headername .. ':' .. headervalue .. '\" -d \"' .. jsonbodygetstatus .. '\" ' .. url .. ''
local h=io.popen(runcommand)
local response=h:read("*a")
h:close()
if string.find(response, '{"status":"active"}') then
return 'active'
elseif string.find(response, '{"status":"standby"}') then
return 'standby'
else
return 'unkown'
end
end
commandArray = {}
ping_success=os.execute('ping -c1 10.101.0.50')
if (ping_success) then
print('TV ping success')
powerstatus=getPowerStatus()
print('TV says it is ' .. powerstatus)
if(powerstatus == 'active') then
if(otherdevices['TV'] == 'Off') then
print('TV active, but status is OFF, so update to ON.')
commandArray['Variable:TVOnlyStatusUpdate'] = '1'
commandArray['TV'] = 'On'
else
print('TV active, status is ON, so do nothing.')
end
elseif(powerstatus == 'standby') then
if(otherdevices['TV'] == 'On') then
print('TV standby, but status is ON, so update to OFF.')
commandArray['Variable:TVOnlyStatusUpdate'] = '1'
commandArray['TV'] = 'Off'
else
print('TV standby, status is OFF, so do nothing.')
end
else
print('TV in unknown power status, doing nothing...')
end
else
print("TV ping fail")
if(otherdevices['TV'] == 'On') then
print('TV current status here is ON, so update status to OFF.')
commandArray['Variable:TVOnlyStatusUpdate'] = '1'
commandArray['TV']='Off'
else
print('TV current status here is OFF, so do nothing.')
end
end
return commandArray
2: script_device_tv.lua
Code: Select all
commandArray = {}
if(devicechanged['TV']) then
url = 'http://10.101.0.50/sony/system'
headername = 'X-Auth-PSK'
headervalue = 'sony'
jsonbodypoweroff = '{\\"id\\":2,\\"method\\":\\"setPowerStatus\\",\\"version\\":\\"1.0\\",\\"params\\":[{ \\"status\\" : false}]}'
if (devicechanged['TV'] == 'On') then
if(uservariables['TVOnlyStatusUpdate'] == 1) then
print('TV status update received (ON), resetting user variable.')
commandArray['Variable:TVOnlyStatusUpdate'] = '0'
else
os.execute('etherwake ab:12:34:56:cd:78')
print('TV got wake up call')
end
end
if (devicechanged['TV'] == 'Off') then
if(uservariables['TVOnlyStatusUpdate'] == 1) then
print('TV status update received (OFF), resetting user variable.')
commandArray['Variable:TVOnlyStatusUpdate'] = '0'
else
runcommand = 'curl -v -H \"Content-Type:application/json\" -H \"' .. headername .. ':' .. headervalue .. '\" -d \"' .. jsonbodypoweroff .. '\" ' .. url .. ''
response = os.execute(runcommand)
if response then
print('TV goes sleepy sleep')
else
print('TV not in the mood for sleepy sleep')
end
end
end
end
return commandArray
Please share your suggestions, tips or other thoughts
Re: LUA script for Sony Bravia TV
Posted: Sunday 04 October 2015 22:44
by G3rard
Thanks for sharing
This works great on my KDL-50W829B.
Do you know how to start Netflix using a script? I have found some commands on
http://mendelonline.be/sony/sony.txt but don't know how to use the Netflix command.
Re: LUA script for Sony Bravia TV
Posted: Monday 05 October 2015 13:12
by StefanPuntNL
G3rard wrote:Thanks for sharing
This works great on my KDL-50W829B.
Do you know how to start Netflix using a script? I have found some commands on
http://mendelonline.be/sony/sony.txt but don't know how to use the Netflix command.
Starting Netflix from Domoticz was/is my next objective. I haven't integrated it yet in Domoticz, but I did figure out how to achieve this through the API on the TV.
You can retrieve a list of possible commands from the TV by executing the getRemoteControllerInfo method of the API. You can do this by posting the following JSON to 'http://[your tv ip here]/sony/system' (same as in the on/off scripts). Don't forget send the X-Auth-PSK header.
Code: Select all
{"id":20,"method":"getRemoteControllerInfo","version":"1.0","params":[]}
This will return a JSON with command names and values. The values can be used to control the TV. However these commands must be send to a SOAP (XML) endpoint with a different url: 'http://[your tv ip]/sony/IRCC' (for some models the URL is 'http://[your tv ip]/IRCC'). Again, don't forget the X-Auth-PSK header.
This is an example of a SOAP XML message that should start Netflix (at least on some models, be sure to check the getRemoteControllerInfo result):
Code: Select all
<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:X_SendIRCC xmlns:u="urn:schemas-sony-com:service:IRCC:1">
<IRCCCode>AAAAAgAAABoAAAB8Aw==</IRCCCode>
</u:X_SendIRCC>
</s:Body>
</s:Envelope>
I'm still thinking about what the best way is to integrate this into Domoticz: as a on/off-switch that automatically turns to off after Netflix has started or as a scene. If you have any good ideas let me know.
Another idea would be to pause the TV when someone presses the doorbell.
As soon as I have a Netflix integrated I will post my solution with scripts to this thread.
Re: LUA script for Sony Bravia TV
Posted: Tuesday 06 October 2015 23:55
by G3rard
I have checked the getRemoteControllerInfo (Netflix command is the same as above) and sent the SOAP XML message to the TV, but can't get it working. Which curl command are you using for sending the XML file?
I have used
https://github.com/breunigs/bravia-auth-and-remote on my laptop to start Netflix and it worked for some time, but not anymore.
So it would be nice if your method is working.
Re: LUA script for Sony Bravia TV
Posted: Wednesday 07 October 2015 12:44
by StefanPuntNL
G3rard wrote:I have checked the getRemoteControllerInfo (Netflix command is the same as above) and sent the SOAP XML message to the TV, but can't get it working. Which curl command are you using for sending the XML file?
I have used
https://github.com/breunigs/bravia-auth-and-remote on my laptop to start Netflix and it worked for some time, but not anymore.
So it would be nice if your method is working.
Nice Github repo! I see that the author of those scripts has implemented the auth mechanism. Nice! However, when using the pre-shared key you don't have to save that cookie. I will use the repo to create my own variant. When I got it working I will post it here. Probably Saturday or Sunday.
Re: LUA script for Sony Bravia TV
Posted: Wednesday 07 October 2015 12:51
by G3rard
Nice, I have issues with the auth cookie (doesn't work okay on my NAS, did work on my Ubuntu laptop) so I am looking forward to your solution.
Re: LUA script for Sony Bravia TV
Posted: Sunday 11 October 2015 14:52
by StefanPuntNL
I created the following bash script: remote.sh
- Set the variables at the top of the file to match your own environment
- Place file in scripts folder of Domoticz
- Make it executable (chmod +x remote.sh)
- Example of usage: ./remote.sh PowerOn
- Possible commands depend on exact type of TV, but most commands are probably the same for each Bravia TV.
Code: Select all
#!/bin/bash
#Uncomment the following lines by removing the hash sign when your variables are not stored in profile.d
SonyBraviaAuthHeader="X-Auth-PSK"
SonyBraviaPreSharedKey="sony"
SonyBraviaIP="192.168.0.100"
SonyBraviaMAC=ab:12:34:56:cd:78
set -e
cd $(dirname $0)
if [ "$1" = "" ]; then
echo "Usage: $0 <COMMAND>"
exit 1
fi
if [ "$1" = "PowerOn" ]; then
wakeonlan $SonyBraviaMAC >/dev/null
echo "PowerOn: ✓"
exit 0
fi
declare -A commandmap
commandmap[PowerOff]="AAAAAQAAAAEAAAAvAw=="
commandmap[Input]="AAAAAQAAAAEAAAAlAw=="
commandmap[GGuide]="AAAAAQAAAAEAAAAOAw=="
commandmap[EPG]="AAAAAgAAAKQAAABbAw=="
commandmap[Favorites]="AAAAAgAAAHcAAAB2Aw=="
commandmap[Display]="AAAAAQAAAAEAAAA6Aw=="
commandmap[Home]="AAAAAQAAAAEAAABgAw=="
commandmap[Options]="AAAAAgAAAJcAAAA2Aw=="
commandmap[Return]="AAAAAgAAAJcAAAAjAw=="
commandmap[Up]="AAAAAQAAAAEAAAB0Aw=="
commandmap[Down]="AAAAAQAAAAEAAAB1Aw=="
commandmap[Right]="AAAAAQAAAAEAAAAzAw=="
commandmap[Left]="AAAAAQAAAAEAAAA0Aw=="
commandmap[Confirm]="AAAAAQAAAAEAAABlAw=="
commandmap[Red]="AAAAAgAAAJcAAAAlAw=="
commandmap[Green]="AAAAAgAAAJcAAAAmAw=="
commandmap[Yellow]="AAAAAgAAAJcAAAAnAw=="
commandmap[Blue]="AAAAAgAAAJcAAAAkAw=="
commandmap[Num1]="AAAAAQAAAAEAAAAAAw=="
commandmap[Num2]="AAAAAQAAAAEAAAABAw=="
commandmap[Num3]="AAAAAQAAAAEAAAACAw=="
commandmap[Num4]="AAAAAQAAAAEAAAADAw=="
commandmap[Num5]="AAAAAQAAAAEAAAAEAw=="
commandmap[Num6]="AAAAAQAAAAEAAAAFAw=="
commandmap[Num7]="AAAAAQAAAAEAAAAGAw=="
commandmap[Num8]="AAAAAQAAAAEAAAAHAw=="
commandmap[Num9]="AAAAAQAAAAEAAAAIAw=="
commandmap[Num0]="AAAAAQAAAAEAAAAJAw=="
commandmap[Num11]="AAAAAQAAAAEAAAAKAw=="
commandmap[Num12]="AAAAAQAAAAEAAAALAw=="
commandmap[VolumeUp]="AAAAAQAAAAEAAAASAw=="
commandmap[VolumeDown]="AAAAAQAAAAEAAAATAw=="
commandmap[Mute]="AAAAAQAAAAEAAAAUAw=="
commandmap[ChannelUp]="AAAAAQAAAAEAAAAQAw=="
commandmap[ChannelDown]="AAAAAQAAAAEAAAARAw=="
commandmap[SubTitle]="AAAAAgAAAJcAAAAoAw=="
commandmap[ClosedCaption]="AAAAAgAAAKQAAAAQAw=="
commandmap[Enter]="AAAAAQAAAAEAAAALAw=="
commandmap[DOT]="AAAAAgAAAJcAAAAdAw=="
commandmap[Analog]="AAAAAgAAAHcAAAANAw=="
commandmap[Teletext]="AAAAAQAAAAEAAAA/Aw=="
commandmap[Exit]="AAAAAQAAAAEAAABjAw=="
commandmap[Analog2]="AAAAAQAAAAEAAAA4Aw=="
commandmap[*AD]="AAAAAgAAABoAAAA7Aw=="
commandmap[Digital]="AAAAAgAAAJcAAAAyAw=="
commandmap[Analog?]="AAAAAgAAAJcAAAAuAw=="
commandmap[BS]="AAAAAgAAAJcAAAAsAw=="
commandmap[CS]="AAAAAgAAAJcAAAArAw=="
commandmap[BSCS]="AAAAAgAAAJcAAAAQAw=="
commandmap[Ddata]="AAAAAgAAAJcAAAAVAw=="
commandmap[PicOff]="AAAAAQAAAAEAAAA+Aw=="
commandmap[Tv_Radio]="AAAAAgAAABoAAABXAw=="
commandmap[Theater]="AAAAAgAAAHcAAABgAw=="
commandmap[SEN]="AAAAAgAAABoAAAB9Aw=="
commandmap[InternetWidgets]="AAAAAgAAABoAAAB6Aw=="
commandmap[InternetVideo]="AAAAAgAAABoAAAB5Aw=="
commandmap[Netflix]="AAAAAgAAABoAAAB8Aw=="
commandmap[SceneSelect]="AAAAAgAAABoAAAB4Aw=="
commandmap[Mode3D]="AAAAAgAAAHcAAABNAw=="
commandmap[iManual]="AAAAAgAAABoAAAB7Aw=="
commandmap[Audio]="AAAAAQAAAAEAAAAXAw=="
commandmap[Wide]="AAAAAgAAAKQAAAA9Aw=="
commandmap[Jump]="AAAAAQAAAAEAAAA7Aw=="
commandmap[PAP]="AAAAAgAAAKQAAAB3Aw=="
commandmap[MyEPG]="AAAAAgAAAHcAAABrAw=="
commandmap[ProgramDescription]="AAAAAgAAAJcAAAAWAw=="
commandmap[WriteChapter]="AAAAAgAAAHcAAABsAw=="
commandmap[TrackID]="AAAAAgAAABoAAAB+Aw=="
commandmap[TenKey]="AAAAAgAAAJcAAAAMAw=="
commandmap[AppliCast]="AAAAAgAAABoAAABvAw=="
commandmap[acTVila]="AAAAAgAAABoAAAByAw=="
commandmap[DeleteVideo]="AAAAAgAAAHcAAAAfAw=="
commandmap[PhotoFrame]="AAAAAgAAABoAAABVAw=="
commandmap[TvPause]="AAAAAgAAABoAAABnAw=="
commandmap[KeyPad]="AAAAAgAAABoAAAB1Aw=="
commandmap[Media]="AAAAAgAAAJcAAAA4Aw=="
commandmap[SyncMenu]="AAAAAgAAABoAAABYAw=="
commandmap[Forward]="AAAAAgAAAJcAAAAcAw=="
commandmap[Play]="AAAAAgAAAJcAAAAaAw=="
commandmap[Rewind]="AAAAAgAAAJcAAAAbAw=="
commandmap[Prev]="AAAAAgAAAJcAAAA8Aw=="
commandmap[Stop]="AAAAAgAAAJcAAAAYAw=="
commandmap[Next]="AAAAAgAAAJcAAAA9Aw=="
commandmap[Rec]="AAAAAgAAAJcAAAAgAw=="
commandmap[Pause]="AAAAAgAAAJcAAAAZAw=="
commandmap[Eject]="AAAAAgAAAJcAAABIAw=="
commandmap[FlashPlus]="AAAAAgAAAJcAAAB4Aw=="
commandmap[FlashMinus]="AAAAAgAAAJcAAAB5Aw=="
commandmap[TopMenu]="AAAAAgAAABoAAABgAw=="
commandmap[PopUpMenu]="AAAAAgAAABoAAABhAw=="
commandmap[RakurakuStart]="AAAAAgAAAHcAAABqAw=="
commandmap[OneTouchTimeRec]="AAAAAgAAABoAAABkAw=="
commandmap[OneTouchView]="AAAAAgAAABoAAABlAw=="
commandmap[OneTouchRec]="AAAAAgAAABoAAABiAw=="
commandmap[OneTouchStop]="AAAAAgAAABoAAABjAw=="
commandmap[DUX]="AAAAAgAAABoAAABzAw=="
commandmap[FootballMode]="AAAAAgAAABoAAAB2Aw=="
commandmap[Social]="AAAAAgAAABoAAAB0Aw=="
IRCC=${commandmap[$1]}
if [ "$IRCC" = "" ]; then
echo "Unkown command $1"
exit 1
fi
cmd="<?xml version=\"1.0\"?><s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:X_SendIRCC xmlns:u=\"urn:schemas-sony-com:service:IRCC:1\"><IRCCCode>$IRCC</IRCCCode></u:X_SendIRCC></s:Body></s:Envelope>"
auth="$SonyBraviaAuthHeader: $SonyBraviaPreSharedKey"
url=http://$SonyBraviaIP/sony/IRCC
code=$(curl -w "%{http_code}" --silent -d "$cmd" -H 'Content-Type: text/xml; charset=UTF-8' -H "$auth" $url -o /dev/null )
if [ "$code" = "200" ]; then
echo "$1: ✓"
else
echo "$1: Command failed (HTTP_CODE: $code, try running it in a console)"
exit 1
fi
I also created a bash script to start Netflix named: start_netflix.sh. In this script I call the remote.sh script. This script can optionally be called with parameter PowerOn, so that it will first power on the TV before starting Netflix. Don't forget to make it executable: chmod +x start_netflix.sh
- ./start_netflix.sh PowerOn
You can also use this as an example for creating remote control macro's (e.g. PowerOn > Home > Left > Left > Confirm).
Code: Select all
#!/bin/bash
set -e
cd $(dirname $0)
remote() {
./remote.sh $1
}
# turn on when poweron parameter is used, pass this from lua script
if [ "$1" = "PowerOn" ]; then
remote 'PowerOn'
echo 'Waiting for TV to boot!'
sleep 30
fi
remote 'Netflix'
exit 0
The last piece of scripting for Netflix is a LUA script that is triggered when the virtual switch 'Netflix' is turned on: script_device_netflix.lua
Code: Select all
commandArray = {}
if (devicechanged['Netflix'] == 'On') then
print('Starting Netflix')
scriptPath = '/home/pi/domoticz/scripts/start_netflix.sh'
if(otherdevices['TV'] == 'On') then
cmd= scriptPath .. ' &'
os.execute(cmd)
else
cmd=scriptPath .. ' PowerOn &'
commandArray['TV'] = 'On'
os.execute(cmd)
end
commandArray['Netflix'] = 'Off'
end
return commandArray
Re: LUA script for Sony Bravia TV
Posted: Sunday 11 October 2015 15:03
by G3rard
Thanks for the scripts
Will try this asap and let you know the results.
Re: LUA script for Sony Bravia TV
Posted: Monday 12 October 2015 20:08
by G3rard
@StefanPuntNL, I get an 500 error code when starting ./start_netflix.sh.
Code: Select all
Netflix: Command failed (HTTP_CODE: 500, try running it in a console)
I changed the settings in the remote.sh scripts and the scripts are executable. The command for Netflix has the right code. I also tried other commands with the remote.sh script, but get the same 500 error.
Do you have an idea how to fix this? I have googled but found no relevant information.
Re: LUA script for Sony Bravia TV
Posted: Monday 12 October 2015 23:23
by StefanPuntNL
G3rard wrote:@StefanPuntNL, I get an 500 error code when starting ./start_netflix.sh.
Code: Select all
Netflix: Command failed (HTTP_CODE: 500, try running it in a console)
I changed the settings in the remote.sh scripts and the scripts are executable. The command for Netflix has the right code. I also tried other commands with the remote.sh script, but get the same 500 error.
Do you have an idea how to fix this? I have googled but found no relevant information.
Oooops, I made a copy/paste mistake while placing the variables at the top of the remote.sh script. That is because I don't use these variables myself.
Change: SonyBraviaHeader="X-Auth-PSK"
To: SonyBraviaAuthHeader="X-Auth-PSK"
I edited the script in my previous post.
Re: LUA script for Sony Bravia TV
Posted: Wednesday 14 October 2015 22:52
by G3rard
Thanks, that did the trick
. Now it works!
I also placed the MAC address between quotes.
Re: LUA script for Sony Bravia TV
Posted: Friday 30 October 2015 8:58
by galadril
Thanks!!
Works great with my tv
Re: LUA script for Sony Bravia TV
Posted: Friday 27 November 2015 22:22
by assenzuid
Unfortunately it won't work with a Sony KDL xxHX850 series
2015-11-27 22:19:00.373 LUA: TV ping success
2015-11-27 22:19:03.479 LUA: TV says it is unkown
2015-11-27 22:19:03.479 LUA: TV in unknown power status, doing nothing...
If I browse to
http://xxx.xxx.xxx.xxx/KDL-xxHX850/system the result is 'unknow', also to
http://xxx.xxx.xxx.xxx result in 'unknow'
Re: LUA script for Sony Bravia TV
Posted: Tuesday 12 January 2016 20:24
by toming
Hi,
I'm trying to get this running, but i keep receiving an error 500 despite all settings on the TV and in the script-parameters are correct...
Code: Select all
PowerOff: Command failed (HTTP_CODE: 500, try running it in a console)
I tried to run the command manually from the terminal (without --silent) to the tv, and the command gets send out, but looks like the TV doesn't accept it. i'm running a newer AndroidTV (KDL-55X8509C). Does anyone have a clue or experience this too?
Re: LUA script for Sony Bravia TV
Posted: Thursday 28 January 2016 22:58
by wmnl
toming wrote:Hi,
I'm trying to get this running, but i keep receiving an error 500 despite all settings on the TV and in the script-parameters are correct...
Code: Select all
PowerOff: Command failed (HTTP_CODE: 500, try running it in a console)
I tried to run the command manually from the terminal (without --silent) to the tv, and the command gets send out, but looks like the TV doesn't accept it. i'm running a newer AndroidTV (KDL-55X8509C). Does anyone have a clue or experience this too?
Hi,
Same goes for me with a 49X8305C.
Code: Select all
$ ./start_netflix.sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 804 100 513 100 291 41417 23494 --:--:-- --:--:-- --:--:-- 42750
Netflix: Command failed (HTTP_CODE: 500, try running it in a console)
The first script posted in this thread, the on/off script with preshared key, works.
When I try to manually send data (eg the Netflix command) with the Chrome rest api app, first a 403 is returned. After authentication (which succeeds as described) I also receive a 500. Details:
Code: Select all
<?xml version="1.0"?>
<s:Envelope
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<s:Fault>
<faultcode>s:Client</faultcode>
<faultstring>UPnPError</faultstring>
<detail>
<UPnPError xmlns="urn:schemas-upnp-org:control-1-0">
<errorCode>401</errorCode>
<errorDescription>Invalid Action</errorDescription>
</UPnPError>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>
Anyone have a clue
?
Re: LUA script for Sony Bravia TV
Posted: Thursday 31 March 2016 0:21
by noddy119
I also have a 2015 Sony Android TV.
After a bit of trial and error the following bash script <thanks to StefanPuntNL
> seems to work, at least from the shell
My TV does not respond to wake on lan or etherwake but by querying the TV using info from this post:
http://www.openremote.org/display/forum ... TP+control I found a command called 'WakeUp' which turns on the tv.
N.b. I have not tested all the commands in the code below as yet, but have the output from my TV to compare.
Its actually simpler than before:
- Enable remote start on your TV: [Settings] → [Network] → [Home Network Setup] → [Remote Start] → [On]
Enable pre-shared key on your TV: [Settings] → [Network] → [Home Network Setup] → [IP Control] → [Authentication] → [Normal and Pre-Shared Key]
Enable Simple IP Control on your TV: [Settings] → [Network] → [Home Network Setup] → [IP Control] → [Simple IP Control] → [On]
Set pre-shared key on your TV: [Settings] → [Network] → [Home Network Setup] → [IP Control] → [Pre-Shared Key] → [yourkey]
Give your TV a static IP address, or make a DHCP reservation for a specific IP address in your router.
Code: Select all
#!/bin/bash
#Change these to your variables
SonyBraviaPreSharedKey="yourpresharedkey"
SonyBraviaIP="yourTVipaddress"
set -e
cd $(dirname $0)
if [ "$1" = "" ]; then
echo "Usage: $0 <COMMAND>"
exit 1
fi
declare -A commandmap
commandmap[PowerOff]="AAAAAQAAAAEAAAAvAw=="
commandmap[PowerOn]="AAAAAQAAAAEAAAAuAw=="
commandmap[VolumeUp]="AAAAAQAAAAEAAAASAw=="
commandmap[VolumeDown]="AAAAAQAAAAEAAAATAw=="
commandmap[Mute]="AAAAAQAAAAEAAAAUAw=="
commandmap[Input]="AAAAAQAAAAEAAAAlAw=="
commandmap[GGuide]="AAAAAQAAAAEAAAAOAw=="
commandmap[EPG]="AAAAAgAAAKQAAABbAw=="
commandmap[Favorites]="AAAAAgAAAHcAAAB2Aw=="
commandmap[Display]="AAAAAQAAAAEAAAA6Aw=="
commandmap[Home]="AAAAAQAAAAEAAABgAw=="
commandmap[Options]="AAAAAgAAAJcAAAA2Aw=="
commandmap[Return]="AAAAAgAAAJcAAAAjAw=="
commandmap[Up]="AAAAAQAAAAEAAAB0Aw=="
commandmap[Down]="AAAAAQAAAAEAAAB1Aw=="
commandmap[Right]="AAAAAQAAAAEAAAAzAw=="
commandmap[Left]="AAAAAQAAAAEAAAA0Aw=="
commandmap[Confirm]="AAAAAQAAAAEAAABlAw=="
commandmap[Red]="AAAAAgAAAJcAAAAlAw=="
commandmap[Green]="AAAAAgAAAJcAAAAmAw=="
commandmap[Yellow]="AAAAAgAAAJcAAAAnAw=="
commandmap[Blue]="AAAAAgAAAJcAAAAkAw=="
commandmap[Num1]="AAAAAQAAAAEAAAAAAw=="
commandmap[Num2]="AAAAAQAAAAEAAAABAw=="
commandmap[Num3]="AAAAAQAAAAEAAAACAw=="
commandmap[Num4]="AAAAAQAAAAEAAAADAw=="
commandmap[Num5]="AAAAAQAAAAEAAAAEAw=="
commandmap[Num6]="AAAAAQAAAAEAAAAFAw=="
commandmap[Num7]="AAAAAQAAAAEAAAAGAw=="
commandmap[Num8]="AAAAAQAAAAEAAAAHAw=="
commandmap[Num9]="AAAAAQAAAAEAAAAIAw=="
commandmap[Num0]="AAAAAQAAAAEAAAAJAw=="
commandmap[Num11]="AAAAAQAAAAEAAAAKAw=="
commandmap[Num12]="AAAAAQAAAAEAAAALAw=="
commandmap[ChannelUp]="AAAAAQAAAAEAAAAQAw=="
commandmap[ChannelDown]="AAAAAQAAAAEAAAARAw=="
commandmap[SubTitle]="AAAAAgAAAJcAAAAoAw=="
commandmap[ClosedCaption]="AAAAAgAAAKQAAAAQAw=="
commandmap[Enter]="AAAAAQAAAAEAAAALAw=="
commandmap[DOT]="AAAAAgAAAJcAAAAdAw=="
commandmap[Analog]="AAAAAgAAAHcAAAANAw=="
commandmap[Teletext]="AAAAAQAAAAEAAAA/Aw=="
commandmap[Exit]="AAAAAQAAAAEAAABjAw=="
commandmap[Analog2]="AAAAAQAAAAEAAAA4Aw=="
commandmap[*AD]="AAAAAgAAABoAAAA7Aw=="
commandmap[Digital]="AAAAAgAAAJcAAAAyAw=="
commandmap[Analog?]="AAAAAgAAAJcAAAAuAw=="
commandmap[BS]="AAAAAgAAAJcAAAAsAw=="
commandmap[CS]="AAAAAgAAAJcAAAArAw=="
commandmap[BSCS]="AAAAAgAAAJcAAAAQAw=="
commandmap[Ddata]="AAAAAgAAAJcAAAAVAw=="
commandmap[PicOff]="AAAAAQAAAAEAAAA+Aw=="
commandmap[Tv_Radio]="AAAAAgAAABoAAABXAw=="
commandmap[Theater]="AAAAAgAAAHcAAABgAw=="
commandmap[SEN]="AAAAAgAAABoAAAB9Aw=="
commandmap[InternetWidgets]="AAAAAgAAABoAAAB6Aw=="
commandmap[InternetVideo]="AAAAAgAAABoAAAB5Aw=="
commandmap[Netflix]="AAAAAgAAABoAAAB8Aw=="
commandmap[SceneSelect]="AAAAAgAAABoAAAB4Aw=="
commandmap[Mode3D]="AAAAAgAAAHcAAABNAw=="
commandmap[iManual]="AAAAAgAAABoAAAB7Aw=="
commandmap[Audio]="AAAAAQAAAAEAAAAXAw=="
commandmap[Wide]="AAAAAgAAAKQAAAA9Aw=="
commandmap[Jump]="AAAAAQAAAAEAAAA7Aw=="
commandmap[PAP]="AAAAAgAAAKQAAAB3Aw=="
commandmap[MyEPG]="AAAAAgAAAHcAAABrAw=="
commandmap[ProgramDescription]="AAAAAgAAAJcAAAAWAw=="
commandmap[WriteChapter]="AAAAAgAAAHcAAABsAw=="
commandmap[TrackID]="AAAAAgAAABoAAAB+Aw=="
commandmap[TenKey]="AAAAAgAAAJcAAAAMAw=="
commandmap[AppliCast]="AAAAAgAAABoAAABvAw=="
commandmap[acTVila]="AAAAAgAAABoAAAByAw=="
commandmap[DeleteVideo]="AAAAAgAAAHcAAAAfAw=="
commandmap[PhotoFrame]="AAAAAgAAABoAAABVAw=="
commandmap[TvPause]="AAAAAgAAABoAAABnAw=="
commandmap[KeyPad]="AAAAAgAAABoAAAB1Aw=="
commandmap[Media]="AAAAAgAAAJcAAAA4Aw=="
commandmap[SyncMenu]="AAAAAgAAABoAAABYAw=="
commandmap[Forward]="AAAAAgAAAJcAAAAcAw=="
commandmap[Play]="AAAAAgAAAJcAAAAaAw=="
commandmap[Rewind]="AAAAAgAAAJcAAAAbAw=="
commandmap[Prev]="AAAAAgAAAJcAAAA8Aw=="
commandmap[Stop]="AAAAAgAAAJcAAAAYAw=="
commandmap[Next]="AAAAAgAAAJcAAAA9Aw=="
commandmap[Rec]="AAAAAgAAAJcAAAAgAw=="
commandmap[Pause]="AAAAAgAAAJcAAAAZAw=="
commandmap[Eject]="AAAAAgAAAJcAAABIAw=="
commandmap[FlashPlus]="AAAAAgAAAJcAAAB4Aw=="
commandmap[FlashMinus]="AAAAAgAAAJcAAAB5Aw=="
commandmap[TopMenu]="AAAAAgAAABoAAABgAw=="
commandmap[PopUpMenu]="AAAAAgAAABoAAABhAw=="
commandmap[RakurakuStart]="AAAAAgAAAHcAAABqAw=="
commandmap[OneTouchTimeRec]="AAAAAgAAABoAAABkAw=="
commandmap[OneTouchView]="AAAAAgAAABoAAABlAw=="
commandmap[OneTouchRec]="AAAAAgAAABoAAABiAw=="
commandmap[OneTouchStop]="AAAAAgAAABoAAABjAw=="
commandmap[DUX]="AAAAAgAAABoAAABzAw=="
commandmap[FootballMode]="AAAAAgAAABoAAAB2Aw=="
commandmap[Social]="AAAAAgAAABoAAAB0Aw=="
IRCC=${commandmap[$1]}
if [ "$IRCC" = "" ]; then
echo "Unknown command $1"
exit 1
fi
code=$(curl -sw "%{http_code}" --silent -XPOST http://$SonyBraviaIP/sony/IRCC -H "X-Auth-PSK:$SonyBraviaPreSharedKey" -d "<?xml version=\"1.0\"?><s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:X_SendIRCC xmlns:u=\"urn:schemas-sony-com:service:IRCC:1\"><IRCCCode>"$IRCC"</IRCCCode></u:X_SendIRCC></s:Body></s:Envelope>" -H 'Content-Type: text/xml; charset=UTF-8' -H 'SOAPACTION: "urn:schemas-sony-com:service:IRCC:1#X_SendIRCC"' -o /dev/null)
#Debug should return 200
#echo "Returned code = " $code
if [ "$code" = "200" ]; then
echo "Command $1 transmitted"
else
echo "$1: Command failed (HTTP_CODE: $code)"
exit 1
fi
Re: LUA script for Sony Bravia TV
Posted: Wednesday 04 May 2016 12:57
by WorldO
When I try to manually send data (eg the Netflix command) with the Chrome rest api app, first a 403 is returned. After authentication (which succeeds as described) I also receive a 500. Details:????
Re: LUA script for Sony Bravia TV
Posted: Tuesday 24 May 2016 15:34
by piotr
The script logs an error every few seconds:
Error: EventSystem: Lua script /home/pi/domoticz/scripts/lua/script_device_tv.lua did not return a commandArray
Any ideas ?
Re: LUA script for Sony Bravia TV
Posted: Wednesday 25 May 2016 23:05
by G3rard
Does your script start with
and end with?
Re: LUA script for Sony Bravia TV
Posted: Wednesday 08 June 2016 15:51
by piotr
G3rard wrote:Does your script start with
and end with?
I copied script_time_tvstatus.lua from the first post in this topic