Python plugin: Sony Bravia TV

Python and python framework
User avatar
lmet
Posts: 24
Joined: Wednesday 19 July 2017 22:35
Target OS: Raspberry Pi
Domoticz version: v3.8153
Location: France
Contact:

Re: Python plugin: Sony Bravia TV

Post by lmet » Monday 07 August 2017 17:09

Remains the same
It's an android tv
This is what I'v done :
I enter Andoid in the PSK field --> KO
I'v removed the device from Hardware list, reboot system and add it again --> KO
I'v modify the PSK Key from sony to Android on tv --> KO
I'v modify the localtest.py and change psk = 'sony' to psk = 'Android' --> KO
May be not compatible with my KDL-50W755C model of 2015 ?
Clear browser cache and appcache done

alanlsmith
Posts: 91
Joined: Monday 07 August 2017 17:17
Target OS: Linux
Domoticz version: 4.9701
Location: Near London
Contact:

Re: Python plugin: Sony Bravia TV

Post by alanlsmith » Monday 07 August 2017 17:24

@imet
I think Gerard meant to say, enter Android in the MAC address field on the Domoticz hardware entry for Sony TV. Leave the psk as sony in both Domoticz and the actual television (or anything that you want provided the television and Domoticz and the scripts all have the same)
Domoticz v4.9701 beta, Ubuntu 18.04 on Intel NUC i3, 8Gb ram, 70Gb drive, RFXtrx433, z-wave and a bit of Broadlink/Android

User avatar
G3rard
Posts: 827
Joined: Wednesday 04 March 2015 23:15
Target OS: Linux
Domoticz version: V3.8153
Location: The Netherlands
Contact:

Re: Python plugin: Sony Bravia TV

Post by G3rard » Monday 07 August 2017 18:08

You're right, I meant the MAC field in the Domoticz Hardware page. The plugin checks for that value and then sends another command to switch the TV on.

The localtest.py is just for testing on the command line, changes there have no influence on the plugin.

PSK should be the same value in Domoticz and on the TV (I use sony as PSK).
Ubuntu Server 14.04 | Domoticz v3.8153 | RFXtrx433E | Z-Wave Aeotec Z-Stick S2
Frontpage | Sonos PHP | Dark th3me | Sony Bravia Python plugin | Sonos Python plugin

User avatar
lmet
Posts: 24
Joined: Wednesday 19 July 2017 22:35
Target OS: Raspberry Pi
Domoticz version: v3.8153
Location: France
Contact:

Re: Python plugin: Sony Bravia TV

Post by lmet » Monday 07 August 2017 18:15

It works great thanks to you both
So plugin is compatible with Sony KDL-50W755C

User avatar
G3rard
Posts: 827
Joined: Wednesday 04 March 2015 23:15
Target OS: Linux
Domoticz version: V3.8153
Location: The Netherlands
Contact:

Re: Python plugin: Sony Bravia TV

Post by G3rard » Monday 07 August 2017 19:21

That's good to hear! Will add your model to the supported TV list on the Github page.
Ubuntu Server 14.04 | Domoticz v3.8153 | RFXtrx433E | Z-Wave Aeotec Z-Stick S2
Frontpage | Sonos PHP | Dark th3me | Sony Bravia Python plugin | Sonos Python plugin

alanlsmith
Posts: 91
Joined: Monday 07 August 2017 17:17
Target OS: Linux
Domoticz version: 4.9701
Location: Near London
Contact:

Re: Python plugin: Sony Bravia TV

Post by alanlsmith » Monday 07 August 2017 20:02

KD-55XD8005 works fine also with version 1.2

The previous version caused Domoticz to crash with a python fragmentation error after about 2 hours, although the plugin 'devices' worked perfectly within that time. (I was able to reproduce this each time I enabled the plugin.)

Now with version 1.2 the plugin has been enabled for a day and is running perfectly.

Thank you for your hard work on this.
Domoticz v4.9701 beta, Ubuntu 18.04 on Intel NUC i3, 8Gb ram, 70Gb drive, RFXtrx433, z-wave and a bit of Broadlink/Android

simon_rb
Posts: 699
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: Python plugin: Sony Bravia TV

Post by simon_rb » Monday 07 August 2017 22:24

alanlsmith wrote:KD-55XD8005 works fine also with version 1.2

The previous version caused Domoticz to crash with a python fragmentation error after about 2 hours, although the plugin 'devices' worked perfectly within that time. (I was able to reproduce this each time I enabled the plugin.)

Now with version 1.2 the plugin has been enabled for a day and is running perfectly.

Thank you for your hard work on this.
Same TV as mine and all working except volume feedback. Does your Domoticz update the volume to reflect the volume on the TV? As in if the domoticz is 30 and you change the TV to 20 using the TV remote, does your Domoticz change the volume slider in domoticz to 20?

Cheers

alanlsmith
Posts: 91
Joined: Monday 07 August 2017 17:17
Target OS: Linux
Domoticz version: 4.9701
Location: Near London
Contact:

Re: Python plugin: Sony Bravia TV

Post by alanlsmith » Tuesday 08 August 2017 14:31

@simon_rb

Yes it does, change the volume with the television remote and it's reflected in Domoticz (after the update delay).

Turn the television off and the slider stays at the last setting and the switch shows 'Off' (as it should)
Domoticz v4.9701 beta, Ubuntu 18.04 on Intel NUC i3, 8Gb ram, 70Gb drive, RFXtrx433, z-wave and a bit of Broadlink/Android

simon_rb
Posts: 699
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: Python plugin: Sony Bravia TV

Post by simon_rb » Tuesday 08 August 2017 23:20

Its hit and miss whether the Domoticz gets updates from the TV.. Don't know why. Its not just the volume, none of the info gets updated from the TV. Then suddenly it will work for a bit then stop again. Strange

This is in the log, repeated a lot of times:-
Error: (Living Room TV) HTTPError: HTTP Error 500: Internal Server Error

UPDATE:- Works fine when watching normal TV, its when I'm using apps like Amazon on the Android TV that there is no feedback to Domoticz. Soon as I got to watching TV via HDMI I start getting updates

markcame
Posts: 34
Joined: Wednesday 07 December 2016 20:13
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Sony Bravia TV

Post by markcame » Thursday 10 August 2017 16:04

After installation of the lastest stable version of domoticz i'm able to run the plugin without crash, but when i try to reboot or restart the service domoticz.sh it fail and became active(exited) and the web interface goes offline.
if i disable the hardware prior to make a restart and re-enable the hardware after all will be again up and running.
all is 100% reproducible on my system

It seems related with the creation of the object _tv = BraviaRC in onStart(self). but i have no idea how to fix it

I'v also coded the support for the cookie if you want can be integrated in the plugin

User avatar
miesjel
Posts: 14
Joined: Saturday 05 August 2017 13:34
Target OS: Raspberry Pi
Domoticz version:
Location: The Netherlands
Contact:

Re: Python plugin: Sony Bravia TV

Post by miesjel » Thursday 10 August 2017 19:52

I've installed the plugin and it looks amazing!

Unfortunality not everything works with my tv, a Sony KD-49X8308C Android TV. I'm not able to turn it on and change channels, but it does read the status of the TV. So it shows if its on or off.

Any tricks i might try to get it to work fully? :D

The test file, localtest.py does not seem to work, when typing ./localtest.py it says permission denied and when i use sudo ./localtest.py it says command not found (logged in via SSH)

edit: The log file:
2017-08-10 20:58:52.999 User: Admin initiated a switch command (50/Sony TV - Status/On)
2017-08-10 20:58:53.047 (Sony TV) onCommand called for Unit 1: Parameter 'On', Level: 0
2017-08-10 20:58:53.047 (Sony TV) Error when starting TV using WOL (invalid literal for int() with base 16: 'AC-9B-0A-BA-4D-74')

