Re: Python plugin: Sony Bravia [ready for test]
Posted: Tuesday 18 April 2017 23:40
yes, was fixed, see editted post
Open source Home Automation System
https://forum.domoticz.com/
I have added the setPowerStatus command.Monki77 wrote:Nice plugin!
X8509C Android TV here.
My findings are -
Source seems to work fine.
EPG data works fine - Reports what is on TV
Volume doesn't work (as mentioned by others) but muting and reporting of volume does work.
The TV Remote button doesn't do anything (Not sure what it's supposed to do).
The TV does turn off, but will not turn on (I use WIFI, and a quick look at your script shows you use WOL, so i'm out of luck)
What i use to turn the TV on via wifi is an adapted version of another script made by StefanPuntNL (pasted it at the end of my post)
i just added this part -
jsonbodypoweron = '{\\"id\\":2,\\"method\\":\\"setPowerStatus\\",\\"version\\":\\"1.0\\",\\"params\\":[{ \\"status\\" : true}]}'
and then i edited the rest of the script accordingly.
I don't know if this only works for android TVs or not though...
Here's the full On/Off script (it does pull info from another script which pings my TV)
Sorry, but in the last past days i was a bit busy but i didn't stop to test the plugin.G3rard wrote:I think this can also work with the bravia.py file.markcame wrote:for the authorization with cookie i use the following script that can be found here https://github.com/breunigs/bravia-auth-and-remote
move on auth_cookie_examples folder then run auth.sh (you must previously fill with the required information in the script such as IP, nickname and a UUID)
then on the TV wil be displayed a code you can now enter on the console the code and a file will be created with the cookie.
it would be nice if this can be automatized in the plugin as a binding procedure, otherwise you can always run the the script and modify to update a domoticz variable that the plugin can catch, i think that for a full integration the harder part is to create a text box to enter the code displayed on the TV.
Are you able to try the connect function from bravia.py? You can add that to localtest.py to see if that works as well.
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.33.10"
SonyBraviaMAC="30:f9:ed:e2:3c:1b"
set -e
cd $(dirname $0)
if [ "$1" = "" ]; then
echo "Usage: $0 <COMMAND> [COUNT]"
exit 1
fi
if [ "$1" = "PowerOn" ]; then
wakeonlan $SonyBraviaMAC >/dev/null
echo "PowerOn: ✓"
exit 0
fi
if [ "$2" = "" ]; then
count="1"
else
count="$2"
fi
declare -A commandmap
#commandmap[PowerOff]="AAAAAQAAAAEAAAAvAw=="
#commandmap[PowerOff]="AAAAAQAAAAEAAAAVAw=="
commandmap[PowerOff]="AAAAAQAAAAEAAAAuAw=="
commandmap[Input]="AAAAAQAAAAEAAAAlAw=="
commandmap[TV]="AAAAAQAAAAEAAAAkAw=="
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=="
commandmap[Hdmi1]="AAAAAgAAABoAAABaAw=="
commandmap[Hdmi2]="AAAAAgAAABoAAABbAw=="
commandmap[Hdmi3]="AAAAAgAAABoAAABcAw=="
commandmap[Hdmi4]="AAAAAgAAABoAAABdAw=="
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/IRCC
for ((n=0;n<count;n++)); do
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
done
Can you share me some more details on the steps your are taking and what you think can be achieved from within the plugin?markcame wrote: Sorry, but in the last past days i was a bit busy but i didn't stop to test the plugin.
I've tryed the connect function and passing 0000 the tv will prompt a pin, i've also experimented with the cookie and i will confirm that afther about 2 weeks the cookie must be renewd, to do this i pass a null pin (using the code previously found on github) and this tells the tv to send a new cookie, obiouvsly this happens only if the device was previously paired, do you think this can be integrated in the plugin ?
What can you use from that script with your TV? Because the plugin uses the same method as in that script.DarkFoxDK wrote:I've got a Sony Bravia KDL-46EX724, which is a couple of generations older than the ones supported by the plugin, however, it still does support IRCC codes, so I wonder what would be needed for at least partial support?
Currently I'm using this script for somewhat limited control:
I think pretty much all but power on and off works in that script. None of the commands in the plugin work, it never even acknowledged that the TV was on.G3rard wrote: What can you use from that script with your TV? Because the plugin uses the same method as in that script.
The plugin also uses IRCC codes, for example in the Sources switch. Can you use that?
Ok I've tryed on localtest.py the connect function passing "0000" as pin start the pairing, then i execute again with the pin provided by TV and the registration was succesfull. I was not able instead to retrive the cookie from the function, it seems something goes wrong with the response from json.G3rard wrote:Can you share me some more details on the steps your are taking and what you think can be achieved from within the plugin?markcame wrote: Sorry, but in the last past days i was a bit busy but i didn't stop to test the plugin.
I've tryed the connect function and passing 0000 the tv will prompt a pin, i've also experimented with the cookie and i will confirm that afther about 2 weeks the cookie must be renewd, to do this i pass a null pin (using the code previously found on github) and this tells the tv to send a new cookie, obiouvsly this happens only if the device was previously paired, do you think this can be integrated in the plugin ?
* First registration
I guess you need to enter the pincode that is shown on the TV in the terminal when using the code from https://github.com/breunigs/bravia-auth-and-remote?
That means that you always need to go to the terminal to pair the TV, because you can't enter the code (which will be different every time) in Domoticz.
* Cookie renewal
Is that done with reauth.sh and without a pin?
In that case maybe it is a solution to use a LUA script in Domoticz to run the sh script every 2 weeks.
The plugin is designed to use with a pre-shared key which works much easier than the cookie method.
I saw that breunings also changed his code to work with a pre-shared key.
I made some changes in bravia.py because the plugin was not working with requests module, so changed that to urllib module.markcame wrote: Ok I've tryed on localtest.py the connect function passing "0000" as pin start the pairing, then i execute again with the pin provided by TV and the registration was succesfull. I was not able instead to retrive the cookie from the function, it seems something goes wrong with the response from json.
Are you able do make some code changes for this yourself?markcame wrote: I think this can be implemented in the plugin in the following way.
On plugin configuration in domoticz you can provide a checkbox to enable or not the use of cookie, than you can create a variable on domoticz in and you can store the auth cookie, then the variable that store the cookie can be updated triggered by the exeption on error 403 forbidden that means that the access is not authorized by the tv.
For the first pairing i think is better execute them on command line because i think will be difficult to input the pin provided by tv in domoticz.
Are you able do make some code changes for this yourself?[/quote]markcame wrote: I think this can be implemented in the plugin in the following way.
On plugin configuration in domoticz you can provide a checkbox to enable or not the use of cookie, than you can create a variable on domoticz in and you can store the auth cookie, then the variable that store the cookie can be updated triggered by the exeption on error 403 forbidden that means that the access is not authorized by the tv.
For the first pairing i think is better execute them on command line because i think will be difficult to input the pin provided by tv in domoticz.
Ok, bravia-auth-and-remote works perfect ...G3rard wrote:@Schuko80
Is localtest.py showing information on the program that is playing on the TV (if you are using the built-in TV tuner)?
Strange that the MAC address gives an error. Can you uncomment line 62 and share the results?
Are other Python plugins working on your system?
And can you explain a bit more on what happens when you try to add the plugin under Hardware? Maybe some screenshots.
And what do you mean with: "Every other device will work, too."?