Page 1 of 9

Python Plugin: Samsung TV

Posted: Friday 24 March 2017 23:11
by zak45
Something I wrote for myself but think could be nice to share with community.
this is the samsungctl implementation into Domoticz.
link to wiki page : https://www.domoticz.com/wiki/Plugins/SamsungTV.html

Re: Python Plugin: Samsung TV

Posted: Monday 27 March 2017 22:11
by G3rard
Great job! Good to see that more and more Python plugins are being developed.

I am currently working on a plugin for Sony Bravia TV. Currently some issues with importing modules, but hope to fix that soon.

Re: Python Plugin: Samsung TV

Posted: Monday 27 March 2017 22:42
by freijn
Hey Great Job !!!

Will give it a try next days

Thanks!!

Re: Python Plugin: Samsung TV

Posted: Monday 27 March 2017 23:04
by zak45
Thanks to all.
This plugin framework has opened more possibility...
Central repository is missing to store/find them, but this is maybe on project ??!!

Re: Python Plugin: Samsung TV

Posted: Monday 27 March 2017 23:12
by deennoo
Real great job !

Re: Python Plugin: Samsung TV

Posted: Thursday 30 March 2017 21:36
by Bob123bob
Can someone tell me if you succeed using raspberry domoticz image ?
I can install the plugin but when a add hardware I got
2017-03-30 20:47:29.152 Error: (SamsungTV) failed to load 'plugin.py', Python Path used was '/home/pi/domoticz/plugins/SamsungTV/:/usr/lib/python3.4/:/usr/lib/python3.4/plat-arm-linux-gnueabihf:/usr/lib/python3.4/lib-dynload'.
2017-03-30 20:47:29.152 Error: (Samsung TV) Module Import failed, exception: 'ImportError'
2017-03-30 20:47:29.152 Error: (Samsung TV) Module Import failed: ' Name: samsungctl'
2017-03-30 20:48:30.175 Error: Samsung TV hardware (12) thread seems to have ended unexpectedly
2017-03-30 20:49:00.192 Error: Samsung TV hardware (12) thread seems to have ended unexpectedly
2017-03-30 20:49:30.200 Error: Samsung TV hardware (12) thread seems to have ended unexpectedly
2017-03-30 20:50:00.782 Error: Samsung TV hardware (12) thread seems to have ended unexpectedly
I'm running Domoticz beta 3.7123 on Rpi2 and I have python 2.7, python3 and python 3.4 installed
default python is 2.7.9

Code: Select all

python -V
Python 2.7.9

Re: Python Plugin: Samsung TV

Posted: Thursday 30 March 2017 22:07
by zak45
all is related to the fact several python version.
for help you can look here, similar case :

http://www.domoticz.com/wiki/Plugins/BroadlinkRM2.html

Re: Python Plugin: Samsung TV

Posted: Saturday 01 April 2017 8:35
by Bob123bob
zak45 wrote:all is related to the fact several python version.
for help you can look here, similar case :

http://www.domoticz.com/wiki/Plugins/BroadlinkRM2.html
Thanks It's working now

Need to copy package to use python3.4 using

Code: Select all

sudo cp -r /usr/local/lib/python3.4/dist-packages/samsungctl/ /usr/lib/python3.4/

Re: Python Plugin: Samsung TV

Posted: Tuesday 18 April 2017 22:54
by felix63
Hi,

I'm stuck. After

Code: Select all

sudo cp -r /usr/local/lib/python3.4/dist-packages/samsungctl/ /usr/lib/python3.4/
the switches are added.

Code: Select all

2017-04-18 22:51:48.704 Error: (SamsungTV) 'onCommand' failed 'ImportError'.
2017-04-18 22:51:48.704 Error: (SamsungTV) ----> Line 159 in /home/pi/domoticz/plugins/samsungTV/plugin.py, function onCommand
2017-04-18 22:51:48.704 Error: (SamsungTV) ----> Line 287 in /home/pi/domoticz/plugins/samsungTV/plugin.py, function SamsungSend
2017-04-18 22:51:48.704 Error: (SamsungTV) ----> Line 10 in /usr/lib/python3.4/samsungctl/remote.py, function __init__
2017-04-18 22:51:48.704 Error: (SamsungTV) ----> Line 13 in /usr/lib/python3.4/samsungctl/remote_websocket.py, function __init__
Any thoughts what I could do? Calling samsungctl directly works.

