Samsung TV Binding (Beta)

@andan ,

Good to know it works. Not sure what to do about the sourceName after a refresh, as that is what SmartThings is reporting ie dtv.

I’ll give it some thought now that I know the solution.

@andan ,

Ok, a lot of rework, but this should do it org.openhab.binding.samsungtv-4.3.0-SNAPSHOT.jar.

You can now use dtv to change to digital TV.

Same as before, give it a try and post the results here.

Thanks!

I can confirm that switching to the TV source is now possible with dtv. Thanks for your fix.

A different question: It seems that the Channel channel to switch TV channels by number is internally implemented by sending corresponding key codes for each digit. Is this correct?

If yes, do you have any plans to offer the corresponding SmartThings API tvChannel command? The reason I’m asking is that the API command seems to be much more reliable for my TV model. However, this might be related to the use of a special TV provider service which seems to intercept the key commands for switching to channels based on a service specific list.

Yes, you are right. This is because you can always change channels with the keypad (hopefully), but not everyone has smarthings, and I like to keep things as local as possible - calling a cloud service to change channel on a TV seems unreliable at best.

I totally agree that basic features like switching tv channels should not rely on Cloud services. However, it seems that (at least the newer) Samsung TVs have quite limited local control capabilities, and using keys for switching channels might not work in specific situations.

E.g., when you browse within the home screen, my observation is that the only reliable way to switch to a specific tv channel (e.g. from a predefined channel list) is by using the tvchannel command. So it might be worth to offer a write option to this SmartThings channel. As a workaround, I’'ve implemented a direct API call via a JRuby rule.,

Hi all:

I’m trying to set this up for my 2016 Samsung TV and the Thing is always offline, not sure what to do. I have another Homebridge connection to control the TV on the same server, would that be a problem with 2 connections from the same ip?
Below is the output from api:

{
  "id": "uuid:e1e80173-b2cc-448d-88c8-bb233ee2d347",
  "name": "[TV] Samsung 6 Series (40)",
  "version": "2.1.0",
  "device": {
    "type": "Samsung SmartTV",
    "duid": "uuid:e1e80173-b2cc-448d-88c8-xxxxxxxxxx",
    "model": "16_JAZZL_UHD_BASIC",
    "modelName": "UE40KU6075",
    "description": "Samsung DTV RCR",
    "networkType": "wired",
    "ssid": "6a:xx:xx:xx:xx:xx",
    "ip": "xxx.xx.1.2",
    "firmwareVersion": "Unknown",
    "name": "[TV] Samsung 6 Series (40)",
    "id": "uuid:e1e80173-b2cc-448d-88c8-bb233ee2d347",
    "udn": "uuid:e1e80173-b2cc-448d-88c8-bb233ee2d347",
    "resolution": "3840x2160",
    "countryCode": "DK",
    "msfVersion": "2.1.0",
    "smartHubAgreement": "true",
    "VoiceSupport": "false",
    "GamePadSupport": "true",
    "wifiMac": "68:27:xx:xx:xx:xx",
    "developerMode": "0",
    "developerIP": "",
    "OS": "Tizen"
  },
  "type": "Samsung SmartTV",
  "uri": "http://xxx.xxx.xx.x:8001/api/v2/",
  "remote": "1.0",
  "isSupport": "{\"remote_available\":\"true\",\"remote_fourDirections\":\"true\",\"remote_touchPad\":\"true\",\"remote_voiceControl\":\"false\",\"DMP_available\":\"true\",\"DMP_DRM_PLAYREADY\":\"false\",\"DMP_DRM_WIDEVINE\":\"false\",\"EDEN_available\":\"true\"}"
}

I have tried port 8001, 8002 and 55000 without luck. When I first setup it up in Things file I forgot to turn on the TV, and afterwards I never see any pop up on TV to authorise the connection, does the binding try to re-authorize when the token was not retrieved from the previous try? I have tried:

  1. Enable/disable thing
  2. Rename the thing
    However it just shows the device offline. My configuration is as below:
Thing samsungtv:tv:samsungtizentv [ hostName="xxx.xx.1.2",  port=8002, macAddress="68:xx:xx:xx:xx:xx", protocol="SecureWebSocket", refreshInterval=1000, smartThingsSubscription=false ]

Currently I can control the TV from HomeBridge but would like to use OpenHAB in the future.
Any suggestion where to look? Thanks in advance!

Edit: the log I see when enable the Thing:

2025-02-03 21:49:12.582 [DEBUG] [tv.internal.handler.SamsungTvHandler] - xxx.xx.1.2: Create a Samsung TV Handler for thing 'samsungtv:tv:samsungtizentv'
2025-02-03 21:49:12.588 [DEBUG] [tv.internal.handler.SamsungTvHandler] - xxx.xx.1.2: Initializing Samsung TV handler for uid 'samsungtv:tv:samsungtizentv'
2025-02-03 21:49:12.604 [DEBUG] [tv.internal.handler.SamsungTvHandler] - xxx.xx.1.2: Updated artModeSupported: false PowerState: true(on) artMode2022: false
2025-02-03 21:49:12.605 [DEBUG] [tv.internal.handler.SamsungTvHandler] - xxx.xx.1.2: Configuration: SecureWebSocket, port: 8002, token: , MAC: 68:xx:xx:xx:xx:xx, subscription: false
2025-02-03 21:49:12.605 [DEBUG] [tv.internal.handler.SamsungTvHandler] - xxx.xx.1.2: SmartThings disabled
2025-02-03 21:49:12.605 [DEBUG] [tv.internal.handler.SamsungTvHandler] - xxx.xx.1.2: Check and create missing services
2025-02-03 21:49:12.605 [DEBUG] [tv.internal.handler.SamsungTvHandler] - xxx.xx.1.2: Received value 'artMode':'OFF' for thing 'samsungtv:tv:samsungtizentv'
2025-02-03 21:49:12.605 [DEBUG] [tv.internal.handler.SamsungTvHandler] - xxx.xx.1.2: Received value 'power':'OFF' for thing 'samsungtv:tv:samsungtizentv'
2025-02-03 21:49:12.606 [DEBUG] [tv.internal.handler.SamsungTvHandler] - xxx.xx.1.2: Received value 'artImage':'NULL' for thing 'samsungtv:tv:samsungtizentv'
2025-02-03 21:49:12.606 [DEBUG] [tv.internal.handler.SamsungTvHandler] - xxx.xx.1.2: Received value 'artLabel':'' for thing 'samsungtv:tv:samsungtizentv'
2025-02-03 21:49:12.606 [DEBUG] [tv.internal.handler.SamsungTvHandler] - xxx.xx.1.2: Received value 'sourceApp':'' for thing 'samsungtv:tv:samsungtizentv'
2025-02-03 21:49:12.607 [DEBUG] [tv.internal.handler.SamsungTvHandler] - xxx.xx.1.2: TV is OFFLINE

Edit: some more findings. I noticed even though the Thing is offline and most items don’t have value, but I can use Power switch to turn on the TV, it just that the state is not synced back so after some seconds the Power is off but the TV is indeed turned on. That shows OH can send command to TV however cannot receive state update from TV. I have checked my homebridge connection and it is port 8001 so I assume it’s WebSocket protocol.

@somy
You don’t need the marketplace binding for this - if you are running the latest OH, the binding is included now (samsungtv).

It is likely that you don’t have the UPNP transport protocol installed. If you use the OH default binding, it get loaded automatically, if you load it from marketplace, it does not.

To install, in the console:

feature:install openhab-transport-upnp

This is what the binding uses to detect the TV is online or not.

If you are running OH from a docker container, you also get the same problem, as UPNP multicast messages are not passed by the docker container.

Finally, if you set port 8001, the protocol is “WebSocket”, 8002 is “SecureWebSocket”, but it maybe that your TV does not support port 8002.

1 Like

Hi Nicholas:
Thank you for your reply! I have tried the included binding and also installed UPnP feature, however still can’t seem to get it to work.
So first thing, I’m running OH with docker so most likely I have issue with UPnP. I tried to scan the network to find the TV but it’s not shown after scan. Is UPnP used only for discovery? And how do I know if my TV supports it?
When I turn off the TV I checked my network (Unifi), the TV is completely offline so there shouldn’t be any network activity. My HomeBridge add-on turns on TV with WOL, and afterwards use WebSocket for communication. Is it not how it works with this binding?
I looked into my network connection and can see HomeBridge creates to port 8001, so guess it’s standard WebSocket. When I create the thing manually with WebSocket (Things file) OH doesn’t seem to create the connection as I don’t see any permission from screen. I’m thinking maybe because I missed the authorisation first time when I forgot to turn on TV (there is only 30 seconds). Is there a way to force to re-authorize the connection? (I’m thinking maybe the binding remembers the previous connection was rejected and refuses to re-connect?)
Many thanks in advance!

Edit: strange looks like OH does established a TCP connection to the TV:

java    29390     9001   44u  IPv6 1108450843      0t0  TCP xxx.xx.x.x:47532->xxx.xx.x.x:8001 (ESTABLISHED)

So what I found so far:
when the TV is on and I created the Thing, the binding creates a connection there, and I noticed the Power channel even work to turn on/off TV. When TV is off, the binding lost connection and won’t reconnect to TV.
During the whole time TV thing is offline (based on my understand uPnP doesn’t work).

@somy

Yes, the OH binding works the same way, but it uses UPNP multicast messages broadcast by the TV to determine if the TV is on or off - ie ONLINE/OFFLINE.

If you are running OpenHab in a docker container, these multicast messages are not passed through the container, so the binding will not detect the TV ON/OFF status - and there is nothing I can do about this.

1 Like