Second edit: Only power on doesnt work, i can switch channels and turn it off, change volume etc.

markcame
Posts: 34
Joined: Wednesday 07 December 2016 20:13
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Sony Bravia TV

Post by markcame » Thursday 10 August 2017 20:49

miesjel wrote:
Thursday 10 August 2017 19:52
I've installed the plugin and it looks amazing!

Unfortunality not everything works with my tv, a Sony KD-49X8308C Android TV. I'm not able to turn it on and change channels, but it does read the status of the TV. So it shows if its on or off.

Any tricks i might try to get it to work fully? :D

The test file, localtest.py does not seem to work, when typing ./localtest.py it says permission denied and when i use sudo ./localtest.py it says command not found (logged in via SSH)

edit: The log file:
2017-08-10 20:58:52.999 User: Admin initiated a switch command (50/Sony TV - Status/On)
2017-08-10 20:58:53.047 (Sony TV) onCommand called for Unit 1: Parameter 'On', Level: 0
2017-08-10 20:58:53.047 (Sony TV) Error when starting TV using WOL (invalid literal for int() with base 16: 'AC-9B-0A-BA-4D-74')

Second edit: Only power on doesnt work, i can switch channels and turn it off, change volume etc.
Have you put in the plugin configuration the word "Android" instead of the mac address ?
the localtest instead must be run calling "python3 localtest.py" and must be configured proprely editing the file.

User avatar
G3rard
Posts: 827
Joined: Wednesday 04 March 2015 23:15
Target OS: Linux
Domoticz version: V3.8153
Location: The Netherlands
Contact:

Python plugin: Sony Bravia TV

Post by G3rard » Thursday 10 August 2017 20:50

Enter 'Android' (without quotes) in the MAC address field on the Hardware page in Domoticz and press Update.
Then turning the TV on should work.

To make localtest.py work, enter 'chmod +x localtest.py' on the command line via SSH. Then ./localtest.py should work.
Ubuntu Server 14.04 | Domoticz v3.8153 | RFXtrx433E | Z-Wave Aeotec Z-Stick S2
Frontpage | Sonos PHP | Dark th3me | Sony Bravia Python plugin | Sonos Python plugin

markcame
Posts: 34
Joined: Wednesday 07 December 2016 20:13
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Sony Bravia TV

Post by markcame » Thursday 10 August 2017 22:11

markcame wrote:
Thursday 10 August 2017 16:04
After installation of the lastest stable version of domoticz i'm able to run the plugin without crash, but when i try to reboot or restart the service domoticz.sh it fail and became active(exited) and the web interface goes offline.
if i disable the hardware prior to make a restart and re-enable the hardware after all will be again up and running.
all is 100% reproducible on my system

It seems related with the creation of the object _tv = BraviaRC in onStart(self). but i have no idea how to fix it

I'v also coded the support for the cookie if you want can be integrated in the plugin
@G3rard

At the end the version with the cookie is fully functional with auto renew based on access forbidden issued by tv, the first pairing must be done manually with a shell script then if you put "Cookie" without quote as PSK the plugin switch automotically to Cookie method.
if you want i cann pull on github

i didn't understand why both your and my version instead crash for segmentation only if the plugin is enabled and you restart the service or rebbot .
if you enable the plugin after domoticz starting no more crash for segmentatation.
the function called by plugin init i assume is the same if you restart or enable the hardware, do you agree ?
thanks
Marco

User avatar
G3rard
Posts: 827
Joined: Wednesday 04 March 2015 23:15
Target OS: Linux
Domoticz version: V3.8153
Location: The Netherlands
Contact:

Re: Python plugin: Sony Bravia TV

Post by G3rard » Thursday 10 August 2017 23:34

@markcame,
Indeed strange that your plugin crashes on restart. Here it does not happen (RPi3 and Ubuntu Server).
Does it make a difference if the TV is on or off when restarting?
If you think it is related to _tv = BraviaRC maybe you can try this in the onStart().

