Core: Samsung TV new integration doesn't work

Created on 5 Feb 2020  Â·  56Comments  Â·  Source: home-assistant/core

The problem


Can't integrate my Samsunt TV with HA

Environment

  • Home Assistant release with the issue: 0.105.0
  • Last working Home Assistant release (if known): 104
  • Operating environment (Hass.io/Docker/Windows/etc.): Hass.io/Home Assistant
  • Integration causing this issue: Samsung TV
  • Link to integration documentation on our website: https://www.home-assistant.io/integrations/samsungtv/

Problem-relevant configuration.yaml


removed integration from configuration.yaml.


Traceback/Error logs

```Error handling request
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start
resp = await task
File "/usr/local/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle
resp = await handler(request)
File "/usr/local/lib/python3.7/site-packages/aiohttp/web_middlewares.py", line 119, in impl
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/real_ip.py", line 39, in real_ip_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 72, in ban_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 135, in auth_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 123, in handle
result = await result
File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 160, in post
return await super().post(request, flow_id)
File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 50, in wrapper
result = await method(view, request, args, *kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 89, in post
result = await self._flow_mgr.async_configure(flow_id, data)
File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 130, in async_configure
result = await self._async_handle_step(flow, cur_step["step_id"], user_input)
File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 172, in _async_handle_step
result: Dict = await getattr(flow, method)(user_input)
File "/usr/src/homeassistant/homeassistant/components/samsungtv/config_flow.py", line 129, in async_step_user
result = await self.hass.async_add_executor_job(self._try_connect)
File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(self.args, *self.kwargs)
File "/usr/src/homeassistant/homeassistant/components/samsungtv/config_flow.py", line 92, in _try_connect
with Remote(config.copy()):
File "/usr/local/lib/python3.7/site-packages/samsungctl/remote.py", line 11, in __init__
self.remote = RemoteWebsocket(config)
File "/usr/local/lib/python3.7/site-packages/samsungctl/remote_websocket.py", line 30, in __init__
self._read_response()
File "/usr/local/lib/python3.7/site-packages/samsungctl/remote_websocket.py", line 67, in _read_response
response = self.connection.recv()
File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 310, in recv
opcode, data = self.recv_data()
File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 327, in recv_data
opcode, frame = self.recv_data_frame(control_frame)
File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 340, in recv_data_frame
frame = self.recv_frame()
File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 374, in recv_frame
return self.frame_buffer.recv_frame()
File "/usr/local/lib/python3.7/site-packages/websocket/_abnf.py", line 383, in recv_frame
frame.validate(self.skip_utf8_validation)
File "/usr/local/lib/python3.7/site-packages/websocket/_abnf.py", line 182, in validate
raise WebSocketProtocolException("Invalid close opcode.")
websocket._exceptions.WebSocketProtocolException: Invalid close opcode.

```

Additional information

samsung

Manually adding the integration also does not work in the latest version.

samsungtv

Most helpful comment

@twsl error will be fixed with 0.106. TV will work with mentioned PR.

All 56 comments

Having the same issue with the same error log.

  • Removed the Samsung TV config from configuration.yaml
  • Rebooted and went to add "Samsung TV" in HA Integration
  • Received same error "unknown error occurred" and same error log as @KuChar91
  • Tried to add back in code in configuration.yaml but still doesn't work

Happy to test any updates. Thanks!

Hey there @escoand, mind taking a look at this issue as its been labeled with a integration (samsungtv) you are listed as a codeowner for? Thanks!

Looks like there error is happening really deep within the samsungctl library. It's exactly the same as before 0.105. I don't own such a Websockets device. So it's hard for me to test.

@tulindo are you able to debug this? The only thing that's different now is we normally do not send a fixed port with the samsungctl config but the method.

@rosscullen can you please increase the log level of the samsungtv integration and show the output?

Here the steps to hopefully debug the problem:

  1. Increase the debug level for samsungtv:

    logger:
     default: info
     logs:
       homeassistant.components.samsungtv: debug
       samsungctl: debug
    
  2. restart Home Assistant
  3. check the logs for interesting outputs
    2020-02-06 10:11:40 DEBUG (SyncWorker_0) [homeassistant.components.samsungtv] Try config: {'name': 'HomeAssistant', 'description': 'HomeAssistant', 'id': 'ha.component.samsung', 'host': '192.168.12.34', 'method': 'websocket', 'port': None, 'timeout': 31} 2020-02-06 10:12:11 DEBUG (SyncWorker_0) [homeassistant.components.samsungtv] Failing config: {'name': 'HomeAssistant', 'description': 'HomeAssistant', 'id': 'ha.component.samsung', 'host': '192.168.12.34', 'method': 'websocket', 'port': None, 'timeout': 31}, error: timed out 2020-02-06 10:12:11 DEBUG (SyncWorker_0) [homeassistant.components.samsungtv] Try config: {'name': 'HomeAssistant', 'description': 'HomeAssistant', 'id': 'ha.component.samsung', 'host': '192.168.12.34', 'method': 'legacy', 'port': None, 'timeout': 31}
  4. try to start samsungctl directly with this config
    samsungctl --host 192.169.12.34 --method websocket --name HomeAssistant --description HomeAssistant --id ha.component.samsung --timeout 31

