Thank you for your input. I think I did: I setup IP masquerading between Home Assistant and the Samsung TV host. What exactly that means in your specific situation depends a lot on the specific details of your network setup and deployed router.
Since this issue is caused by a more sophisticated network setup than what most users have (network segmentation with multiple subnets and a router deployed between segments), one can assume that most people running into this problem are more advanced network administrators than your average users and either already familiar with how IP masquerading works, how to set it up for their specific situation and/or able to find that information easily online as it applies to their specific setup.
On a high level, for those that maybe do not run into this problem but are just curious to learn more what this is even about:
I’ve been trying to integrate my Samsung TV into my smart home since I bought it maybe a year ago. While Home Assistant discovered the TV it always failed to connect and integrate it. I have a relatively complex home network setup where I utilize multiple VLANs, subnets and WIFI networks to separate specific parts of my network from each other. Most importantly my IOT devices live on a part of the network that doesn’t have access to my regular home network (like my PC or my NAS).
Since I’ve setup routing and firewall rules between those parts of my network such that Home Assistant can communicate with the Samsung TV, it shouldn’t lead to any issues with the communication between them and Home Assistant can communicate with many other devices on the IOT network no problem. But here we are with communication problems nevertheless.
The Samsung TV Integration documentation has never been really helpful in understanding or solving that problem. It mentioned that the integration had issues communicating with some versions of Samsung TVs and I thought maybe I was just unlucky and got one of those and didn’t bother with it any more.
In one of the more recent Home Assistant updates I noticed some bug fixes in the Samsung TV integration and decided to give it another try. My first attempt failed again as it always had. Home Assistant failed to connect to the Samsung TV. I took another look at the integration documentation and to my surprise found a new section in the documentation (quoted above). The updated documentation said that the TV itself declines any connection attempts from hosts that are not on the same subnet as the TV – exactly my situation! The documentation also suggested two solutions: using a proxy or IP masquerading. While the documentation isn’t explicit about this, in both cases the goal is to make the connection “bounce” off of a host that is on the same subnet as the Samsung TV.
In the proxy case you would install and setup a proxy server (I assume a HTTP proxy, because I believe the connection in question is a HTTP/WebSocket connection – but I’m not sure, so don’t quote me on this) on any host that Home Assistant can connect to on the same subnet as your Samsung TV and have Home Assistant use that proxy server instead of trying to connect directly to the Samsung TV. The proxy will forward the connection to the Samsung TV and to the TV it will look like the connection is coming from the same subnet and accept the connection.
However, I ended up using IP masquerading since it was more convenient in my case. Most non-network nerds are probably unfamiliar with the term IP masquerading, but might have heard of something called NAT (Network Address Translation) that your Internet router is doing. Basically what it does is provide access to multiple clients on your local network to the internet by replacing (“translating” or “masquerading”) the clients local network IP addresses with the routers public internet IP address while communication between your local clients and hosts on the internet passes back and forth. Hosts on the internet will only see your routers IP address and your router becomes responsible for delivering packets to the correct local network IP addresses when it receives them.
In this case, what you need to do is to setup NAT/IP masquerading on the router between the Home Assistant and the Samsung TV networks – or just between the two hosts or even just the relevant connections. Doing this was relatively straight forward on my ER-X running EdgeRouter. It would require a little more console-fu on your average pure Linux router and might not even be possible on your Internet provider’s off-the-shelve plastic router.
Now, when my Home Assistant instance connects to the Samsung TV it will look to the Samsung TV like the connection is coming from the router’s IP address on it’s subnet and will not refuse the connection attempt.
Voila, the integration now works. What in the end allowed me to understand what was going on and allowed me to fix it was the information that the Samsung TV refuses connections from subnets other the one that it is on.