Code: Select all

try:
    _tv = BraviaRC(Parameters["Address"], Parameters["Mode1"], Parameters["Mode2"]) #IP, PSK, MAC
except Exception as err:
    Domoticz.Error("Something went wrong (" +  str(err) + ")")
You can make a pull request on Github, please do that on the development branch.
Last edited by G3rard on Friday 11 August 2017 0:02, edited 1 time in total.
Ubuntu Server 14.04 | Domoticz v3.8153 | RFXtrx433E | Z-Wave Aeotec Z-Stick S2
Frontpage | Sonos PHP | Dark th3me | Sony Bravia Python plugin | Sonos Python plugin

markcame
Posts: 34
Joined: Wednesday 07 December 2016 20:13
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Sony Bravia TV

Post by markcame » Thursday 10 August 2017 23:57

no the status of tv makes no difference
i've tried to catch the exception but was not triggered, the crash happens during the load of the plugin if it is enabled
sometimes gives segmentation fault, somentimes not just crash, and somentimes Fatal python error

Code: Select all

pi@raspberrypi:~/domoticz$ sudo ./domoticz
2017-08-10 23:44:52.424  Domoticz V3.8153 (c)2012-2017 GizMoCuz
2017-08-10 23:44:52.425  Build Hash: 494fff7, Date: 2017-07-30 12:19:41
2017-08-10 23:44:52.426  System: Raspberry Pi
2017-08-10 23:44:52.427  Startup Path: /home/pi/domoticz/
2017-08-10 23:44:52.476  Sunrise: 06:20:00 SunSet:20:38:00
2017-08-10 23:44:52.477  EventSystem: reset all events...
2017-08-10 23:44:52.620  PluginSystem: Started, Python version '3.4.2'.
2017-08-10 23:44:52.637  Active notification Subsystems: email, kodi, pushover (3/12)
2017-08-10 23:44:52.640  WebServer(HTTP) started on address: :: with port 8080
2017-08-10 23:44:52.651  WebServer(SSL) started on address: :: with port 443
2017-08-10 23:44:52.655  Proxymanager started.
2017-08-10 23:44:52.658  Starting shared server on: :::6144
2017-08-10 23:44:52.659  TCPServer: shared server started...
2017-08-10 23:44:52.659  RxQueue: queue worker started...
2017-08-10 23:44:54.667  Kodi: Started
2017-08-10 23:44:54.668  (evohome) Worker started...
2017-08-10 23:44:54.668  EventSystem: reset all events...
2017-08-10 23:44:54.671  EventSystem: reset all device statuses...
2017-08-10 23:44:54.769  Kodi: (Mediacenter Salotto) Starting thread.
2017-08-10 23:44:54.771  Kodi: (Mediacenter Salotto) Connected to '192.168.2.37:9090'.
2017-08-10 23:44:54.869  Kodi: Starting I/O service thread.
2017-08-10 23:44:54.983  PluginSystem: Entering work loop.
2017-08-10 23:44:55.613  (Sony Salotto) Initialized version 1.2, author 'G3rard'
2017-08-10 23:44:55.664  RFXCOM: Using serial port: /dev/ttyUSB-RFX433
2017-08-10 23:44:55.667  MySensors: trying to connect to: 192.168.2.36:5003
2017-08-10 23:44:55.672  (Sony Salotto) Debug log level set to: 'true'.
2017-08-10 23:44:55.672  (Sony Salotto) 'Port':'0'
2017-08-10 23:44:55.672  (Sony Salotto) 'Mode6':'Debug'
2017-08-10 23:44:55.672  (Sony Salotto) 'Key':'sony'
2017-08-10 23:44:55.672  (Sony Salotto) 'Address':'192.168.2.85'
2017-08-10 23:44:55.673  (Sony Salotto) 'Name':'Sony Salotto'
2017-08-10 23:44:55.673  (Sony Salotto) 'HomeFolder':'/home/pi/domoticz/plugins/sony/'
2017-08-10 23:44:55.673  (Sony Salotto) 'Version':'1.2'
2017-08-10 23:44:55.673  (Sony Salotto) 'Author':'G3rard'
2017-08-10 23:44:55.673  (Sony Salotto) 'Mode2':'3C:07:71:D4:AB:BC'
2017-08-10 23:44:55.673  (Sony Salotto) 'HardwareID':'12'
2017-08-10 23:44:55.673  (Sony Salotto) 'Mode1':'Cookie'
Fatal Python error: GC object already tracked