Here is the log when I try and use the samsungtv integration, having the same problem as everyone else

2020-02-06 21:42:31 DEBUG (SyncWorker_11) [homeassistant.components.samsungtv] Try config: {'name': 'HomeAssistant', 'description': 'HomeAssistant', 'id': 'ha.component.samsung', 'host': '192.168.1.55', 'method': 'websocket', 'port': None, 'timeout': 31}
2020-02-06 21:42:31 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start
    resp = await task
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/real_ip.py", line 39, in real_ip_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 72, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 135, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 123, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 160, in post
    return await super().post(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 50, in wrapper
    result = await method(view, request, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 89, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 130, in async_configure
    result = await self._async_handle_step(flow, cur_step["step_id"], user_input)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 172, in _async_handle_step
    result: Dict = await getattr(flow, method)(user_input)
  File "/usr/src/homeassistant/homeassistant/components/samsungtv/config_flow.py", line 170, in async_step_confirm
    result = await self.hass.async_add_executor_job(self._try_connect)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/samsungtv/config_flow.py", line 92, in _try_connect
    with Remote(config.copy()):
  File "/usr/local/lib/python3.7/site-packages/samsungctl/remote.py", line 11, in __init__
    self.remote = RemoteWebsocket(config)
  File "/usr/local/lib/python3.7/site-packages/samsungctl/remote_websocket.py", line 30, in __init__
    self._read_response()
  File "/usr/local/lib/python3.7/site-packages/samsungctl/remote_websocket.py", line 67, in _read_response
    response = self.connection.recv()
  File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 310, in recv
    opcode, data = self.recv_data()
  File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 327, in recv_data
    opcode, frame = self.recv_data_frame(control_frame)
  File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 340, in recv_data_frame
    frame = self.recv_frame()
  File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 374, in recv_frame
    return self.frame_buffer.recv_frame()
  File "/usr/local/lib/python3.7/site-packages/websocket/_abnf.py", line 383, in recv_frame
    frame.validate(self.skip_utf8_validation)
  File "/usr/local/lib/python3.7/site-packages/websocket/_abnf.py", line 182, in validate
    raise WebSocketProtocolException("Invalid close opcode.")
websocket._exceptions.WebSocketProtocolException: Invalid close opcode.

Does the same happen when calling with samsungctl? And does the TV worked before with samsungtv integration?

And does the TV worked before with samsungtv integration?

Yes, the integration worked before the yesterday's update to 105. It worked like media_player.

I'll add my experience (hass in venv 0.105.1) using yaml.
If I start with
```samsungtv:

  • host: 192.168.0.52
    port: 55000
    name: samsung_smart_tv
I get the same config_flow error.
However If I change to:

samsungtv:

  • host: 192.168.0.52

port: 55000 #Default is 55000

name: samsung_smart_tv

```
Everything starts working.
I also noticed in the UI that the Samsung Integration gets created (but with no devices).

Also, I find that after this, I can remove all the samsung yaml config, and reboot and the samsung media player is still there (not being removed), and it is still showing in the UI Integration, I have to remove it from the UI as well to remove the samsung media player.

@tommyjlong

First, port 55000 is used for legacy devices so the stacktrace could not be the same as mentioned above. This was from a websocket connection on port 8001.

Second, what you realized is exactly how it was designed. A manual yaml configuration will be once imported into the config registry. Afterwards it will be ignored unless the entry gets removed. As been defined by hand the entry has no information about the device, just the ip. So there is no connection between the device and the media_player entity.
Nonetheless, when later the same TV will be discovered by ssdp the device information will be updated and then be visible in the ui (after a restart, this is an open point).

When starting directly with the discovered TV all is instantly fine.

@tommyjlong long story short, not the same issue. I don't see an issue at all.

Found https://github.com/websocket-client/websocket-client/issues/136. Seems to be an invalid websocket message. So we need a workaround. Can somebody test if this, as the message says, happening on close? Maybe we could just catch this exception and ignore it. We just want to close the connection, so a bad response isn't critical.

  1. try to start samsungctl directly with this config
    samsungctl --host 192.169.12.34 --method websocket --name HomeAssistant --description HomeAssistant --id ha.component.samsung --timeout 31

@KuChar91 @rosscullen @size9ed Could somebody try to run this command. I've added this high timeout, maybe the TVs don't like it. My legacy TV needs this. In that time I've to accept a popup message asking for authorization.

Same issue as the others, just wanted to add my details if it helps.

I have 3 Samsung TVs, I have never configured them for HA before. All 3 get found by discovery and discovery showed the model numbers. 2 of them added OK, the 3rd has the issue described above.

  1. UN32F5500, integration works
  2. UN55ES7100, integration works
  3. QN75Q7FAM, integration does not work

Pretty new to HA, unsure how to help @escoand by running the command at the moment but will look into how.

If I'm right and the timeout is the problem, this should fix our problems: https://github.com/escoand/home-assistant/commit/3c5ff511b0a02bf3c4e1b5adf361e736b6d8e509

Can I somehow update it manually or just wait for another HA update?

@KuChar91 depends how you use HA. First you could try the samsungctl commands with the high timeout.

I am using HassIO + HassOS, how would I test that command?

@beloso connect to Hass.io "SSH & Web Terminal" addon and enter

apk add py3-websocket-client
pip3 install samsungctl
samsungctl ...

Here is the output, seems like the same error as in HA
My TV is UE40MU6125K.

➜  ~  samsungctl --host 192.168.2.115 --method websocket --name HomeAssistant --description HomeAssistant --id ha.component.samsung --timeout 31
Traceback (most recent call last):
  File "/usr/bin/samsungctl", line 11, in <module>
    load_entry_point('samsungctl==0.7.1', 'console_scripts', 'samsungctl')()
  File "/usr/lib/python3.8/site-packages/samsungctl/__main__.py", line 110, in main
    with Remote(config) as remote:
  File "/usr/lib/python3.8/site-packages/samsungctl/remote.py", line 11, in __init__
    self.remote = RemoteWebsocket(config)
  File "/usr/lib/python3.8/site-packages/samsungctl/remote_websocket.py", line 30, in __init__
    self._read_response()
  File "/usr/lib/python3.8/site-packages/samsungctl/remote_websocket.py", line 67, in _read_response
    response = self.connection.recv()
  File "/usr/lib/python3.8/site-packages/websocket/_core.py", line 313, in recv
    opcode, data = self.recv_data()
  File "/usr/lib/python3.8/site-packages/websocket/_core.py", line 330, in recv_data
    opcode, frame = self.recv_data_frame(control_frame)
  File "/usr/lib/python3.8/site-packages/websocket/_core.py", line 343, in recv_data_frame
    frame = self.recv_frame()
  File "/usr/lib/python3.8/site-packages/websocket/_core.py", line 377, in recv_frame
    return self.frame_buffer.recv_frame()
  File "/usr/lib/python3.8/site-packages/websocket/_abnf.py", line 383, in recv_frame
    frame.validate(self.skip_utf8_validation)
  File "/usr/lib/python3.8/site-packages/websocket/_abnf.py", line 182, in validate
    raise WebSocketProtocolException("Invalid close opcode.")
websocket._exceptions.WebSocketProtocolException: Invalid close opcode.

I have exactly the same problem with the UE40MU6100 (error log: https://pastebin.com/hihueway), the previous method with media_player worked fine (no play/pause etc but the state was always right). I'm now using the custom component: https://github.com/roberodin/ha-samsungtv-custom play/pause etc works now but the state is not correct.

Does someone maybe have the old method as a custom compontent so that can be used or will this command fix the problems with the new method:

@beloso connect to Hass.io "SSH & Web Terminal" addon and enter

apk add py3-websocket-client
pip3 install samsungctl
samsungctl ...

If I'm right and the timeout is the problem, this should fix our problems: escoand@3c5ff51

I don't think this is the case. In my case, the error shows up instantaneously. It doesn't even take a second.

@beloso can you test the same command with timeout 1? If this working we have the reason.

@mkArtak I do also not think it's timing out, but maybe the TV responds in a wrong way.

@escoand here is the output:

➜  ~  samsungctl --host 192.168.2.115 --method websocket --name HomeAssistant --description HomeAssistant --id ha.component.samsung --timeout 1
Traceback (most recent call last):
  File "/usr/bin/samsungctl", line 11, in <module>
    load_entry_point('samsungctl==0.7.1', 'console_scripts', 'samsungctl')()
  File "/usr/lib/python3.8/site-packages/samsungctl/__main__.py", line 110, in main
    with Remote(config) as remote:
  File "/usr/lib/python3.8/site-packages/samsungctl/remote.py", line 11, in __init__
    self.remote = RemoteWebsocket(config)
  File "/usr/lib/python3.8/site-packages/samsungctl/remote_websocket.py", line 30, in __init__
    self._read_response()
  File "/usr/lib/python3.8/site-packages/samsungctl/remote_websocket.py", line 67, in _read_response
    response = self.connection.recv()
  File "/usr/lib/python3.8/site-packages/websocket/_core.py", line 313, in recv
    opcode, data = self.recv_data()
  File "/usr/lib/python3.8/site-packages/websocket/_core.py", line 330, in recv_data
    opcode, frame = self.recv_data_frame(control_frame)
  File "/usr/lib/python3.8/site-packages/websocket/_core.py", line 343, in recv_data_frame
    frame = self.recv_frame()
  File "/usr/lib/python3.8/site-packages/websocket/_core.py", line 377, in recv_frame
    return self.frame_buffer.recv_frame()
  File "/usr/lib/python3.8/site-packages/websocket/_abnf.py", line 383, in recv_frame
    frame.validate(self.skip_utf8_validation)
  File "/usr/lib/python3.8/site-packages/websocket/_abnf.py", line 182, in validate
    raise WebSocketProtocolException("Invalid close opcode.")
websocket._exceptions.WebSocketProtocolException: Invalid close opcode.

Looks like the same to me.
Both commands fail instantly. They don't wait for the timeout period.

__EDIT:__ I will not have access to the TV during the weekend, but I will gladly help out with debugging next week.

Same errors for me, so maybe I could help out

Uhh, then we need to test the parameters a bit. You could try to set only the port 8001 but not the method and next set both. And also the description was changed.
It seems something doesn't satisfy the TVs expectations.

... and please also use --verbose.

Just port 8001

➜  ~  samsungctl --host 192.168.2.115 --port 8001 --name HomeAssistant --description HomeAssistant --id ha.component.samsung --timeout 31 --verbose
Sending handshake.
Error: Connection closed!

Both port 8001 and method

➜  ~  samsungctl --host 192.168.2.115 --port 8001 --method websocket --name HomeAssistant --description HomeAssistant --id ha.component.samsung --timeout 31 --verbose
Traceback (most recent call last):
  File "/usr/bin/samsungctl", line 11, in <module>
    load_entry_point('samsungctl==0.7.1', 'console_scripts', 'samsungctl')()
  File "/usr/lib/python3.8/site-packages/samsungctl/__main__.py", line 110, in main
    with Remote(config) as remote:
  File "/usr/lib/python3.8/site-packages/samsungctl/remote.py", line 11, in __init__
    self.remote = RemoteWebsocket(config)
  File "/usr/lib/python3.8/site-packages/samsungctl/remote_websocket.py", line 30, in __init__
    self._read_response()
  File "/usr/lib/python3.8/site-packages/samsungctl/remote_websocket.py", line 67, in _read_response
    response = self.connection.recv()
  File "/usr/lib/python3.8/site-packages/websocket/_core.py", line 313, in recv
    opcode, data = self.recv_data()
  File "/usr/lib/python3.8/site-packages/websocket/_core.py", line 330, in recv_data
    opcode, frame = self.recv_data_frame(control_frame)
  File "/usr/lib/python3.8/site-packages/websocket/_core.py", line 343, in recv_data_frame
    frame = self.recv_frame()
  File "/usr/lib/python3.8/site-packages/websocket/_core.py", line 377, in recv_frame
    return self.frame_buffer.recv_frame()
  File "/usr/lib/python3.8/site-packages/websocket/_abnf.py", line 383, in recv_frame
    frame.validate(self.skip_utf8_validation)
  File "/usr/lib/python3.8/site-packages/websocket/_abnf.py", line 182, in validate
    raise WebSocketProtocolException("Invalid close opcode.")
websocket._exceptions.WebSocketProtocolException: Invalid close opcode.

@beloso I don't get it. Has it ever worked? There are newer TVs which use 8002, but this is encrypted afaik.

It used to work a long time ago, it has been broken for me since around 0.81 (#17802).
It was using port 8001 back then. I think there was a samsung firmware update at the time also, amongst all that chaos the TV never integrated with HA ever again.
Some people discuss custom components on that ticket. But I never bothered with those.

@beloso Then you have to wait for https://github.com/home-assistant/home-assistant/pull/31537. It should add support for this newer devices.

Anybody with a working device until 0.104?

Personally I don't like all the custom components. There are so many out there but nobody tried or is willing to integrate his into HA directly.

Alright, I'll follow it.
I bought this TV around 2018, I don't know what is the year it was released. I guess I didn't thought it was that recent.

@escoand I have a Samsung TV that was working at least in a basic sense that I could see if it was on or off, but not control it. Which for what I was using it for was enough.
Worked in .104 not working now in .105.x
When trying to add, via Integration I enter the IP address and it quickly fails to add with "unknown error occurred"

HA log

2020-02-07 18:32:01 DEBUG (SyncWorker_0) [homeassistant.components.samsungtv] Try config: {'name': 'HomeAssistant', 'description': 'HomeAssistant', 'id': 'ha.component.samsung', 'host': '192.168.200.52', 'method': 'websocket', 'port': None, 'timeout': 31}
2020-02-07 18:32:01 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start
    resp = await task
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/real_ip.py", line 39, in real_ip_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 72, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 135, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 123, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 160, in post
    return await super().post(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 50, in wrapper
    result = await method(view, request, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 89, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 130, in async_configure
    result = await self._async_handle_step(flow, cur_step["step_id"], user_input)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 172, in _async_handle_step
    result: Dict = await getattr(flow, method)(user_input)
  File "/usr/src/homeassistant/homeassistant/components/samsungtv/config_flow.py", line 129, in async_step_user
    result = await self.hass.async_add_executor_job(self._try_connect)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/samsungtv/config_flow.py", line 92, in _try_connect
    with Remote(config.copy()):
  File "/usr/local/lib/python3.7/site-packages/samsungctl/remote.py", line 11, in __init__
    self.remote = RemoteWebsocket(config)
  File "/usr/local/lib/python3.7/site-packages/samsungctl/remote_websocket.py", line 30, in __init__
    self._read_response()
  File "/usr/local/lib/python3.7/site-packages/samsungctl/remote_websocket.py", line 67, in _read_response
    response = self.connection.recv()
  File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 310, in recv
    opcode, data = self.recv_data()
  File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 327, in recv_data
    opcode, frame = self.recv_data_frame(control_frame)
  File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 340, in recv_data_frame
    frame = self.recv_frame()
  File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 374, in recv_frame
    return self.frame_buffer.recv_frame()
  File "/usr/local/lib/python3.7/site-packages/websocket/_abnf.py", line 383, in recv_frame
    frame.validate(self.skip_utf8_validation)
  File "/usr/local/lib/python3.7/site-packages/websocket/_abnf.py", line 182, in validate
    raise WebSocketProtocolException("Invalid close opcode.")
websocket._exceptions.WebSocketProtocolException: Invalid close opcode.

Running the samsungctl:

samsungctl --host 192.168.200.52 --port 8001 --name HomeAssistant --description HomeAssistant --id ha.component.samsung --timeout 31 --verbose > a.out
Sending handshake.
Traceback (most recent call last):
  File "/usr/bin/samsungctl", line 11, in <module>
    load_entry_point('samsungctl==0.7.1', 'console_scripts', 'samsungctl')()
  File "/usr/lib/python3.8/site-packages/samsungctl/__main__.py", line 110, in main
    with Remote(config) as remote:
  File "/usr/lib/python3.8/site-packages/samsungctl/remote.py", line 9, in __init__
    self.remote = RemoteLegacy(config)
  File "/usr/lib/python3.8/site-packages/samsungctl/remote_legacy.py", line 32, in __init__
    self._read_response(True)
  File "/usr/lib/python3.8/site-packages/samsungctl/remote_legacy.py", line 95, in _read_response
    raise exceptions.UnhandledResponse(response)
samsungctl.exceptions.UnhandledResponse: b'tml><body><h1>403</h1></body></html>'

@shortbloke OK, this makes sense. Until 0.104 we just tried to send keys to the websocket devices. If they respond with 403 (forbidden) we took this at least as a sign for a powered on device.

With 0.105 we now check the connection status before we add the device to HA. And we do this with a with statement. Obviously samsungctl is not able to handle the 403 correctly when using this type of code.

As a quick fix I'll now add code to catch the exception and show a message that the device is currently not supported. Yes, I know this is a step back but mature support is on the way. @MartinHjelmare Are you fine with this or should I re-add the previous at-least-power-state-recognition-support?

I can't answer based on this issue. I'll look at the PR.

@beloso Then you have to wait for #31537. It should add support for this newer devices.

Anybody with a working device until 0.104?

Personally I don't like all the custom components. There are so many out there but nobody tried or is willing to integrate his into HA directly.

My device worked in 0.104.x (model: UE40MU6100), only the state but that was everything I needed, now it doesn't do anything anymore. Would be great to see the power state recognition return.

@werra11 sorry, but you have to work for #31537

    homeassistant.components.samsungtv: debug
    samsungctl: debug

Better late than never.... logs from HA on my instance:
2020-02-08 08:06:18 DEBUG (SyncWorker_4) [homeassistant.components.samsungtv] Try config: {'name': 'HomeAssistant', 'description': 'HomeAssistant', 'id': 'ha.component.samsung', 'host': '192.168.5.2', 'method': 'websocket', 'port': None, 'timeout': 31} 2020-02-08 08:06:18 ERROR (MainThread) [aiohttp.server] Error handling request Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start resp = await task File "/usr/local/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle resp = await handler(request) File "/usr/local/lib/python3.7/site-packages/aiohttp/web_middlewares.py", line 119, in impl return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/real_ip.py", line 39, in real_ip_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 72, in ban_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 135, in auth_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 123, in handle result = await result File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 160, in post return await super().post(request, flow_id) File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 50, in wrapper result = await method(view, request, *args, **kwargs) File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 89, in post result = await self._flow_mgr.async_configure(flow_id, data) File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 130, in async_configure result = await self._async_handle_step(flow, cur_step["step_id"], user_input) File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 172, in _async_handle_step result: Dict = await getattr(flow, method)(user_input) File "/usr/src/homeassistant/homeassistant/components/samsungtv/config_flow.py", line 129, in async_step_user result = await self.hass.async_add_executor_job(self._try_connect) File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/usr/src/homeassistant/homeassistant/components/samsungtv/config_flow.py", line 92, in _try_connect with Remote(config.copy()): File "/usr/local/lib/python3.7/site-packages/samsungctl/remote.py", line 11, in __init__ self.remote = RemoteWebsocket(config) File "/usr/local/lib/python3.7/site-packages/samsungctl/remote_websocket.py", line 30, in __init__ self._read_response() File "/usr/local/lib/python3.7/site-packages/samsungctl/remote_websocket.py", line 67, in _read_response response = self.connection.recv() File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 310, in recv opcode, data = self.recv_data() File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 327, in recv_data opcode, frame = self.recv_data_frame(control_frame) File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 340, in recv_data_frame frame = self.recv_frame() File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 374, in recv_frame return self.frame_buffer.recv_frame() File "/usr/local/lib/python3.7/site-packages/websocket/_abnf.py", line 383, in recv_frame frame.validate(self.skip_utf8_validation) File "/usr/local/lib/python3.7/site-packages/websocket/_abnf.py", line 182, in validate raise WebSocketProtocolException("Invalid close opcode.") websocket._exceptions.WebSocketProtocolException: Invalid close opcode.

I've a Samsung ue55mu6400u that uses port 8002. It's never could control the TV, just report its status which was sufficient for my needs.

Tried running the samsungctl command as well (tried 8001 and 8002):

ash-4.3# docker exec -it dc63888959xx samsungctl --host 192.168.5.2 --port 8002 --name HomeAssistant --description HomeAssistant --id ha.component.samsung --timeout 31 --verbose Sending handshake. Error: Connection closed! ash-4.3# docker exec -it dc63888959xx samsungctl --host 192.168..2 --port 8001 --name HomeAssistant --description HomeAssistant --id ha.component.samsung --timeout 31 --verbose Sending handshake. Traceback (most recent call last): File "/usr/local/bin/samsungctl", line 8, in <module> sys.exit(main()) File "/usr/local/lib/python3.7/site-packages/samsungctl/__main__.py", line 110, in main with Remote(config) as remote: File "/usr/local/lib/python3.7/site-packages/samsungctl/remote.py", line 9, in __init__ self.remote = RemoteLegacy(config) File "/usr/local/lib/python3.7/site-packages/samsungctl/remote_legacy.py", line 32, in __init__ self._read_response(True) File "/usr/local/lib/python3.7/site-packages/samsungctl/remote_legacy.py", line 95, in _read_response raise exceptions.UnhandledResponse(response) samsungctl.exceptions.UnhandledResponse: b'tml><body><h1>403</h1></body></html>' ash-4.3#

Hope this is of some use.

my 2016 tv is working great in 0.105.2

@rosscullen Then you've to wait as well.
@Hackashaq666 That's fine. Either it's using the legacy connection or the mentioned firmware update was never done. Can you verify this (logs, ...)?

@rosscullen Then you've to wait as well.
@Hackashaq666 That's fine. Either it's using the legacy connection or the mentioned firmware update was never done. Can you verify this (logs, ...)?

No worries, let me know if you need me to test anything in the future @escoand

@rosscullen Then you've to wait as well.
@Hackashaq666 That's fine. Either it's using the legacy connection or the mentioned firmware update was never done. Can you verify this (logs, ...)?

No worries, let me know if you need me to test anything in the future @escoand

OK, I need to correct my previous post. All is working with my 2016 TV in 0.105.2 once the TV is on.
Volume controls, input control, and channel buttons (RWD, FWD) all work as they should.
However, once TV is turned off there is no option to turn it on.
I setup the TV in homeassistat using the integration, no yaml entries.

2020-02-09 14:34:11 INFO (MainThread) [homeassistant.setup] Setting up samsungtv 2020-02-09 14:34:11 INFO (MainThread) [homeassistant.setup] Setup of domain samsungtv took 0.0 seconds. 2020-02-09 14:34:56 INFO (MainThread) [homeassistant.components.discovery] Unknown service discovered: dlna_dmr {'host': 'REDACTED', 'port': 9197, 'ssdp_description': 'http://REDACTED:9197/dmr', 'name': '[TV] Samsung 6 Series (55)', 'model_name': 'UN55KU6300', 'model_number': 'AllShare1.0', 'serial': 'REDACTED', 'manufacturer': 'Samsung Electronics', 'udn': 'REDACTED', 'upnp_device_type': 'urn:schemas-upnp-org:device:MediaRenderer:1'} 2020-02-09 14:34:56 INFO (MainThread) [homeassistant.components.discovery] Unknown service discovered: samsung_tv {'host': 'REDACTED', 'port': 7676, 'ssdp_description': 'http://REDACTED:7676/rcr/', 'name': 'Samsung 6 Series (55)', 'model_name': 'UN55KU6300', 'model_number': '1.0', 'serial': 'REDACTED', 'manufacturer': 'Samsung Electronics', 'udn': 'uuid:REDACTED', 'upnp_device_type': 'urn:samsung.com:device:RemoteControlReceiver:1'}

@Hackashaq666 Turning on is afaik only possible for some devices with wake-on-lan. There is a detailed description on the samsungtv docs page: https://www.home-assistant.io/integrations/samsungtv/#wake-up-tv
Sadly, this log is not enough to decide if you have a legacy or websocket TV. We need a debug log.

Updated 0.105.3, this issue still exists. Instantly fails as soon as you hit submit to configure. Thank you for attempting to fix this.

Log Details (ERROR)
Mon Feb 10 2020 23:06:02 GMT-0800 (Pacific Standard Time)
Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start
    resp = await task
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/real_ip.py", line 39, in real_ip_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 72, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 135, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 123, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 160, in post
    return await super().post(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 50, in wrapper
    result = await method(view, request, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 89, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 130, in async_configure
    result = await self._async_handle_step(flow, cur_step["step_id"], user_input)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 172, in _async_handle_step
    result: Dict = await getattr(flow, method)(user_input)
  File "/usr/src/homeassistant/homeassistant/components/samsungtv/config_flow.py", line 170, in async_step_confirm
    result = await self.hass.async_add_executor_job(self._try_connect)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/samsungtv/config_flow.py", line 92, in _try_connect
    with Remote(config.copy()):
  File "/usr/local/lib/python3.7/site-packages/samsungctl/remote.py", line 11, in __init__
    self.remote = RemoteWebsocket(config)
  File "/usr/local/lib/python3.7/site-packages/samsungctl/remote_websocket.py", line 30, in __init__
    self._read_response()
  File "/usr/local/lib/python3.7/site-packages/samsungctl/remote_websocket.py", line 67, in _read_response
    response = self.connection.recv()
  File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 310, in recv
    opcode, data = self.recv_data()
  File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 327, in recv_data
    opcode, frame = self.recv_data_frame(control_frame)
  File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 340, in recv_data_frame
    frame = self.recv_frame()
  File "/usr/local/lib/python3.7/site-packages/websocket/_core.py", line 374, in recv_frame
    return self.frame_buffer.recv_frame()
  File "/usr/local/lib/python3.7/site-packages/websocket/_abnf.py", line 383, in recv_frame
    frame.validate(self.skip_utf8_validation)
  File "/usr/local/lib/python3.7/site-packages/websocket/_abnf.py", line 182, in validate
    raise WebSocketProtocolException("Invalid close opcode.")
websocket._exceptions.WebSocketProtocolException: Invalid close opcode.

@snook Yes, as it was not fixed in 0.105.3.

@snook Yes, as it was not fixed in 0.105.3.

Thanks, still new to HA. Saw it in the notes and didn't notice the beta fix note. Beta fixes are available by selecting the beta channel in Supervisor?

Where have you seen it? Here are the release notes: https://github.com/home-assistant/home-assistant/releases
It'll be in 0.106 or should we add it to a minor 0.105, @balloob?

Where have you seen it? Here are the release notes: https://github.com/home-assistant/home-assistant/releases
It'll be in 0.106 or should we add it to a minor 0.105, @balloob?

I saw Samsung fixes mentioned here https://www.home-assistant.io/blog/2020/02/05/release-105/#beta-fixes

Now I'm realizing those notes were there for the 105.0 release. Reading on my phone I didn't see the whole picture and thought the listed beta fixes were for 105.3 right above them.

version 0.105.4 and UE75MU6179, same issue. custom version with port 8002 can at least connect to tv

@twsl error will be fixed with 0.106. TV will work with mentioned PR.

@escoand with 0.106 I now get "Aborted" - "The Samsung TV device is currently not supported".

What is the plan for handling old TVs where the socket error was at least used for determining power state? Is that capability coming back, or do I need to work on a new method?

@shortbloke You wait for #31537 and will have full featured support for your device.

@escoand Tried 0.107 which I believe has the update.
I still can't add it. All I want is to know if it's on or not. Which seems to have been lost in these series of updates. Are we not going to get this capability back?

2020-03-19 10:53:14 DEBUG (SyncWorker_17) [homeassistant.components.samsungtv] Try config: {'name': 'HomeAssistant', 'description': 'HomeAssistant', 'id': 'ha.component.samsung', 'host': '192.168.200.52', 'method': 'legacy', 'port': None, 'timeout': 31}
2020-03-19 10:53:14 DEBUG (SyncWorker_17) [homeassistant.components.samsungtv] Failing config: {'name': 'HomeAssistant', 'description': 'HomeAssistant', 'id': 'ha.component.samsung', 'host': '192.168.200.52', 'method': 'legacy', 'port': None, 'timeout': 31}, error: [Errno 111] Connection refused
2020-03-19 10:53:14 DEBUG (SyncWorker_17) [homeassistant.components.samsungtv] Try config: {'name': 'HomeAssistant', 'host': '192.168.200.52', 'method': 'websocket', 'port': 8001, 'timeout': 31}
2020-03-19 10:53:14 DEBUG (SyncWorker_17) [homeassistant.components.samsungtv] Working but unsupported config: {'name': 'HomeAssistant', 'host': '192.168.200.52', 'method': 'websocket', 'port': 8001, 'timeout': 31}

Doesn't work for me eigher.
Here is my api data:

{
  "device": {
    "FrameTVSupport": "false",
    "GamePadSupport": "true",
    "ImeSyncedSupport": "true",
    "OS": "Tizen",
    "TokenAuthSupport": "true",
    "VoiceSupport": "true",
    "countryCode": "DE",
    "description": "Samsung DTV RCR",
    "developerIP": "...",
    "developerMode": "1",
    "duid": "uuid:xxx",
    "firmwareVersion": "Unknown",
    "id": "uuid:xxx",
    "ip": "192.168.1.23",
    "model": "17_KANTM_UHD_BASIC",
    "modelName": "UE75MU6179",
    "name": "[TV] Samsung 6 Series (75)",
    "networkType": "wired",
    "resolution": "3840x2160",
    "smartHubAgreement": "true",
    "type": "Samsung SmartTV",
    "udn": "uuid:xxx",
    "wifiMac": "xxx"
  },
  "id": "uuid:xxx",
  "isSupport": "{\"DMP_DRM_PLAYREADY\":\"false\",\"DMP_DRM_WIDEVINE\":\"false\",\"DMP_available\":\"true\",\"EDEN_available\":\"true\",\"FrameTVSupport\":\"false\",\"ImeSyncedSupport\":\"true\",\"TokenAuthSupport\":\"true\",\"remote_available\":\"true\",\"remote_fourDirections\":\"true\",\"remote_touchPad\":\"true\",\"remote_voiceControl\":\"true\"}\n",
  "name": "[TV] Samsung 6 Series (75)",
  "remote": "1.0",
  "type": "Samsung SmartTV",
  "uri": "http://192.168.1.23:8001/api/v2/",
  "version": "2.0.25"
}

In 0.107 this fix was listed under 'beta fixed' section. Does that means that I need to enable some kind of 'beta mode'?

Please look at #32942.

Was this page helpful?
0 / 5 - 0 ratings