Samsung TV 2014 H Series not working

can someone point me how to execute python in hassio? Or should i run it from terminal on my mac?

Hi,
i get this message. can somebody please help me?

Traceback (most recent call last):
  File "get_token.py", line 3, in <module>
    from PySmartCrypto.pysmartcrypto import PySmartCrypto
  File "/home/diablo/Downloads/ha-samsungtv-encrypted-master/custom_components/samsungtv_encrypted/PySmartCrypto/pysmartcrypto.py", line 2, in <module>
    from . import crypto
  File "/home/diablo/Downloads/ha-samsungtv-encrypted-master/custom_components/samsungtv_encrypted/PySmartCrypto/crypto.py", line 2, in <module>
    from Crypto.Cipher import AES
ModuleNotFoundError: No module named 'Crypto'

Add the ‘name’ attribute:

media_player:
  - platform: samsungtv_encrypted # Samsung TV da Sala
    name: Kitchen TV
    host: !secret samsungtv_encrypted_sala_host
    token: !secret samsungtv_encrypted_sala_token
    sessionid: !secret samsungtv_encrypted_sala_sessionid
    port: !secret samsungtv_encrypted_sala_port
1 Like

Better a terminal outside Home Assistant

The custom component is in HACS.

Follow the steps in https://github.com/sermayoral/ha-samsungtv-encrypted

execute the following:

pip3 install pycrypto

Do you have the possibility of executing it outside Home Assistant?

yes; i’ll try on MAC today

For you who’s having difficulties executing “get_token.py”, I’ve been there and had success with the Mac’s Terminal using the following command:

python3 get_token.py --ip 192.168.X.X --port 8080

I got many errors and needed to install a number of packages (like pycrypto)… Every time I got an error output, I copied it into google and found what I needed to install.
After that, I managed to show the code on TV, but here is the tricky part: when I typed the code in Terminal I got another error… What worked for me was:

  1. Execute “get_token.py”.
  2. When the code appears on TV screen, DO NOT enter the code in Mac’s Terminal. Press “Control+C” and stop “get_token.py”. The code will remain on TV screen.
  3. Run “get_token.py” again. Just use the same exact command line. The code on TV screen won’t change.
  4. Type the code in Terminal.
  5. Get the CTX and SESSION_ID output.

Hope it works for you too.
Cheers

Hi,
after i installed the required things, i get this. sorry but i dont know whats the problem. please help me again. thanks

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 159, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw)
  File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 57, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/usr/lib/python3.7/socket.py", line 748, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 354, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/lib/python3.7/http/client.py", line 1252, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.7/http/client.py", line 1298, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.7/http/client.py", line 1247, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.7/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/usr/lib/python3.7/http/client.py", line 966, in send
    self.connect()
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 181, in connect
    conn = self._new_conn()
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 168, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7fa4b7287d90>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 398, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='p', port=8000): Max retries exceeded with url: /socket.io/1/?t=1585352900149 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fa4b7287d90>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "get_token.py", line 27, in <module>
    main(sys.argv[1:])
  File "get_token.py", line 24, in main
    PySmartCrypto(ip, port)
  File "/home/diablo/Downloads/ha-samsungtv-encrypted-master/custom_components/samsungtv_encrypted/PySmartCrypto/pysmartcrypto.py", line 123, in __init__
    self._connection = self.connect()
  File "/home/diablo/Downloads/ha-samsungtv-encrypted-master/custom_components/samsungtv_encrypted/PySmartCrypto/pysmartcrypto.py", line 95, in connect
    websocket_response = requests.get(step4_url)
  File "/usr/lib/python3/dist-packages/requests/api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='p', port=8000): Max retries exceeded with url: /socket.io/1/?t=1585352900149 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fa4b7287d90>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))

I see host=‘p’. It shoud be an IP, like 192.168.1.54

requests.exceptions.ConnectionError: HTTPConnectionPool(host='p', port=8000)

Hi,
that comes with the command: python3 get_token.py -ip 192.168.1.48 -port 8080

now i tried: python3 get_token.py -i 192.168.1.48 -p 8080

than comes

ws://192.168.1.48:8000/socket.io/1/websocket/g1AsCE-TB7ymmqWRAPs4
Traceback (most recent call last):
  File "get_token.py", line 27, in <module>
    main(sys.argv[1:])
  File "get_token.py", line 24, in main
    PySmartCrypto(ip, port)
  File "/home/diablo/Downloads/ha-samsungtv-encrypted-master/custom_components/samsungtv_encrypted/PySmartCrypto/pysmartcrypto.py", line 123, in __init__
    self._connection = self.connect()
  File "/home/diablo/Downloads/ha-samsungtv-encrypted-master/custom_components/samsungtv_encrypted/PySmartCrypto/pysmartcrypto.py", line 99, in connect
    connection = websocket.create_connection(websocket_url)
AttributeError: module 'websocket' has no attribute 'create_connection'

try this:

python3 get_token.py 192.168.1.48 --port 8080

then it comes only that.

get_token.py -ip <ip> -port <port>

I don’t understand why it doesn’t work for me.

@sermayoral,

the HACS custom component doesn’t appear to be compatible with H and J models - I specifically need that functionality. @StevusPrimus’s version, at least on the cover, should work.

If I’m mistaken, would love to be corrected.

It works with most ot H and J models. Mine is H6400 and it works perfect.

I have an issue with some specific model, but it is in process of resolution

@sermayoral thank you really much for your efforts, got it workin’ partially, can control volume and switch between the chans, but turnin’ off is not working so far and that’s the main feature I am looking for. could you kindly help?!

  • platform: samsungtv_encrypted
    host: 192.168.178.71
    port: 8080
    token: xxxxx
    sessionid: xxxx

UPDATE:
got it workin’ with a new sessionid and token :smiley:

2 Likes

@sermayoral is it possible to integrate a kind of sourcelist which is editable like in the original Samsung TV Control integration?

@sermayoral , Installed the component version master and 2.2, but both versions in the error log:
When you try to form a team
entity_id: media_player.samsung_room
media_content_type: send_key
media_content_id: KEY_CHDOWN

2020-04-02 21:52:03 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.1770011216] extra keys not allowed @ data['media_content_type']
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 134, in handle_call_service
    connection.context(msg),
  File "/usr/src/homeassistant/homeassistant/core.py", line 1210, in async_call
    processed_data = handler.schema(service_data)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/validators.py", line 208, in __call__
    return self._exec((Schema(val) for val in self.validators), v)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/validators.py", line 287, in _exec
    raise e if self.msg is None else AllInvalid(self.msg, path=path)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/validators.py", line 283, in _exec
    v = func(v)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 817, in validate_callable
    return schema(data)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 594, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 432, in validate_mapping
    raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: extra keys not allowed @ data['media_content_type']

When you try to change the sound with the slider in the widget:

2020-04-02 21:44:27 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.1770011216] 'NoneType' object is not subscriptable
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 134, in handle_call_service
    connection.context(msg),
  File "/usr/src/homeassistant/homeassistant/core.py", line 1232, in async_call
    await asyncio.shield(self._execute_service(handler, service_call))
  File "/usr/src/homeassistant/homeassistant/core.py", line 1255, in _execute_service
    await handler.func(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
    self._platforms.values(), func, call, required_features
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 412, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 600, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 443, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 542, in async_set_volume_level
    await self.hass.async_add_job(self.set_volume_level, volume)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/samsungtv_encrypted/media_player.py", line 359, in set_volume_level
    self.SendSOAP(self._smp[0], self._urns[0], 'SetVolume',

The token and session number were received without problems through the execution request get_token.py

bash-5.0# python3 get_token.py --ip 192.168.169.9 --port 8080
ws://192.168.169.9:8000/socket.io/1/websocket/7hwVABdjBnbxQhAWRtVH
Current state: stopped
Pin NOT on TV
Please enter pin from tv: 2646
Got pin: '2646'

AES key: a133e693a5e73c64a5c82f9a26f03d2d
AES encrypted: 16*******6b7611ef4cdedd6645534ced4803208cc66ea
AES swapped: 79d90******422656f45f889478ccb3e53d1e49614357972a30d60dbc292
data buffer: 000000063*********C292
hash: feca1daaf7fdafe1b814fc2bd497096e27fd8eee
secondStepResponse: {"auth_data":"{\"auth_type\":\"SPC\",\"request_id\":\"0\",\"GeneratorClientHello\":\"01010**********2D1B58A2BDF800000000000\"}"}


thirdLen: 138
hello: 01010********d308230e721542d1b58a2bdf800000000000
dest: 0000000636**********27fd8eee
userId: 654321
pEncWBGx: b25809d*********40add528822f828f1c170ba72
pEncGx: 1fff9bc859********a920a982b4c0d9262437ef
pGx: 1b9d430*********38b375f83647a65a0fe59381aa4e6e04b5a38074a0d26c
secret: 9be7***********17cda8492bfcee5acd38e92c39
hash2: 0461e27**********8a2bdf80
secret2: 363534*********5acd38e92c39
hash3: 0461e277169*******21542d1b58a2bdf80
Pin OK :)

dest_hash: c6098041ec*******07b2a6ec187f8cbf5
SKPrime: df142da193b********9046f652a21ff98d
SKPrimeHash: abdac4dd21********4c70c48d476ca149
ctx: 1e66f533***cf950286123
Pin accepted :)

sessionId: 3
SessionID: 3
Authorization successfull :)

Config Home Assistant 0.108.0b0

  - platform: samsungtv_encrypted
    name: samsung_room
    host: 192.168.169.9
    token: 2646
    sessionid: 3
    port: 8080

Can someone tell me what the problem is, in HA only the On / Off status is displayed. The sound level is not displayed, the command does not accept
P.s
TV response at http://192.168.169.9:8001/api/v2/

{
  "id": "uuid:409*******************b803",
  "name": "[TV] UE48J6530",
  "version": "2.0.25",
  "device": {
    "type": "Samsung SmartTV",
    "duid": "uuid:40951******************b803",
    "model": "15_HAWKM_2D",
    "modelName": "UE48J6300",
    "description": "Samsung DTV RCR",
    "networkType": "wired",
    "ssid": "",
    "ip": "192.168.169.9",
    "firmwareVersion": "Unknown",
    "name": "[TV] UE48J6530",
    "id": "uuid:40951**********1b803",
    "udn": "uuid:409518***********31b803",
    "resolution": "1920x1080",
    "countryCode": "RU",
    "msfVersion": "2.0.25",
    "smartHubAgreement": "true",
    "wifiMac": "f8:********:e1",
    "developerMode": "0",
    "developerIP": ""
  },
  "type": "Samsung SmartTV",
  "uri": "http://192.168.169.9:8001/api/v2/"

I can make customizable names such as HDMI1, HDMI2, … but you need sourcelist working. If not, the customization does not work

1 Like