Current thread 0x2017-08-10 23:44:55.674  (Sony Salotto) 'Mode5':'30'
75826440 (most recent call first):
  File 2017-08-10 23:44:55.674  (Sony Salotto) 'Mode3':'Volume'
"/ho2017-08-10 23:44:55.674  (Sony Salotto) Device count: 5
me/pi/domo2017-08-10 23:44:55.674  (Sony Salotto) Device:           1 - ID: 237, Name: 'Sony Salotto - Status', nValue: 0, sValue: 'Off'
ticz2017-08-10 23:44:55.674  (Sony Salotto) Internal ID:     '237'
/plu2017-08-10 23:44:55.674  (Sony Salotto) External ID:     '000C0001'
gins2017-08-10 23:44:55.674  (Sony Salotto) Device Name:     'Sony Salotto - Status'
/son2017-08-10 23:44:55.674  (Sony Salotto) Device nValue:    0
y/p2017-08-10 23:44:55.674  (Sony Salotto) Device sValue:   'Off'
lugi2017-08-10 23:44:55.674  (Sony Salotto) Device LastLevel: 0
n.py"2017-08-10 23:44:55.675  (Sony Salotto) Device:           2 - ID: 238, Name: 'Sony Salotto - Volume', nValue: 0, sValue: '10'
, line 65 in o2017-08-10 23:44:55.675  (Sony Salotto) Internal ID:     '238'
nSta2017-08-10 23:44:55.675  (Sony Salotto) External ID:     '000C0002'
rt
  File 2017-08-10 23:44:55.675  (Sony Salotto) Device Name:     'Sony Salotto - Volume'
"/h2017-08-10 23:44:55.675  (Sony Salotto) Device nValue:    0
ome/2017-08-10 23:44:55.675  (Sony Salotto) Device sValue:   '10'
pi/2017-08-10 23:44:55.675  (Sony Salotto) Device LastLevel: 10
domot2017-08-10 23:44:55.675  (Sony Salotto) Device:           3 - ID: 239, Name: 'Sony Salotto - Source', nValue: 0, sValue: '0'
icz/2017-08-10 23:44:55.675  (Sony Salotto) Internal ID:     '239'
plug2017-08-10 23:44:55.676  (Sony Salotto) External ID:     '000C0003'
ins/2017-08-10 23:44:55.676  (Sony Salotto) Device Name:     'Sony Salotto - Source'
sony2017-08-10 23:44:55.676  (Sony Salotto) Device nValue:    0
/pl2017-08-10 23:44:55.676  (Sony Salotto) Device sValue:   '0'
ugin2017-08-10 23:44:55.676  (Sony Salotto) Device LastLevel: 40
.py", line 2017-08-10 23:44:55.676  (Sony Salotto) Device:           4 - ID: 240, Name: 'Sony Salotto - Control', nValue: 0, sValue: '0'
370 in on2017-08-10 23:44:55.676  (Sony Salotto) Internal ID:     '240'
Star2017-08-10 23:44:55.676  (Sony Salotto) External ID:     '000C0004'
t
2017-08-10 23:44:55.676  (Sony Salotto) Device Name:     'Sony Salotto - Control'
2017-08-10 23:44:55.676  (Sony Salotto) Device Name:     'Sony Salotto - Control'
2017-08-10 23:44:55.676  (Sony Salotto) Device nValue:    0
or

