Package: samsungctl
samsungctl is a library and a command line tool for remote controlling Samsung
televisions via a TCP/IP connection. It currently supports both pre-2016 TVs as
well most of the modern Tizen-OS TVs with Ethernet or Wi-Fi connectivity.DependenciesPython 3websocket-client(optional, for 2016+ TVs)curses(optional, for the interactive mode)Installationsamsungctl can be installed usingpip:# pip install samsungctlAlternatively you can clone the Git repository and run:# python setup.py installIt’s possible to use the command line tool without installation:$ python -m samsungctlCommand line usageYou can usesamsungctlcommand to send keys to a TV:$ samsungctl --host <host> [options] <key> [key ...]hostis the hostname or IP address of the TV.keyis a key code, e.g.KEY_VOLDOWN. SeeKey codes.There is also an interactive mode (ncurses) for sending the key presses:$ samsungctl --host <host> [options] --interactiveUsesamsungctl--helpfor more information about the command line
arguments:usage: samsungctl [-h] [--version] [-v] [-q] [-i] [--host HOST] [--port PORT]
                  [--method METHOD] [--name NAME] [--description DESC]
                  [--id ID] [--timeout TIMEOUT]
                  [key [key ...]]

Remote control Samsung televisions via TCP/IP connection

positional arguments:
  key                 keys to be sent (e.g. KEY_VOLDOWN)

optional arguments:
  -h, --help          show this help message and exit
  --version           show program's version number and exit
  -v, --verbose       increase output verbosity
  -q, --quiet         suppress non-fatal output
  -i, --interactive   interactive control
  --host HOST         TV hostname or IP address
  --port PORT         TV port number (TCP)
  --method METHOD     Connection method (legacy or websocket)
  --name NAME         remote control name
  --description DESC  remote control description
  --id ID             remote control id
  --timeout TIMEOUT   socket timeout in seconds (0 = no timeout)

E.g. samsungctl --host 192.168.0.10 --name myremote KEY_VOLDOWNThe settings can be loaded from a configuration file. The file is searched from$XDG_CONFIG_HOME/samsungctl.conf,~/.config/samsungctl.conf, and/etc/samsungctl.confin this order. A simple default configuration is
bundled with the source assamsungctl.conf.Library usagesamsungctl can be imported as a Python 3 library:importsamsungctlA context managed remote controller object of classRemotecan be
constructed using thewithstatement:withsamsungctl.Remote(config)asremote:# Use the remote objectThe constructor takes a configuration dictionary as a parameter. All
configuration items must be specified.KeyTypeDescriptionhoststringHostname or IP address of the TV.portintTCP port number. (Default:55000)methodstringConnection method (legacyorwebsocket)namestringName of the remote controller.descriptionstringRemote controller description.idstringAdditional remote controller ID.timeoutintTimeout in seconds.0means no timeout.TheRemoteobject is very simple and you only need thecontrol(key)method. The only parameter is a string naming the key to be sent (e.g.KEY_VOLDOWN). SeeKey codes. You can callcontrolmultiple times
using the sameRemoteobject. The connection is automatically closed when
exiting thewithstatement.When something goes wrong you will receive an exception:ExceptionDescriptionAccessDeniedThe TV does not allow you to send keys.ConnectionClosedThe connection was closed.UnhandledResponseAn unexpected response was received.socket.timeoutThe connection timed out.Example programThis simple program opens and closes the menu a few times.#!/usr/bin/env python3importsamsungctlimporttimeconfig={"name":"samsungctl","description":"PC","id":"","host":"192.168.0.10","port":55000,"method":"legacy","timeout":0,}withsamsungctl.Remote(config)asremote:foriinrange(10):remote.control("KEY_MENU")time.sleep(0.5)Key codesThe list of accepted keys may vary depending on the TV model, but the following
list has some common key codes and their descriptions.Key codeDescriptionKEY_POWEROFFPower offKEY_UPUpKEY_DOWNDownKEY_LEFTLeftKEY_RIGHTRightKEY_CHUPP UpKEY_CHDOWNP DownKEY_ENTEREnterKEY_RETURNReturnKEY_CH_LISTChannel ListKEY_MENUMenuKEY_SOURCESourceKEY_GUIDEGuideKEY_TOOLSToolsKEY_INFOInfoKEY_REDA / RedKEY_GREENB / GreenKEY_YELLOWC / YellowKEY_BLUED / BlueKEY_PANNEL_CHDOWN3DKEY_VOLUPVolume UpKEY_VOLDOWNVolume DownKEY_MUTEMuteKEY_00KEY_11KEY_22KEY_33KEY_44KEY_55KEY_66KEY_77KEY_88KEY_99KEY_DTVTV SourceKEY_HDMIHDMI SourceKEY_CONTENTSSmartHubPlease note that some codes are different on the 2016+ TVs. For example,KEY_POWEROFFisKEY_POWERon the newer TVs.ReferencesI did not reverse engineer the control protocol myself and samsungctl is not
the only implementation. Here is the list of things that inspired samsungctl.http://sc0ty.pl/2012/02/samsung-tv-network-remote-control-protocol/https://gist.github.com/danielfaust/998441https://github.com/Bntdumas/SamsungIPRemotehttps://github.com/kyleaa/homebridge-samsungtv2016