Cheers,
Lex

Re: Python Plugin: Samsung TV

Posted: Tuesday 18 April 2017 23:20
by zak45
The error is line 13: import websocket
websocket is required for new Samsung TV.
if the command line is working, do you have put right settings into Domoticz Hw configuration page ?

Re: Python Plugin: Samsung TV

Posted: Wednesday 19 April 2017 1:06
by felix63
Thanks. Got it working now. New challenge. I found this command

Code: Select all

wakeonlan -i 192.168.99.255 F8:3F:51:DE:33:33
to wake up my tv. But when I use this in the parameters for your plugin it doesn't work. I also tried adding a bash script containing the same command and calling that. But that also doesn't work.

How do I call a shell command to do a wakeonlan?

Thanks for your help!

btw
didn't copy the files but used symbolic links...

Code: Select all

sudo ln -s /usr/local/lib/python3.4/dist-packages/samsungctl/ /usr/lib/python3.4/samsungctl
sudo ln -s /usr/local/lib/python3.4/dist-packages/websocket/ /usr/lib/python3.4/websocket
sudo ln -s /usr/local/lib/python3.4/dist-packages/six.py /usr/lib/python3.4/six.py

Re: Python Plugin: Samsung TV

Posted: Wednesday 19 April 2017 12:59
by zak45
nice to see it's working.

for WOL

I would do it in this way:
/full/path/toyour/wol.sh
wol.sh need to be executable, I supose.
into it:
/full/path/toyour/wakeonlan -i 192.168.99.255 F8:3F:51:DE:33:33

/full/path/toyour/ is here only as example.

Re: Python Plugin: Samsung TV

Posted: Thursday 20 April 2017 1:20
by felix63
Sorry. Thanks for the suggestion but it doesn't work. If I send the command from the terminal it works. When I enter it in the settings for your plugin Nothing happens....

Strange!

Re: Python Plugin: Samsung TV

Posted: Thursday 20 April 2017 17:28
by zak45
so.. put debug mode on and post the log.

Re: Python Plugin: Samsung TV

Posted: Saturday 13 May 2017 8:56
by mKotek
I have a 2016+ SamsungTV. I have installed the samsungctl and websocket plugin and everything works from command line.
I have also copied samsunctl and websocket to /usr/local/lib/python3.5/ and plugin started working in Domoticz, meaning the 4 devices have been created.
But the current state of settings is shown incorrectly.
I am not getting any errors in Domoticz log, but the following suggests, the settings are somehow wrong:

Code: Select all

2017-05-13 08:43:33.520 (SamsungTV Dom) Calling message handler 'onHeartbeat'.
2017-05-13 08:43:33.523 (SamsungTV Dom) Delaynumber : 7
2017-05-13 08:43:33.523 (SamsungTV Dom) isAlive status :False
What should be configured as port in the plugin settings for websockets? I have tried 8001, but then I got errors, when I have it at default 55000 I do not get any errors, but it does not work. If I try to initiate any command on the created devices, I get:

Code: Select all

2017-05-13 08:55:43.166 (SamsungTV Dom) Calling message handler 'onCommand'.
2017-05-13 08:55:43.166 (SamsungTV Dom) onCommand called for Unit 1: Parameter 'Off', Level: 0, Connected: False
2017-05-13 08:55:43.167 Error: (SamsungTV Dom) Not Connected
I have updated port again to 8001 (websocket) and now I am getting the status for the TV, but the following is logged in the Domoticz log:

Code: Select all

2017-05-13 09:10:47.855 Error: (SamsungTV Dom) 'onStart' failed 'ImportError'.
2017-05-13 09:10:47.855 Error: (SamsungTV Dom) ----> Line 127 in /home/pi/domoticz/plugins/samsungtv/plugin.py, function onStart
2017-05-13 09:10:47.855 Error: (SamsungTV Dom) ----> Line 287 in /home/pi/domoticz/plugins/samsungtv/plugin.py, function SamsungSend
2017-05-13 09:10:47.855 Error: (SamsungTV Dom) ----> Line 10 in /usr/local/lib/python3.5/samsungctl/remote.py, function __init__
2017-05-13 09:10:47.855 Error: (SamsungTV Dom) ----> Line 13 in /usr/local/lib/python3.5/samsungctl/remote_websocket.py, function __init__
2017-05-13 09:10:47.855 Error: (SamsungTV Dom) ----> Line 22 in /usr/local/lib/python3.5/websocket/__init__.py, function
2017-05-13 09:10:47.855 Error: (SamsungTV Dom) ----> Line 26 in /usr/local/lib/python3.5/websocket/_abnf.py, function
Please let me know, what might be a problem (TV is on during tests of course, as I am using WiFi connection, so WoL does not work).

Re: Python Plugin: Samsung TV

Posted: Saturday 13 May 2017 14:10
by zak45
Hi,
do not have recent Samsung TV so not able to test on my side.
What I know: port should be 8001 and websocket-client module installed.

Re: Python Plugin: Samsung TV

Posted: Saturday 13 May 2017 15:41
by DennisD
@mKotek,

Almost sure it is a python issue (wrong version or default version), i 2 have the same errors as you have with same websocket-client module. I to have similair problems with the wan ip plugin.

Python Plugin: Samsung TV

Posted: Sunday 14 May 2017 15:29
by kingoifsnake74
Please help. This linux noob is getting frustrated.
Synology diskstation ds216j domoticz DSM 6.1.1-15101 Update 1 python module 0109 and python3.5.1.

I installed by ssh/root the samsungctl mandatory and the websocket. In domoticz i find te samsung under hardware and fill in as supposed. But the additional switches won't install. I chmodded 777 and a +x just incase this was the problem.
In domoticz i get the error Error: (SamsungTV) failed to load 'plugin.py', Python Path used was '/usr/local/domoticz/var/plugins/samsungtv/:/volume1/@appstore/py3k/usr/local/lib/python35.zip:/volume1/@appstore/py3k/usr/local/lib/python3.5/:/volume1/@appstore/py3k/usr/local/lib/python3.5/plat-linux:/volume1/@appstore/py3k/usr/local/lib/python3.5/lib-dynload'.

I tried a lot and seems like its a python3 location problem as i read above. Where do i have to install the samsungctl , did it in usr/local/domoticz/var/plugins/samsungtv

I did a sudo python3 -m pip install and it all went well.

Amang trying thought it could be that pip needs a reinstall tried to curl and also not working. Could someone set out the steps one by one so i cam start over or is it an easy problem to fix? thanx all

Re: Python Plugin: Samsung TV

Posted: Sunday 14 May 2017 16:14
by EdwinK
When I try to run this (from the WIKI page)

Code: Select all

samsungctl -i --host 192.168.0.106
Traceback (most recent call last):
  File "/bin/samsungctl", line 9, in <module>
    load_entry_point('samsungctl==0.6.0', 'console_scripts', 'samsungctl')()
  File "/usr/lib/python2.7/site-packages/samsungctl/__main__.py", line 93, in main
    config = _read_config()
  File "/usr/lib/python2.7/site-packages/samsungctl/__main__.py", line 37, in _read_config
    except FileNotFoundError:
NameError: global name 'FileNotFoundError' is not defined
I installd both samsungctl and the websocketclient as instructed in the WIKI. My tv is a pre-2016 model, and it has a static IP. It is a UE50J6200 model

Re: Python Plugin: Samsung TV

Posted: Sunday 14 May 2017 17:15
by DennisD
@EdKo66
Change the installed location from python2.7 to 3.4 (or higher) because the "FileNotFoundError" is not found in python 2.7

So change sudo pip install samsungctl to sudo pip3 install samsungctl and sudo pip install websocket-client to sudo pip3 install websocket-client