Code: Select all

2017-08-10 23:07:38.279  (Sony Salotto) Initialized version 1.2, author 'G3rard'
2017-08-10 23:07:38.329  RFXCOM: Using serial port: /dev/ttyUSB-RFX433
2017-08-10 23:07:38.336  MySensors: trying to connect to: 192.168.2.36:5003
2017-08-10 23:07:38.337  (Sony Salotto) Debug log level set to: 'true'.
2017-08-10 23:07:38.337  (Sony Salotto) 'HomeFolder':'/home/pi/domoticz/plugins/                                              sony/'
Fatal Python error: GC object already tracked

Current thread 0x70cff440 (most recent call first):
  File "<frozen importlib._bootstrap>", line 656 in _compile_bytecode
  File "<frozen importlib._bootstrap>", line 1570 in get_code
  File "<frozen importlib._bootstrap>", line 1471 in exec_module
  File "<frozen importlib._bootstrap>", line 1129 in _exec
  File "<frozen importlib._bootstrap>", line 1200 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 2226 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 2237 in _find_and_load
  File "/usr/lib/python3.4/site.py", line 78 in <module>
  File "<frozen importlib._bootstrap>", line 321 in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1471 in exec_module
  File "<frozen importlib._bootstrap>", line 1129 in _exec
  File "<frozen importlib._bootstrap>", line 1200 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 2226 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 2237 in _find_and_load
do you suggest other trials ?

User avatar
G3rard
Posts: 827
Joined: Wednesday 04 March 2015 23:15
Target OS: Linux
Domoticz version: V3.8153
Location: The Netherlands
Contact:

Re: Python plugin: Sony Bravia TV

Post by G3rard » Friday 11 August 2017 0:08

Do you have other Python plugins which work properly on restart?

But I am afraid I can't help you with this. Maybe @Dnpwwo can have a look at it?
Ubuntu Server 14.04 | Domoticz v3.8153 | RFXtrx433E | Z-Wave Aeotec Z-Stick S2
Frontpage | Sonos PHP | Dark th3me | Sony Bravia Python plugin | Sonos Python plugin

markcame
Posts: 34
Joined: Wednesday 07 December 2016 20:13
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Sony Bravia TV

Post by markcame » Friday 11 August 2017 0:11

G3rard wrote:
Friday 11 August 2017 0:08
Do you have other Python plugins which work properly on restart?

But I am afraid I can't help you with this. Maybe @Dnpwwo can have a look at it?
No at the moment i didn't have other plugin if you can suggest another plugin that i can try to test if it survives at restart

User avatar
G3rard
Posts: 827
Joined: Wednesday 04 March 2015 23:15
Target OS: Linux
Domoticz version: V3.8153
Location: The Netherlands
Contact:

Re: Python plugin: Sony Bravia TV

Post by G3rard » Friday 11 August 2017 0:19

Well that depends on the hardware you have ;)

But you could try https://github.com/ffes/domoticz-buienradar. That is a Dutch weather information plugin, but you could use that to see if it handles a restart.
Ubuntu Server 14.04 | Domoticz v3.8153 | RFXtrx433E | Z-Wave Aeotec Z-Stick S2
Frontpage | Sonos PHP | Dark th3me | Sony Bravia Python plugin | Sonos Python plugin

markcame
Posts: 34
Joined: Wednesday 07 December 2016 20:13
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Sony Bravia TV

Post by markcame » Friday 11 August 2017 15:18

G3rard wrote:
Friday 11 August 2017 0:19
Well that depends on the hardware you have ;)

But you could try https://github.com/ffes/domoticz-buienradar. That is a Dutch weather information plugin, but you could use that to see if it handles a restart.
Finally i find the root cause because also the buienradar plugin does not survive @ domoticz restart.

I have disabled dzVents from domoticz setting and now all is up running and survive to reboot/restart, i don't know why it happens.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests