Samsung TV integration Question -- Driver info starting post 127

Cal, thanks for the assist. The message indicates that the code is working (it returns an error event from the method. This may be due to the TV mode (i.e., you use volume while using the soundbar).

Which key code did you try this with? It looks like code that translated to code 1005 which is reserved. Did you try others? Particularly KEY_TOOLS, KEY_SOURCE, or KEY_SOURCE that work regardless of external source or sound sink.

Dave

Results w a 2014(?) Samsung TV
dev:21312020-10-11 09:15:06.748 am debugwebSocketStatus: status: closing

dev:21312020-10-11 09:15:01.695 am infoparse: {"event":"ms.error","data":{"message":"unrecognized method value : ms.remote.control"}}

dev:21312020-10-11 09:15:01.360 am infoparse: {"event":"ms.channel.connect","data":{"id":"bf7cd270-2327-11b2-9f26-31ddfd4a529d","clients":[{"id":"bf7cd270-2327-11b2-9f26-31ddfd4a529d","connectTime":586551576,"attributes":{},"isHost":false}]}}

dev:21312020-10-11 09:15:01.345 am debugwebSocketStatus: status: open

dev:21312020-10-11 09:15:01.048 am tracesendCmd: {"method":"ms.remote.control","params":{"Cmd":"Click","DataOfCmd":"KEY_MUTE","Option":"false","TypeOfRemote":"SendRemoteKey"}}, 192.168.1.153

dev:21312020-10-11 09:15:01.044 am tracetest: KEY_MUTE

Here's are logs from when trying all the other keys, like KEY_TOOLS and KEY_SOURCE. Tried this with the TV already on with source of HDMI

Thanks. I failed. sigh.

Here are a couple of commands, that worked well to open some apps on the TV:
(Open Netflix)
curl -X POST -i 'http://IP:8001/api/v2/applications/11101200001'
(Open Prime Video)
curl -X POST -i 'http://IP:8001/api/v2/applications/3201512006785'

I was doing some reading on some other forums, and it seems like you can connect over websocket, but first you have to obtain the Name of the TV convert to Base64, connect and obtain the token for future connection. This is far as I could get.

Get TV Name from:
http://IP:8001/api/v2/

Convert TV Name to Base64

Connect using:
https://IP:8002/api/v2/channels/samsung.remote.control?name=base64encodedname

2 Likes

Maybe the code is on the wrong port for your TV. Try changing the line:

def url = "ws://${deviceIp}:8001/api/v2/channels/samsung.remote.control"

to read (changing the port to 8002:

def url = "ws://${deviceIp}:8002/api/v2/channels/samsung.remote.control"

Tried changing the URL, but that didn't work. However, some progress...

I figured out how to get these newer TV's that require encryption to connect. Apparently Remote.Control requires the secure connection.

  1. Installed NPM & wscat on a computer order to investigate websocket connection and responses
  2. TV should be turned on
  3. Open a web browser to http://TVIPADDRESS:8001/api/v2/
  4. A pop up may appear on the TV, you have to click Allow
  5. Web browser will output the TV information, copy the 'TV Name'
  6. The name has to be encoded to Base64, I used this site then copy the string (https://www.base64encode.org)
  7. Next, open a command prompt on the machine you have wscat installed on
  8. wscat -n -c https://TVIPADDRESS:8002/api/v2/channels/samsung.remote.control?name=TVNameStringYouReceivedFromBase64Encode
  9. "Token":"12345678" <-8 Character Token will be displayed in the output
  10. Now, you can connect to the TV securely using the Token by going to: wscat -n -c https://TVIPADDRESS:8002/api/v2/channels/samsung.remote.control?token=<8 digit token> and issue commands. By using the token in the URL, the TV will no longer prompt you to accept the remote device connection each time you send a command.

All of the remote control commands can be now sent, and they all work on the TV if they are in the format below

{"params": {"Cmd": "Click", "Option": "false", "TypeOfRemote": "SendRemoteKey", "DataOfCmd": "KEY_VOLUP"}, "method": "ms.remote.control"}

This site I ran across was a huge help in figuring this out, Samsung TV info is mid way down (S. Andrews)

Based on this info, is it possible to bring it into the App?

  1. Connect to TV's IP, to receive the TV name
  2. Base64Encode TV's name
  3. Connect to TV using Base64 name to receive the Token
  4. Remember Token and URL and use that for connectivity on all future access
1 Like

Several things.
Control you is how I control my Samsung Wifi Speakers. Quite simple, so can do.
Your Step 3: We will have to capture name and uri. Yours uses 8002 as the final port, mine 8001.
Step 6: Base 64: name.encodeAsBase64().toString()
Step 9: Just a parameter to catch
Step 10: Easy

So, yes. What you want should be able to be done. Let me update my test driver some to capture the various data.

Cal,
I created a test driver (no polish, not final version). Tested all but getting token and sending key (but coded those functions.
Step 1: GetData (gets the name of the TV
Step 2: Get token
Step 3: Send Key with key name entry.
I am very interested in what the output for a Send Key is. That should be an event and I want to know if it reports volume for KEY_VOLDOWN.

If this works, I will code further with agreed keys; including the Samsung recommended minimum keys.

link to code: https://raw.githubusercontent.com/DaveGut/Hubitat-TP-Link-Integration-DEPRECATED/master/Test%20Code.groovy

Thanks! Here's the output:

Port set to 8001:

image

Port set to 8002:
image

Updated code at same site to fix one error found this am. Also, now working on port 8002 only. Added commands for key (no longer need to enter) and updated logging.

  • Close device
  • Replace code
  • Open device
  • Get Data
  • Get Token
  • Menu

At some point, you may need to allow the device on your TV. I have seen this on my UPnP efforts where I can control volume, mute, source, play, pause and etc. I actually plan to include these on the final update (particularly calling the explicit source and volume).

This is great with the latest code now under preferences showing the TV Name, Base64 Name and placeholder for Token.

I did another test today while the TV had gone into deep sleep overnight. TV does not accept connections while it's been off for a while.

However, installed Boot Me Up Scottie Wake on LAN app with a virtual switch. TV wakes right away and then you can start sending commands to it. TV is connected to WiFi and not a wired connection.

Also here are the logs using the latest code and then pressing the keys:

I have to figure some way for Hubitat to cause the TV to require "accept" so that the device is in the TV's database. Same error I am getting.

Dave
First thank you for your efforts....
dev:21342020-10-12 12:22:14.743 pm infoTV Test || webSocketStatus: failure: Remote host closed connection during handshake

dev:21342020-10-12 12:22:14.626 pm traceTV Test || sendKey: key = KEY_VOLDOWN, token = null

dev:21342020-10-12 12:22:01.412 pm infoTV Test || webSocketStatus: failure: Remote host closed connection during handshake

dev:21342020-10-12 12:22:01.291 pm traceTV Test || getToken: name = W1RWXVNhbXN1bmcgTEVENjU=

dev:21342020-10-12 12:21:56.077 pm traceTV Test || getData: name = [TV]Samsung LED65

Observation: Token appears to be returned, but not used when sending key. There's no field in settings to add token...
Question: why are two ports used ?
Thanks again

I think it might be running into an issue where it can't verify the self-signed certificate on the Samsung TV so it errors out when connecting. I was running into this as well trying to connect directly using wscat.
I see that Hubitat added the ability to ignore SSL warnings in 2.1.8. Maybe add the IgnoreSSLIssues into the paramters section? Common Methods Object - Hubitat Documentation

  • The 8001 port is only used to get the tv's name.
  • Token should be added automatically via the driver. It is in the return stream and I am trying to capture. If not captured, then the whole message is parsed so I can correct the software. However, I will update to add manual token entry via a preference (it will update the token field and not be required once I get the data structure correct).
  • ignoreLocalHost. I will try this variable. It is really for developmental environemnts; however, if it works, then great.

Will play some and provide update in several hours.

Dave

Next version available. I have added preferences for port and for token. Uninstall and reInstall. Then GetData to get name and GetToken (starts the real test).

Question: In your playing, have you had your TV ask for access?

You can get the TV's view of approved external control through the Network Multimedia device manager. Path is TOOLS -> Network -> Multimedia Device Manager. When you select the device, you options. Interesting one is View Details and what service is available. Of interest is the Device Name and the Service.

Dave

PS - shopping to replace my 2015 TV with a 2020 Samsung. Will then move faster. Final product will automate the token gathering when you save preferences. - D

Looking forward to giving this a shot. I have 5 samsung tv's from various years 2016 to 2020.

It is slow. Mine is 2015 model. Will get my 2020 model on Saturday - so real fun begins Sunday. Looking for suggestions on desired controls. I want to include both remote and UPNP controls (UPNP can provide explicit volume and source control that may be useful). Looking for a Wake On Lan implementation to integrate also - but that is after I get my new TV.

I'd like to be able to set the source HDMI input. Maybe a couple controls to launch specific apps. Sling, Netflix, CBS, AmazonPrime, YouTube