ape / samsungctl Goto Github PK
View Code? Open in Web Editor NEWRemote control Samsung televisions via a TCP/IP connection
License: MIT License
Remote control Samsung televisions via a TCP/IP connection
License: MIT License
Legacy TVs support text being sent through the remote. I wonder if that is also possible with the new models. Maybe through some other params in this request:
payload = json.dumps({
"method": "ms.remote.control",
"params": {
"Cmd": "Click",
"DataOfCmd": key,
"Option": "false",
"TypeOfRemote": "SendRemoteKey"
}
})
The following options should be added:
-q
to suppress any non-fatal output-v
enables info ouput-vv
enables debug outputHello,
I am using KEY_POWERON to switch on the tv. But, command is not reaching to the TV. How can i turn ON the TV?
Thank you,
Gowtham M
When I start the interactive mode and when I choose to show the menu, it wil show it on de screen of my tv. But after about 30 seconds and entering a new command it's not responding anymore and the console gets closed with the message Error: Broken pipe
I can start the interactive mode again and the first few commands are working correctly but after 30 seconds I get the same error again.
System: Raspberry Pi 3
Tv: Samsung UE55KS7000
samsungctl 0.7.0
[Edit]
I notice I have the same issue as #16. After a while I have to allow again before I can connect
AUR is a community based application repository for Arch Linux. PKGBUILD should be created and uploaded there.
The project should include an interactive remote control application that is based on the samsungctl library.
Im running on windows and followed your instructions:
I get the following error from 2.
Traceback (most recent call last):
File "C:\Users\xbmc\AppData\Local\Programs\Python\Python36-32\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Users\xbmc\AppData\Local\Programs\Python\Python36-32\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\xbmc\AppData\Local\Programs\Python\Python36-32\lib\site-packages\samsungctl\__main__.py", line 11, in <module>
from . import interactive
File "C:\Users\xbmc\AppData\Local\Programs\Python\Python36-32\lib\site-packages\samsungctl\interactive.py", line 1, in <module>
import curses
File "C:\Users\xbmc\AppData\Local\Programs\Python\Python36-32\lib\curses\__init__.py", line 13, in <module>
from _curses import *
ModuleNotFoundError: No module named '_curses'
What am i doing wrong?
Python version 3.6.0
Hi!
When I type command sudo python3 -m samsungctl --host 192.168.1.110 --port 8001 KEY_MUTE --method websocket
in my terminal I see this error:
Error: Operation now in progress
I think this is from web socket, but do not know workaround. Do not see this message in your code.
My TV is H6640.
Currently, either --interactive
or some specified keys are required. It should be possible to only test the connection without sending any keys, too.
I have a UN65KS850 (2016 curved model) that appears to use websockets. When I try to use this tool, it throws:
python -m samsungctl --host <IPADDRESS> --method websocket KEY_POWER
File "samsungctl/remote.py", line 10, in __init__
self.remote = RemoteWebsocket(config)
File "samsungctl/remote_websocket.py", line 25, in __init__
self._read_response()
File "samsungctl/remote_websocket.py", line 67, in _read_response
raise exceptions.UnhandledResponse(response)
samsungctl.exceptions.UnhandledResponse: {u'event': u'ms.channel.timeOut'}
I've tried specifying other flags such as ID and changing the keycode, but it makes no difference. I also don't receive a request on my TV asking about allowing access (as others have implied may happen).
Output of wireshark:
Not shown: 65522 closed ports
PORT STATE SERVICE
7676/tcp open imqbrokerd
7678/tcp open unknown
8000/tcp open http-alt
8001/tcp open vcom-tunnel
8002/tcp open teradataordbms
8080/tcp open http-proxy
8187/tcp open unknown
9119/tcp open unknown
9197/tcp open unknown
9999/tcp open abyss
10443/tcp open unknown
15500/tcp open unknown
49326/tcp open unknown
tried to set-up my tv via homeassistant but got no luck, so i tried to use samsungctl directly from my pc to see whats wrong.
nmap output:
nmap -p 1-65535 192.168.99.20
Starting Nmap 7.40 ( https://nmap.org ) at 2017-05-11 11:41 CEST
Nmap scan report for 192.168.99.20
Host is up (0.0034s latency).
Not shown: 65529 closed ports
PORT STATE SERVICE
7676/tcp open imqbrokerd
8000/tcp open http-alt
8001/tcp open vcom-tunnel
8080/tcp open http-proxy
8443/tcp open https-alt
15500/tcp open unknown
looks like this tv is using 8001 (websockets) - telnet to this ip,port works.
so i tried samsungctl:
samsungctl --host 192.168.99.20 --method websocket KEY_MUTE
(got no output on the console - so it shall be ok)
but on the wireshark i see that it is not.
mypc -> tv
GET /api/v2/channels/samsung.remote.control?name=cmVtb3Rl HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Host: 192.168.99.20:8001
Origin: http://192.168.99.20:8001
Sec-WebSocket-Key: u5Y00EnwvXkhM4CqnAGJVQ==
Sec-WebSocket-Version: 13
tv -> my pc
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: xAXj7aiUcGOEkRzP+LaFtHVICqs=
tv->my pc(via websocket)
{"event":"ms.channel.connect","data":{"id":"43c8abe0-1ddc-11b2-8e9e-eb818775dcdb","clients":[{"id":"43c8abe0-1ddc-11b2-8e9e-eb818775dcdb","connectTime":4375967,"attributes":{"name":"cmVtb3Rl"},"isHost":false}]}}
mypc->tv (via websocket)
{"params": {"Cmd": "Click", "Option": "false", "TypeOfRemote": "SendRemoteKey", "DataOfCmd": "KEY_VOLUP"}, "method": "ms.remote.control"}
tv->mypc (via websocket)
{"event":"ms.error","data":{"message":"unrecognized method value : ms.remote.control"}}
mypc->tv (via websocket)
connection close (status code: normal closure(1000)
tv->mypc (via websocket)
connection close (status code: normal closure(1000)
got any idea what could be wrong? i have something disabled on my tv? or h series uses some different protocol? - i can test something more if needed
Currently, --interactive
ignores any specified keys. The keys should be sent before going to the interactive mode.
I'm trying to use samsungctl to automate some common tasks. However, most tasks relevant to me involves the smart hub, and I can't find or figure out the key code for that. Does anyone know it, or is anyone able to figure it out by sniffing the network traffic?
Hi there,
I get the authentication message on TV each time I use samsungctl.
I have to agree it, afterwards the sent key-command is executed.
Can you tell how to solve this problem please?
Hi,
I'm attempting to port this over to c# to eventually use in homeseer for my 2016 UN55KU6270.
I'm able to get a connection and authenticate with the tv. However, after sending the JSON I'm getting the following error from the tv:
{"event":"ms.error","data":{"message":"missing method field from message"}}
I'm sending the following JSON across:
"{\"method\":\"ms.remote.control\",\"params\":\"{\"Cmd\":\"Click\",\"DataOfCmd\":\"KEY_MENU\",\"Option\":\"false\",\"TypeOfRemote\":\"SendRemoteKey\"}\"}"
Any clue what I'm doing wrong here?
If verbose option is set there should be detailed log messages.
im trying to remotely fire off events but im getting ms.channel.timeOut each time. Port 8001 is open so i can connect using websockets. Is this a known issue?
Once installed the current pip version (0.3.0) as well as the git Master triggers an undefined error if the config is not manually created.
$ samsungctl
Traceback (most recent call last):
File "/usr/local/bin/samsungctl", line 9, in <module>
load_entry_point('samsungctl===0.3.0-git', 'console_scripts', 'samsungctl')()
File "build/bdist.linux-x86_64/egg/samsungctl/__main__.py", line 88, in main
File "build/bdist.linux-x86_64/egg/samsungctl/__main__.py", line 36, in _read_config
NameError: global name 'FileNotFoundError' is not defined
Once the config file is created, this particular error disappears.
Have python3 and websocket installed.
Below is my conf and the error from samsungctl - any advice how to solve?
pi@raspberrypi ~ $ samsungctl --host 192.168.1.24 KEY_VOLUP
Traceback (most recent call last):
File "/usr/local/bin/samsungctl", line 9, in <module>
load_entry_point('samsungctl==0.6.0', 'console_scripts', 'samsungctl')()
File "/usr/local/lib/python3.2/dist-packages/samsungctl/__main__.py", line 101, in main
with Remote(config) as remote:
File "/usr/local/lib/python3.2/dist-packages/samsungctl/remote.py", line 10, in __init__
self.remote = RemoteWebsocket(config)
File "/usr/local/lib/python3.2/dist-packages/samsungctl/remote_websocket.py", line 21, in __init__
self.connection = websocket.WebSocket()
TypeError: __init__() takes exactly 4 arguments (1 given)
My conf:
pi@raspberrypi ~ $ cat .config/samsungctl.conf
{
"name": "samsungctl",
"description": "PC",
"id": "",
"method": "websocket",
"port": 7676,
"timeout": 0
}
The controlled TV sends return messages with the TCP connection. These messages should be handled.
Some cases:
Show proper error messages if the connection cannot be established.
Some cases:
This is 2014 model, so try the traditional way with port 55000. Seems the TV reject to setup the TCP
Try the websocket method. Installed websocket with command "sudo pip3 install websocket-client". When restart HA, got the error below:
hass[17816]: 2017-08-31 13:25:10 ERROR (MainThread) [homeassistant.helpers.entity] Update for media_player.samsung_tv_remote fails
hass[17816]: Traceback (most recent call last):
hass[17816]: File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 225, in async_update_ha_state
hass[17816]: yield from self.hass.async_add_job(self.update)
hass[17816]: File "/usr/lib/python3.5/asyncio/futures.py", line 380, in iter
hass[17816]: yield self # This tells Task to wait for completion.
hass[17816]: File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
hass[17816]: future.result()
hass[17816]: File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
hass[17816]: raise self._exception
hass[17816]: File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
hass[17816]: result = self.fn(*self.args, **self.kwargs)
hass[17816]: File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/media_player/samsungtv.py", line 121, in update
hass[17816]: return self.send_key('KEY')
hass[17816]: File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/media_player/samsungtv.py", line 134, in send_key
hass[17816]: self.get_remote().control(key)
hass[17816]: File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/media_player/samsungtv.py", line 127, in get_remote
hass[17816]: self._remote = self._remote_class(self._config)
hass[17816]: File "/srv/homeassistant/lib/python3.5/site-packages/samsungctl/remote.py", line 10, in init
hass[17816]: self.remote = RemoteWebsocket(config)
hass[17816]: File "/srv/homeassistant/lib/python3.5/site-packages/samsungctl/remote_websocket.py", line 13, in init
hass[17816]: import websocket
hass[17816]: ImportError: No module named 'websocket'
did I install the websocket correctly?
Currently the interactive mode prints the key mappings, but it should also show the technical key codes (e.g. KEY_VOLDOWN).
Hi friends,
I want to set my TV volume to specific value like "Volume 40, Volume 55". How can we set like, how we are setting for channels.
@nunofgs @Ape First, samsungctl has been working great for me with my Samsung UN24M4500AF. So, this isn't really a question about the samsungctl project. Rather, it's a question regarding my Samsung TV. KEY_HDMI and KEY_HDMI1 etc. do not switch to the specified HDMI. Instead, KEY_HDMI cycles through the input sources. Do you know if this functionality is common among many Samsung TVs, or does it only apply to few Samsung TVs?
Thank you!
Hello, I have a KS8000 Samsung TV and have found that port 55000 is not open. Any ideas on how we could support my TV?
Here's a quick nmap of the running TV:
Host is up (0.010s latency).
Not shown: 994 closed ports
PORT STATE SERVICE
7676/tcp open imqbrokerd
8000/tcp open http-alt
8001/tcp open vcom-tunnel
8002/tcp open teradataordbms
8080/tcp open http-proxy
9999/tcp open abyss
Is this a known issue?
The last couple versions on pypi are missing README.md resulting in the trigger of FileNotFoundError, which is not defined:
Traceback (most recent call last):
File "/usr/local/bin/samsungctl", line 9, in <module>
load_entry_point('samsungctl===0.3.0-git', 'console_scripts', 'samsungctl')()
File "build/bdist.linux-x86_64/egg/samsungctl/__main__.py", line 88, in main
File "build/bdist.linux-x86_64/egg/samsungctl/__main__.py", line 36, in _read_config
NameError: global name 'FileNotFoundError' is not defined
Hi,
When i try to run the sample on a windows machine (Windows 10, python 3.6 64-bit) i get the following error:
File "sample.py" line 16, in
with samsungctl.Remote(config) as remote:
File "C:\Program Files\Python36\lib\site-packages\samsungctl\remote.py", line 10, in init
self.remote = RemoteWebsocket(config)
File "C:\Program Files\Python36\lib\site-packages\samsungctl\remote_websocket.py", line 22, in init
self._serialize_string(config["name"])), config["timeout"])
File "C:\Program Files\Python36\lib\site-packages\websocket_core.py", line 487, in create_connection
websock.connect(url, **options)
File "C:\Program Files\Python36\lib\site-packages\websocket_core.py", line 211, in connect
options.pop('socket', None))
File "C:\Program Files\Python36\lib\site-packages\websocket_http.py", line 71, in connect
sock = _open_socket(addrinfo_list, options.sockopt, options.timeout)
File "C:\Program Files\Python36\lib\site-packages\websocket_http.py", line 114, in _open_socket
sock.connect(address)
BlockingIOError: [WinError 10035] A non-blocking socket operation could not be completed immediately
Any idea what the issue could be? Python is not my really my programming language so I have no idea where to start solving this issue myself.
Hi, when using this commad:
samsungctl --host 192.168.5.91 --port 8001 KEY_MUTE --method websocket --name "home-assistant" --id 1234567890 --timeout 30 -v
the output is : Sending control command: KEY_MUTE
the TV dosent ask me to accept it as a remote, any ideas?
Hi,
I want to operate multiple keys (KEY_0,KEY_1,KEY_2......,) in python program.
Where those keys are mainly used ?. I'm trying those keys to open applications present on the TV. how can i achieve this?
Dear @Ape ,
based on this library, home-assistant.io requests a new connection each time but it seems some models should be able to remember the host based on MAC address.
Could you be so kind as to add an optional conf variable for it?
I found a practical example that may help here : http://deneb.homedns.org/things/?p=232
Apparently the script is run by python 2.7 but FileNotFoundError is only there in python 3
Write a detailed step-by-step tutorial that shows what samsungctl does and how it should be used.
Hi,
I want to change channels present in my digital setup box from samsungctl API. KEY_CHUP & KEY_CHDOWN is not working for my setup box. How can i change channels using samsungctl API ?
Currently the default configuration parameters are set on the command line tool, not on the Remote object. This means that all configurations fields must be set when using samsungctl as a library.
Change this so that even library usage has the default parameters so that some configuration fields can be omitted.
This error shows up.
samsungctl --host 192.168.1.2 key KEY_POWER Traceback (most recent call last): File "/home/pi/.local/bin/samsungctl", line 11, in <module> sys.exit(main()) File "/home/pi/.local/lib/python2.7/site-packages/samsungctl/__main__.py", line 92, in main config = _read_config() File "/home/pi/.local/lib/python2.7/site-packages/samsungctl/__main__.py", line 37, in _read_config except FileNotFoundError: NameError: global name 'FileNotFoundError' is not defined
When commented the FileNotfoundError exception
New error popped up
samsungctl --host 192.168.1.2 key KEY_POWER
Traceback (most recent call last):
File "/home/pi/.local/bin/samsungctl", line 11, in <module>
sys.exit(main())
File "/home/pi/.local/lib/python2.7/site-packages/samsungctl/__main__.py", line 93, in main
config = _read_config()
File "/home/pi/.local/lib/python2.7/site-packages/samsungctl/__main__.py", line 46, in _read_config
with config_file:
UnboundLocalError: local variable 'config_file' referenced before assignment
PS:I used pip for installation.
I have something like this
with samsungctl.Remote(config_remote) as remote:
for digit in channel:
remote.control("KEY_" + digit)
remote.control("KEY_ENTER")
print 'The channel was changed to ', channel
but the problem is that each time the second command is not sent
If channel is "123" on my TV i get only 13.
The from_bytes handling of the response is producing errors as follows:
$ samsungctl
Traceback (most recent call last):
File "/usr/local/bin/samsungctl", line 9, in <module>
load_entry_point('samsungctl===0.3.0-git', 'console_scripts', 'samsungctl')()
File "build/bdist.linux-x86_64/egg/samsungctl/__main__.py", line 101, in main
File "build/bdist.linux-x86_64/egg/samsungctl/remote.py", line 27, in __init__
File "build/bdist.linux-x86_64/egg/samsungctl/remote.py", line 51, in _read_response
AttributeError: type object 'int' has no attribute 'from_bytes'
While I found this potentially relevant suggestion, I did not pursue any further:
https://stackoverflow.com/questions/28210333/python-nonetype-object-has-no-attribute-from-bytes
If these are all user error on my part, my apologies! I did my best to troubleshoot through these.
Thank you!
Hi,
First Sorry for Silly question and bad Grammar!
I do electronic stuff with ARM and AVR , and I decided to control Samsung Smart TV with TCP/IP, with no background.
1.How execute .py ?
2.How to connect to TV? How send Key Codes?
3.Can i connect TV to my WiFi module and then command it by IP??!
4.At last , what should i do for first step?
Please give me a overview to what to do and what to learn.
Hi - I've noticed using this via Home Assistant commands sent to the TV are almost instantaneous but using it from the command line there can be significant delays up to 5 seconds. Is there a difference in the versions bundled with HA vs running this via python3?
Thanks.
When I use the ssh command line Samsungctl via Websocket it works. However when I use the Domoticz plugin I get a message Error: Not Connected. Can't seem to find the problem...
Hi,
I am getting a websocket timeout exception when trying to run this against my Samsung UE40KU6405 TV.
The command run is:
samsungctl --host 10.10.0.191 --method websocket -i -v --timeout 10 POWER
The relevant network packages sent/received are:
T 10.10.20.248:49904 -> 10.10.0.191:8001 [AP]
GET /api/v2/channels/samsung.remote.control?name=c2Ftc3VuZ2N0bA== HTTP/1.1.
Upgrade: websocket.
Connection: Upgrade.
Host: 10.10.0.191:8001.
Origin: http://10.10.0.191:8001.
Sec-WebSocket-Key: rQzS/gChQASWksDDbnq7+A==.
Sec-WebSocket-Version: 13.
.
##
T 10.10.0.191:8001 -> 10.10.20.248:49904 [AP]
HTTP/1.1 101 Switching Protocols.
Upgrade: websocket.
Connection: Upgrade.
Sec-WebSocket-Accept: StzHg6opiZEMJIg4pld3vv3rnSI=.
.
##
T 10.10.0.191:8001 -> 10.10.20.248:49904 [AP]
..{"event":"ms.channel.timeOut"}
Any idea what I might be doing wrong?
Edited by @Ape:
I hijacked this issue to collect all instances where some random TV model does not work, but we don't know what is the cause or how it could be fixed. Some TV models might not simply support TCP/IP control at all, and some models may require a whole new protocol. When you have techinical details about a specific case that could be fixed please open a new issue.
Original message:
I'm wondering if anyone can confirm if this works for their JS9000 or H5203? Getting 'Connection refused' from the 9000 and no response from the 5203.
Hello Ape,
I have a Samsung UE46D6500. Samsung's own iOS App "Smart View" is working.
I've installed samsungctl and called it by the following command:
samsungctl --host 192.168.100.102 --name myremote KEY_CHDOWN
I've although tried to enter a description and an id and set the timeout to 0.
But I always get the following output direct (without waiting):
Authorization cancelled.
Error: Access denied!
Any ideas ?
Thanks and regards,
Ralf
Hi,
I have sent "KEY_POWEROFF" command to samsung smart tv. The TV is turn off successfully.
But, i want to get acknowledgement from TV. how to get acknowledgement from TV?
For example, If i am changing my channel every time it should acknowledge to me.
Configuration file should be searched from /etc
(after the current locations) and setup.py
should install the default configuration file.
Once the other errors are cleared, I run into errors regarding the values from the config file
(This is both pip version 0.3.0 and git Master)
$ samsungctl --interactive
Traceback (most recent call last):
File "/usr/local/bin/samsungctl", line 9, in <module>
load_entry_point('samsungctl===0.3.0-git', 'console_scripts', 'samsungctl')()
File "build/bdist.linux-x86_64/egg/samsungctl/__main__.py", line 101, in main
File "build/bdist.linux-x86_64/egg/samsungctl/remote.py", line 21, in __init__
TypeError: descriptor 'encode' requires a 'str' object but received a 'unicode'
I may have incorrectly fixed this by changing this:
self._serialize_string(str.encode(description)) +\
self._serialize_string(str.encode(id)) +\
self._serialize_string(str.encode(name))
to this:
self._serialize_string(description.encode('ascii')) +\
self._serialize_string(id.encode("ascii")) +\
self._serialize_string(name.encode("ascii"))
sorry but samsung ue48ju7500t not work . the error is Error: Connection refused
Would be great to be able to send notifications to the TV
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.