Python Plugin: Samsung TV

Python and python framework

Moderator: leecollings

Post Reply
zak45
Posts: 952
Joined: Sunday 22 January 2017 11:37
Target OS: Windows
Domoticz version: V2024.4
Contact:

Python Plugin: Samsung TV

Post 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
User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

Re: Python Plugin: Samsung TV

Post 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.
Not using Domoticz anymore
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: Python Plugin: Samsung TV

Post by freijn »

Hey Great Job !!!

Will give it a try next days

Thanks!!
zak45
Posts: 952
Joined: Sunday 22 January 2017 11:37
Target OS: Windows
Domoticz version: V2024.4
Contact:

Re: Python Plugin: Samsung TV

Post 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 ??!!
deennoo
Posts: 784
Joined: Wednesday 10 December 2014 13:06
Target OS: Linux
Domoticz version: beta
Location: Bordeaux France
Contact:

Re: Python Plugin: Samsung TV

Post by deennoo »

Real great job !
Domoticz stable 3.5877 for real & Domoticz beta for test
Rfxtrxe / RFLink / Milight / Yeelight / Tasmota / MQTT / BLE / Zigate
http://domo-attitude.fr
Bob123bob
Posts: 31
Joined: Monday 09 March 2015 7:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Samsung TV

Post 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
zak45
Posts: 952
Joined: Sunday 22 January 2017 11:37
Target OS: Windows
Domoticz version: V2024.4
Contact:

Re: Python Plugin: Samsung TV

Post 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
Bob123bob
Posts: 31
Joined: Monday 09 March 2015 7:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Samsung TV

Post 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/
User avatar
felix63
Posts: 244
Joined: Monday 07 December 2015 9:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: Gouda
Contact:

Re: Python Plugin: Samsung TV

Post 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
zak45
Posts: 952
Joined: Sunday 22 January 2017 11:37
Target OS: Windows
Domoticz version: V2024.4
Contact:

Re: Python Plugin: Samsung TV

Post 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 ?
User avatar
felix63
Posts: 244
Joined: Monday 07 December 2015 9:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: Gouda
Contact:

Re: Python Plugin: Samsung TV

Post 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
zak45
Posts: 952
Joined: Sunday 22 January 2017 11:37
Target OS: Windows
Domoticz version: V2024.4
Contact:

Re: Python Plugin: Samsung TV

Post 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.
User avatar
felix63
Posts: 244
Joined: Monday 07 December 2015 9:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: Gouda
Contact:

Re: Python Plugin: Samsung TV

Post 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!
zak45
Posts: 952
Joined: Sunday 22 January 2017 11:37
Target OS: Windows
Domoticz version: V2024.4
Contact:

Re: Python Plugin: Samsung TV

Post by zak45 »

so.. put debug mode on and post the log.
mKotek
Posts: 68
Joined: Wednesday 30 December 2015 23:54
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Poland
Contact:

Re: Python Plugin: Samsung TV

Post 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).
Michal 'Kotek', greetings from Poland. Zapraszam na mój blog o automatyce domowej po polsku: http://www.ukotka.com.
zak45
Posts: 952
Joined: Sunday 22 January 2017 11:37
Target OS: Windows
Domoticz version: V2024.4
Contact:

Re: Python Plugin: Samsung TV

Post 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.
DennisD
Posts: 51
Joined: Friday 18 September 2015 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Samsung TV

Post 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.
kingoifsnake74
Posts: 14
Joined: Saturday 06 May 2017 11:41
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Python Plugin: Samsung TV

Post 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
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Python Plugin: Samsung TV

Post 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
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
DennisD
Posts: 51
Joined: Friday 18 September 2015 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Samsung TV

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest