Package: samsungTVlegacy
Forked from Ape/samsungctl github for use with legacy series TV.In my case a F series (2013) Samsung TV.
Added extra time for time_interval to process string of key codessamsungTVlegacysamsungTVlegacy 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)InstallationsamsungTVlegacy can be installed using pip <(https://pip.pypa.io/>:# pip install samsungTVlegacyAlternatively you can clone the Git repository and run:# python setup.py installIt’s possible to use the command line tool without installation:$ python -m samsungTVlegacyCommand line usageYou can usesamsungTVlegacycommand to send keys to a TV:$ samsungTVlegacy --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, to check what key codes are available for your TV:$ samsungTVlegacy --host <host> [options] --interactiveUsesamsungTVlegacy--helpfor more information about the command line
arguments:usage: samsungTVlegacy [-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) or set of keys (e.g. KEY_SOURCE KEY_RIGHT KEY_ENTER)

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. samsungTVlegacy --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_legacy.conf,~/.config/samsungctl_legacy.conf, and/etc/samsungctl_legacy.confin this order. A simple default configuration is
bundled with the source assamsungctl_legacy.conf.Library usagesamsungTVlegacy can be imported as a Python 3 library:importsamsungTVlegacyA context managed remote controller object of classRemotecan be
constructed using thewithstatement:withsamsungTVlegacy.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 python3importsamsungTVlegacyimporttimeconfig={"name":"samsungTVlegacy","description":"PC","id":"","host":"192.168.0.10","port":55000,"method":"legacy","timeout":0,}withsamsungTVlegacy.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.The Samsung Series F TV has a limited number of key codes as listed below.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_TVTV SourceKEY_HDMIHDMI SourcePlease 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-samsungtv2016https://github.com/Ape/samsungctl