I will search for a solution and hopefully it’s not docker limitation as I know many run OH in docker.
Do you mean the binding know the TV is online when it starts to broadcast UPnP data? In which case when the TV is off the Thing will be offline? (I ask because when my TV is off it is disconnected and shown offline in Unifi, so I doubt it can broadcast any data)

Thanks!

@somy
All Samsung TV’s broadcast UPNP multicast messages advertising their services when they come online, and just before they go offline.

The binding listens for the “MediaRenderer” service. When this is broadcast as online, the TV is ON, and the binding goes ONLINE, and checks the TV status to see if it is On or in Standby.

Just before the TV goes into Standby, the “MediaRenderer” service is broadcast as OFFLINE, so the binding uses this to set the binding status (OFFLINE). There is a short period (usually 30 seconds or so) while the TV is in Standby, before it goes completely off (Samsung calls this the “Instant On” feature) - during which time it usually will not respond to WOL packets, as the network card has not completely shut down.

TV ON/OFF/Standby is complex, but it is all triggered by the UPnP multicast packets that all Samsung TV’s send on power ON/OFF (which is why I use it).

If these packets do not make it to the binding (because docker filters them out) - then none of this logic is triggered.

It is also possible that UniFi is filtering these packets (depending on the settings of multicast/broadcast filtering, IGMP snooping, VLAN settings etc) - but most likely it is the docker container, as I have seen this many times before - and I have a UniFi network as well.

1 Like

Hi @Nicholas_Waterton :

It does make perfect sense and it’s a better solution than just checking if the TV is online. I have a fairly complex network setup with VLANs, to make the ws connection possible across VLAN took some weeks, so I guess I will not probably not able to make the uPnP work across VLAN and through Docker.

As a wish for feature request: would it be possible to consider a fallback solution when uPnP isn’t available? One solution could be to ping the TV periondially to check if it’s online, I know it’s a inferior solution but it could work for somebody in my situation :slight_smile:

Thanks for helping me and have a great day!

@somy

You might want to check this out as well: UPnP based discovery does not work on host networked docker container

The problem with detecting if Samsung TV’s are On/Off/Standby etc is very complex, for example the TV’s “wake up” from time to time to send messages to Samsung, even though they are off, and every model year/OS version does it differently.

The UPnP multicast messages are the only consistent thing, and are also very fast - so that’s why they are at the core of the binding.

Thanks also found that post by Google but not sure I understand how to solve the issue. There doesn’t seem to be a conclusion there.

@somy
I was thinking that some success was reported using docker-compose, with a compose.yaml file containing:

services:
  openhab:
    network_mode: host

and

openhab:
     - EXTRA_JAVA_OPTS=-Duser.timezone=${TZ} -Dorg.jupnp.network.useInterfaces=eth0 -Dorg.jupnp.network.useAddresses=192.168.2.27

With your own ethernet interface and ip address (timezone is probably irrelevant).

Hi @Nicholas_Waterton :
Thank you and I will give a try on this.
Do you know if the ip address is the ip of the server that I’m running docker container?
Another question: do you know how to check if uPnP works in OH? I have installed uPnP binding but can only discover my server which I don’t know if it’s correct or not.

Hello all,

i’ve just found a small issue with the plugin.
my Protocoll is sent to “none”.

When the TV is on and i send “on” to the Power then this log entry can be seen after a while:

2025-02-02 22:03:40.289 [WARN ] [b.binding.samsungtv.internal.WolSend] - 192.168.3.48: Service NOT found after 32 attempts: stopping WOL attempts

then the device goes offline and the power switch switches to off.

2025-02-02 22:03:40.291 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'samsungtv:tv:2e7fc64844' changed from ONLINE to OFFLINE
2025-02-02 22:03:40.292 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'SamsungTVSchlafzimmer_Power' changed from ON to OFF

This is a bit problematic because this “off” could be used to turn off other stuff in rules like “when the tv is off then”…

Is it somehow possbile to prevent this “off” if the TV is on?

Thanks

Why are you using the binding with the protocol set to “None”? There is no purpose for this. You need to set the protocol and port to the correct one for your model of TV, then it will work correctly (if your TV supports WOL).

What model TV do you have?

Hi,

I have an older model that is not part of the encrypted series. That’s why I use “none”—I only use it for reading the power state, channel number, and similar information. Additionally, I use it with the TV’s DLNA/UPnP capabilities.

I understand that “none” does not allow control, but my question is: why does the Binding send a Wake-on-LAN (WOL) request at all when the TV is already on and responsive to pings? That is my only concern.

Everything else is working fine, but I’d like to prevent the exception, the device going offline, and the power property switching to “off” even when the TV is actually on.

Thanks,

Franz

@FranzS

How old is old? what is the model number? I suspect you need to set the protocol to “legacy” and port 55000.

The binding doesn’t use pings to determine if the TV is on, it uses the fact that it can connect to the designated port to determine this, then it uses UPnP to detect when the TV goes offline to set the status of the ON/OFF switch.