Page 1 of 11
Python plugin: Sony Bravia TV
Posted: Thursday 30 March 2017 0:52
by G3rard
- Spoiler: show
- I am working on my first Python plugin for a Sony Bravia TV using an existing Python script and rewrote that a little bit.
But my plugin.py keeps giving errors and I need some help to get this fixed.
There is no device created, allthough Domoticz shows a message that devices are created after adding the hardware.
The errors in the Domoticz log:
Code: Select all
2017-03-30 00:23:34.844 (Sony) Initialized version 0.1, author 'G3rard'
2017-03-30 00:23:49.153 Error: PluginList: Error 'Error document empty.' at line 0 column 0 in XML ''.
2017-03-30 00:23:55.347 (Sony) Exiting work loop...
2017-03-30 00:23:55.347 (Sony) Stopped.
2017-03-30 00:25:00.079 Error: Sony hardware (14) thread seems to have ended unexpectedly
2017-03-30 00:25:30.084 Error: Sony hardware (14) thread seems to have ended unexpectedly
2017-03-30 00:26:00.089 Error: Sony hardware (14) thread seems to have ended unexpectedly
2017-03-30 00:26:30.094 Error: Sony hardware (14) thread seems to have ended unexpectedly
I will probably have something done wrong in the plugin.py, but I have no clue left what to fix anymore.
Hope somebody here can point me in the right direction.
I am not a coder (but mostly understand what have I have to do or otherwise do a lot of trial and error), so please bear with me
I have enclosed the Python scripts.
* plugin.py
* bravia.py
* localtest.py
* fakeDomoticz.py
EDIT: I also placed the Python scripts on https://github.com/gerard33/sony-bravia for some easier reviewing.
localtest.py (with fakeDomoticz.py) can be used to do some testing on the CLI.
That will show that bravia.py is working fine (IP address of TV is currently hardcoded in line 39 of bravia.py). If TV is off or if you have no Bravia TV, then it will show a message that the TV is assumed off.
Additional information:
* Domoticz v3.7197 (build date 29 March)
* Ubuntu Server 14.04
* Python 3.4.3
* Other plugins (among which Kodi, Sonos, Denon) are working fine
EDIT2: plugin is ready for testing, see viewtopic.php?f=65&t=16910#p128159
EDIT3: plugin is live, see https://github.com/gerard33/sony-bravia
Re: Python plugin: Sony Bravia [help needed]
Posted: Thursday 30 March 2017 15:17
by ycahome
Hello G3rard
Which series of Sony Bravia you own?
I have tried in the past with my EX720 series without success (other scripts). Finally got the correct method but not yet tried to incorporate into domo-plugin (to be precise, didn't found the way to create a virtual remote like kodi's one).
Re: Python plugin: Sony Bravia [help needed]
Posted: Thursday 30 March 2017 15:40
by ycahome
With your plugin am getting :
Code: Select all
2017-03-30 16:38:52.715 Error: (SonyBraviaTV) failed to load 'plugin.py', Python Path used was '/home/yiannis/domoticz/plugins/SonyBraviaTv/:/usr/lib/python35.zip:/usr/lib/python3.5/:/usr/lib/python3.5/plat-x86_64-linux-gnu:/usr/lib/python3.5/lib-dynload'.
2017-03-30 16:38:52.716 Error: (SonyTest) Module Import failed, exception: 'NameError
Re: Python plugin: Sony Bravia [help needed]
Posted: Thursday 30 March 2017 17:06
by Anrox
I don't know if it helps but I changed the following line in plugin.py
Code: Select all
sys.path.append('/usr/local/lib/python3.4/dist-packages')
to
Code: Select all
sys.path.append('/usr/lib/python3/dist-packages')
I don't get any errors.
Re: Python plugin: Sony Bravia [help needed]
Posted: Thursday 30 March 2017 23:11
by G3rard
ycahome wrote:Hello G3rard
Which series of Sony Bravia you own?
I have tried in the past with my EX720 series without success (other scripts). Finally got the correct method but not yet tried to incorporate into domo-plugin (to be precise, didn't found the way to create a virtual remote like kodi's one).
Hi ycahome,
I am using the Python script on a KDL-50W829B.
As a matter of fact I also have an KDL-32EX720, but I don't think bravia.py will work with that TV as it states the TV needs to be of 2013 or later.
Which method do you use for the EX720?
ycahome wrote:With your plugin am getting :
Code: Select all
2017-03-30 16:38:52.715 Error: (SonyBraviaTV) failed to load 'plugin.py', Python Path used was '/home/yiannis/domoticz/plugins/SonyBraviaTv/:/usr/lib/python35.zip:/usr/lib/python3.5/:/usr/lib/python3.5/plat-x86_64-linux-gnu:/usr/lib/python3.5/lib-dynload'.
2017-03-30 16:38:52.716 Error: (SonyTest) Module Import failed, exception: 'NameError
Can you rename the folder SonyBraviaTv to sony?
I use the key 'sony' in the xml and I am not sure if that key needs to be the same as the folder name, see this text from the wiki regarding the key.
Unique identifier for the plugin. Never visible to users this should be short, meaningful and made up of characters A-Z, a-z, 0-9 and -_ only. Stored in the ‘Extra’ field in the Hardware. Used as the base name for the plugin Python file, e.g. ‘DenonAVR’ maps to /plugins/DenonAVR/plugin.py
Re: Python plugin: Sony Bravia [help needed]
Posted: Thursday 30 March 2017 23:15
by G3rard
Anrox wrote:I don't know if it helps but I changed the following line in plugin.py
Code: Select all
sys.path.append('/usr/local/lib/python3.4/dist-packages')
to
Code: Select all
sys.path.append('/usr/lib/python3/dist-packages')
I don't get any errors.
I changed it to that folder and I get a NameError. The folder on my Ubuntu system for this is the one I used.
Is a TV device created when you added the hardware? Because that is not working on my config.
Re: Python plugin: Sony Bravia [help needed]
Posted: Friday 31 March 2017 9:06
by Anrox
I already have a TV device in my system. Beside that no other TV device was created. When I get home I will try to rename the existing one and try your plugin again.
Re: Python plugin: Sony Bravia [help needed]
Posted: Friday 31 March 2017 11:08
by G3rard
@Anrox, thanks.
However I think there is still something wrong in plugin.py because in my config no device is created.
Hopefully someone can point me in the right direction, otherwise I will try some more options in the coming days.
Re: Python plugin: Sony Bravia [help needed]
Posted: Friday 31 March 2017 11:30
by ycahome
G3rard wrote:Anrox wrote:I don't know if it helps but I changed the following line in plugin.py
Code: Select all
sys.path.append('/usr/local/lib/python3.4/dist-packages')
to
Code: Select all
sys.path.append('/usr/lib/python3/dist-packages')
I don't get any errors.
I changed it to that folder and I get a NameError. The folder on my Ubuntu system for this is the one I used.
Is a TV device created when you added the hardware? Because that is not working on my config.
This is a matter of the version of python and/or modules you have installed. Mine is where Anrox says.
My final result is
-plugin initializing but devices were not created
Seems that code execution not entering on*
Re: Python plugin: Sony Bravia [help needed]
Posted: Friday 31 March 2017 11:43
by ycahome
as for the EX720 series:
if am remember well, with curl the command is the following:
Code: Select all
curl -X POST -d '<?xml version="1.0" encoding="utf-8"?><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>AAAAAQAAAAEAAAAOAw==</IRCCCode></u:X_SendIRCC></s:Body></s:Envelope>' http://SoneBraviaIPaddress/IRCC
Re: Python plugin: Sony Bravia [help needed]
Posted: Friday 31 March 2017 17:42
by Anrox
The problem might be in bravia.py. When I comment out the import and the parts that use it Status device is created.
Re: Python plugin: Sony Bravia [help needed]
Posted: Friday 31 March 2017 20:01
by G3rard
Thanks! I will see if I can get it working by copying only the functions in bravia.py which determine the power state to plugin.py.
If that works I can add some more functions to see if any of these causes an issue.
EDIT: I also placed the Python scripts on
https://github.com/gerard33/sony-bravia for some easier reviewing.
Re: Python plugin: Sony Bravia [help needed]
Posted: Saturday 01 April 2017 15:50
by Anrox
If you comment out the requests module in bravia.py the Status device is created.
Python plugin: Sony Bravia [help needed]
Posted: Saturday 01 April 2017 15:55
by G3rard
I already suspected it had something to do with the requests module.
I use a different path to import it, but saw in another post that it still can cause issues that way and that it was fixed by using another module. I will see what I can do with this requests module.
Edit: the requests module is indeed the reason it doesn't work. I have changed the code to use urllib module and now it's working
It's strange that there are no errors visible related to the requests module after adding the module with sys.path.append.
@Anrox, thanks for your help!!! Now I can continue to further develop the Python plugin.
- sony_tv.png (35.67 KiB) Viewed 9063 times
Re: Python plugin: Sony Bravia [work in progress]
Posted: Friday 07 April 2017 0:28
by G3rard
Making some good progress with the plugin. Expect to release a first version soon which can be used for testing.
Let me know if you are interested to test the plugin.
It will work on Sony Bravia models 2013 and newer. Not tested on Sony Bravia with Android yet!
- sony_tv_plugin.png (94.36 KiB) Viewed 9006 times
Re: Python plugin: Sony Bravia [work in progress]
Posted: Friday 07 April 2017 14:21
by Anrox
I would like to test it.
Re: Python plugin: Sony Bravia [work in progress]
Posted: Sunday 09 April 2017 0:18
by G3rard
@Anrox, will share the script soon.
Do you have Android on your TV? Because I think then simple IP control is needed.
That is currently not supported, but maybe I can add that, because my TV also seems to support simple IP control.
Re: Python plugin: Sony Bravia [work in progress]
Posted: Monday 10 April 2017 10:21
by Anrox
No, I don't. I have a KDL42W705B.
Re: Python plugin: Sony Bravia [ready for test]
Posted: Tuesday 11 April 2017 0:18
by G3rard
The plugin is ready for testing.
You can download the files from
https://github.com/gerard33/sony-bravia.
The instruction is also on the Github page.
Let me know if the plugin is working for you.
If you have any issues or feature requests then please raise an issue on Github.
Re: Python plugin: Sony Bravia [ready for test]
Posted: Tuesday 11 April 2017 11:05
by Anrox
I does work for me. No problems so far.