Skip to content

A Homebridge plugin for Samsung SmartTV H and J models with the pairing protocol

License

Notifications You must be signed in to change notification settings

kkapitan/homebridge-homesung

Repository files navigation

NOTE: This plugin is in WIP state. While it should work in simple cases, there are still some work in progress to make it more stable.


homebridge-homesung

A homebridge plugin that allows you to control the Samsung Smart TV H and J series with HomeKit and Siri.

This plugin was made because the available ones offer the support for only the newer (2016+) models. Thanks to the reverse engineering work done by people in this thread, the specifics of pairing protocol of H and J series were finally revealed.

Installation

  • Install homebridge - refer to their README for further instructions.
  • Install the plugin using: npm install -g --unsafe-perm homebridge-homesung
  • Update your configuration file - see the config-sample.json for reference.

Configuration

  • Edit your configuration file from ~/.homebridge/config.json
  • Platform should be SamsungTV.
  • Devices should be a list of the TV's to be controlled.
  "platforms": [
    {
      "platform": "SamsungTV",
      "devices": [
        {
          "name": "<name of the device>",
          "ip": "<ip of the device>",
          "identity": {
            "sessionId": "<id of the pairing session - obtained after pairing>",
            "aesKey": "<key of the pairing session - obtained after pairing>"
          },
          "power": {
            "name": "<name of the power switch>",
            "key": "<key to use in order to power off the TV if hdmi-cec is disabled>",
            "enableCEC": "<whether to use hdmi-cec as a power on/off method>",
          }
          "switches": [
            { "name": "Vol Down 5", "delay": 1000, "command": "5*KEY_VOLDOWN" },
            { "name": "Channel 12", "command": ["KEY_1", "KEY_2"] },
            { "name": "Play with sound", "command": ["5*KEY_VOLDOWN", "5*KEY_VOLUP"] },
            {
              "name": "Do something",
              "command": { "keys": "5*KEY_VOLDOWN", "delay": 2000 }
            },
            {
              "name": "Do more of something",
              "command": { "keys": ["KEY_1", "KEY_2"], "delay": 1000 }
            },
            {
              "name": "Launch Netflix",
              "command": [
                { "keys": "KEY_CONTENTS", "delay": 2000 },
                { "keys": ["3*KEY_LEFT", "KEY_ENTER"], "delay": 1000 }
              ]
            }
          ]
        }
      ]
    }
  ]
}

Pairing

In order to obtain configuration info such as identity turn on the TV and run homesung-pair <ip of the device> from terminal. The pairing code should be displayed on the TV screen. After typing the correct pin code in the terminal, all the required info should be printed.

If the tool reports that it couldn't establish the connection right after the TV was turned on, try waiting a couple of minutes till the networking interface of the device will be ready to accept http calls.

Device settings

Name Description
name Name of the device in HomeKit.
ip The IP address of the device.
identity Pairing session id and key used to encrypt communication.
power (optional) Power object that specifies the behaviour of powering on/off the TV. See power for a reference.
debug (optional) If set to true, additional connection info will appear in the logs. The default value is false.

Power

Name Description
name Name of the power switch in HomeKit. The default value is "Power TV".
enableCEC Whether to use hdmi-cec as a way to power off/on the device. The default value is false.
key The key to be sent as a power off if hdmi-cec is disabled. The default value is KEY_POWEROFF.
addressCEC The hdmi-cec address of the device. The default value is 0 which should work with most of the cases.

NOTE: In order for HDMI-CEC to work, the server (e.g. rpi) must be connected to the TV via HDMI cable.

Switch settings

Name Description
name Name of the switch in HomeKit.
command Command to be sent to TV. See commands as a syntax reference.
delay (optional) Time (in miliseconds) to wait after sending each of the keys to the TV. The default value is 500 ms.

Commands

The command can be:

  • a single key e.g. KEY_VOLUP to imitate a key press.
  • a key with the multiplier e.g. 5 * KEY_VOLUP to imitate the key being pressed multiple times.
  • an array of the above e.g. [KEY_VOLUP, 5 * KEY_VOLDOWN] to imitate the sequence of key presses.
  • an object or an array of objects with the following properties:
Name Description
keys A single key with or without a multiplier, or an array of such.
delay (optional) Time (in miliseconds) to wait after sending each of the keys associated with the command to the TV. The default value is 500 ms. This option will override the one set as a switch setting.

See the config-sample.json for examples.

Known limitations

  • Turning the TV is possible only using HDMI-CEC technology.
  • The TV does not offer any feedback on the TV state so most of the switches are stateless.
  • As for today this plugin was not heavily tested, while the happy path scenarios might work, it can still break in more complex scenarios.

Work in progress

  • Turning TV on via wol (if possible).
  • Better error handling

List of available keys

KEY_ENTER
KEY_MENU
KEY_UP
KEY_DOWN
KEY_LEFT
KEY_RIGHT
KEY_0
KEY_1
KEY_2
KEY_3
KEY_4
KEY_5
KEY_6
KEY_7
KEY_8
KEY_9
KEY_11
KEY_12
KEY_VOLUP
KEY_VOLDOWN
KEY_MUTE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O_ARC_AUTOCOLOR_SUCCESS
KEY_AUTO_ARC_AUTOCOLOR_FAIL
KEY_AUTO_ARC_C_FORCE_AGING
KEY_AUTO_ARC_USBJACK_INSPECT
KEY_AUTO_ARC_JACK_IDENT
KEY_NINE_SEPERATE
KEY_ZOOM_IN
KEY_ZOOM_OUT
KEY_MIC
KEY_AUTO_ARC_CAPTION_KOR
KEY_AUTO_ARC_CAPTION_ENG
KEY_AUTO_ARC_PIP_SOURCE_CHANGE
KEY_AUTO_ARC_ANTENNA_AIR
KEY_AUTO_ARC_ANTENNA_CABLE
KEY_AUTO_ARC_ANTENNA_SATELLITE
KEY_EXT1
KEY_EXT2
KEY_EXT3
KEY_EXT4
KEY_EXT5
KEY_EXT6
KEY_EXT7
KEY_EXT8
KEY_EXT9
KEY_EXT10
KEY_EXT11
KEY_EXT12
KEY_EXT13
KEY_EXT14
KEY_EXT15
KEY_EXT16
KEY_EXT17
KEY_EXT18
KEY_EXT19
KEY_EXT20
KEY_EXT21
KEY_EXT22
KEY_EXT23
KEY_EXT24
KEY_EXT25
KEY_EXT26
KEY_EXT27
KEY_EXT28
KEY_EXT29
KEY_EXT30
KEY_EXT31
KEY_EXT32
KEY_EXT33
KEY_EXT34
KEY_EXT35
KEY_EXT36
KEY_EXT37
KEY_EXT38
KEY_EXT39
KEY_EXT40
KEY_EXT41

About

A Homebridge plugin for Samsung SmartTV H and J models with the pairing protocol

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published