Samsung TV Binding (Beta)

Thanks for your support!

Screenshot from my TV, you see the TV, HDMI1, HDMI2… source inputs.
There is also the Screen Mirroring source, by selecting this input I can eg share my phone screen to the TV.

Attached my full trace log (log.txt).

This is the part where I switched source to Screen Mirroring. It seems that the device is removed during this step:

2022-01-05 15:11:26.198 [TRACE] [internal.service.MainTVServerService] - 10.0.0.78: Received channel: sourceName, command: REFRESH
2022-01-05 15:11:26.292 [TRACE] [internal.service.MainTVServerService] - 10.0.0.78: Value '0' for ID hasn't changed, ignoring update
2022-01-05 15:11:26.294 [TRACE] [internal.service.MainTVServerService] - 10.0.0.78: Value 'TV' for CurrentExternalSource hasn't changed, ignoring update
2022-01-05 15:11:26.297 [TRACE] [nternal.service.MediaRendererService] - 10.0.0.78: Received channel: volume, command: REFRESH
2022-01-05 15:11:26.310 [DEBUG] [tv.internal.handler.SamsungTvHandler] - 10.0.0.78: Device removed: udn=058
2022-01-05 15:11:26.312 [DEBUG] [tv.internal.handler.SamsungTvHandler] - 10.0.0.78: Shutdown all Samsung services
2022-01-05 15:11:26.312 [DEBUG] [nternal.service.MediaRendererService] - 10.0.0.78: onStatusChanged: status=false
2022-01-05 15:11:26.323 [DEBUG] [tv.internal.handler.SamsungTvHandler] - 10.0.0.78: Shutdown all Samsung services
2022-01-05 15:11:26.324 [DEBUG] [tv.internal.handler.SamsungTvHandler] - 10.0.0.78: TV is Offline
2022-01-05 15:11:26.326 [TRACE] [nternal.service.MediaRendererService] - 10.0.0.78: Received channel: mute, command: REFRESH
2022-01-05 15:11:26.328 [DEBUG] [tv.internal.handler.SamsungTvHandler] - 10.0.0.78: TV is Offline

Here I switched back to source TV:

2022-01-05 15:12:13.578 [DEBUG] [tv.internal.handler.SamsungTvHandler] - 10.0.0.78: remoteDeviceAdded: RemoteControlReceiver, http://10.0.0.78:7676/smp_7_, upnpUDN=0eeb58
2022-01-05 15:12:13.580 [DEBUG] [tv.internal.handler.SamsungTvHandler] - 10.0.0.78: Check and create missing services
2022-01-05 15:12:13.582 [DEBUG] [rnal.service.RemoteControllerService] - 10.0.0.78: Creating a Samsung TV RemoteController service: is UPNP:true
2022-01-05 15:12:13.584 [DEBUG] [rnal.protocol.RemoteControllerLegacy] - 10.0.0.78: Open connection to host '10.0.0.78:55000'
2022-01-05 15:12:13.589 [DEBUG] [rnal.protocol.RemoteControllerLegacy] - 10.0.0.78: Connection successfully opened...querying access
2022-01-05 15:12:13.694 [DEBUG] [rnal.protocol.RemoteControllerLegacy] - 10.0.0.78: Access granted
2022-01-05 15:12:13.696 [DEBUG] [tv.internal.handler.SamsungTvHandler] - 10.0.0.78: Started service for: UE40F6500, RemoteControlReceiver (0eeb58)
2022-01-05 15:12:13.699 [DEBUG] [tv.internal.handler.SamsungTvHandler] - 10.0.0.78: TV is online

@AlexanderVonHumboldt

here are the instructions on how to enable TRACE level logging from the binding documentation:

Separating the Samsung logging into its own file

To separate all the Samsung logging information into a separate file, please edit the file userdata/etc/log4j2.xml as follows:

  1. Add an logger appender definition (including the log file name)
  2. Add a logger definition referencing the appender defined in step 1

Example for logging all DEBUG logs into a separate file samsungtv.log under the standard log folder

<Appenders>
...
    <!-- SamsungTV binding appender -->
    <RollingFile fileName="${sys:openhab.logdir}/samsungtv.log" filePattern="${sys:openhab.logdir}/samsungtv-%d{yyyyMMdd-HHmmss}.log" name="SAMSUNGTV">
        <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n"/>
        <Policies>
            <OnStartupTriggeringPolicy/>
            <SizeBasedTriggeringPolicy size="16 MB"/>
        </Policies>
    </RollingFile>
</Appenders>
<Loggers>
...
    <Logger additivity="false" level="DEBUG" name="org.openhab.binding.samsungtv">
        <AppenderRef ref="SAMSUNGTV"/>
    </Logger>
</Loggers>

If you have problems with the binding, set the log level to TRACE (in place of DEBUG) and post a message with a TRACE log covering 30 seconds before the issue and 30 seconds after (please don’t send me a log with one line that you think is relevant in it, I can’t tell much from this).

This will create a separate log file called samsungtv.log.

Your TV configuration looks normal for an on/off TV (no artMode), so I need to find out if your TV switches on to standby or on mode.

Thanks.

1 Like

@HALLO01

So I can see that when the TV switches to Screen Mirroring, the MediaRenderer service stops. This is the service that is used to determine if the TV is Online/ON or not (as all Samsung TV’s have this service).

There is not much that I can do about that. The TV does not actually turn off - just the power and ONLINE indicators show the TV as OFF and OFFLINE.

I’m afraid it’s just one of those edge cases that the binding has no way of dealing with.

1 Like

@chrismast

Thank you for the link I wanted to look it up myself but this is easier. I entered the KARAF and hit
Log:set TRACE org.openhab.binding.samsungtv

@Nicholas_Waterton
After that I changed the log4j2.xml according to your instructions and changed DEBUG to TRACE

The log file was created but remains empty. Sorry. Maybe there is a general problem with logging on my pi.

@chrismast

If you make the changes to the log4j2.xml file, you don’t have to do anything in the console.

The logging is still probably going to your openhab.log file. Try capturing from that that.

Ok. Got it. There is an issue with the logging. I fixed it with this one:
https://community.openhab.org/t/solved-oh3-logging-not-possible-openhab-log-last-entries-some-days-ago/128127/9

Please find attached the trace (DEBUG)
samsungtv.log (40.4 KB)

@AlexanderVonHumboldt

Are you using my binding? That log looks like it’s from the original binding, not mine.

You need to uninstall the original samsungtv binding for the new one to load.

You can tell the difference in the log. The new binding shows the IP address of the TV in each log line (I added this so that you can tell which TV is reporting if you have more than one).

Oh yes. You are right. Apologize. There was a confusion of the used binding when I tried to get the binding access acknowledged by the TV and I had to reinstall it.
I made sure the right binding is installed now and the TV is reacting on it. The TV behaviour is not as consistent anymore.

I will attach the log later. Nevertheless I noticed that your binding is more focussing on The Frame and I have The Serif so my Setup is maybe not the right one for your binding.

Here are the logs. I changed the binding at around 08:58 and used the ART switch and the power switch.
samsungtv.log (283.4 KB)

@AlexanderVonHumboldt

Thanks for the log.

The Serif should work just fine, as it works like a standard TV.

I do really need a TRACE level log to see what is happening in detail, your log is DEBUG level.

having said that I can see a number of problems.

Everything starts out OK, with the TV discovered and configured correctly. There is something wrong with the way you have the volume channel configured.

2022-01-06 09:05:53.307 [DEBUG] [tv.internal.handler.SamsungTvHandler] - 192.168.178.30: Received channel: samsungtv:tv:043aa128-fa86-49dc-a5c1-305fe7ce3caa:volume, command: 40
2022-01-06 09:05:53.308 [WARN ] [rnal.service.RemoteControllerService] - 192.168.178.30: Remote control: wrong command type 40 channel volume

This is the message you get if you send the wrong command type to the volume channel. It should be set up as a Dimmer (are you sending a string?). Anyway, that isn’t the major problem.

You then seem to reconfigure the TV to use port 8001. Port 8001 will NOT work for your TV, and this causes the websockets connection to fail.

There are a lot of messages about the websocket connection failures (and sending commands while the websockets are disconnected), then you change the connection type from websocketsecure to websocket, and port 8002 - this is the wrong connection type for your TV, you MUST use websocketsecure in order for commands to work (like power).

As a result, there are a lot more messages about websocket connection failures.

Finally, you go back to the correct settings, ie websocketsecure and port 8002. at 09:08:14.341.

When you send the artMode OFF command, it is ignored (no artMode). You then send Power OFF, which works, and shuts the TV down (09:08:28.658).

Now you send artMode ON, which actually starts sending the WOL command. WOL can take 10 - 15 seconds to work, but 5 seconds later you send Power ON, which cancels the WOL job, and restarts it. 3 seconds later, you send Power ON again, which does the same. 2 seconds later, you send artMode ON, again cancelling the WOL job.

This keeps going until the TV comes online at 09:09:04.936, however, the websockets are unable to connect for some reason - I suspect the TV is not really on at this point. This cycle of commands and failing websocket connection prevents WOL commands being sent.
Finally the WOL seems to work at 09:09:30.872 (or at least the TV turns on), and the websockets connect.

There are a bunch of errors about the connection order, and I think I have some work to do in the rediscovery process - the websocket connection is a problem when it fails.

Things that you can do:

  1. Set the log to TRACE level
  2. Disconnect the artMode channel - this is confusing things - you don’t have artMode
  3. Be patient, turning the TV on takes up to 30 seconds. the TV is slow to respond to WOL packets. Sending repeated ON commands does not help.
  4. Once the TV is OFF, wait 60 seconds before turning it on (this time can vary depending on the TV).
  5. Fix your volume channel (Item should be Dimmer).

I will work on the rediscovery reliability and update later today.

Thanks for the log - this was very helpful.

UPDATE:
I have uploaded a fixed binding. Please try this out - do not use the artMode switch! try using the Power switch to turn the TV ON and OFF. Please be patient, sometimes WOL can take a few seconds to work, and sometimes you have to wait 60 seconds or so after the TV turns off, before you can turn it back on.

This is because Samsung TV’s do not completely power down immediately after you turn them off (this is called the “instant on” feature). The TV will not respond to WOL until it has fully powered down, which can take 60 seconds or so. During this time the TV only responds to IR commands (from the remote).

If you can post a TRACE log with the new binding, it will help me see if it is now working as expected.

Thanks again.

Hi Nicholas,

please find attached the trace. I recorded one, after removing the model and the thing, deleted the binding, restarted the pi, and made a new installation of the binding from the marketplace, scanned for the thing, added it, acknowledged the TV, created a model without the artswitch (The Serif has ambient mode not art mode as you stated, but maybe similiar functionality from customer point of view), looked up, that volume is recognized as dimmer, was patient.

I changed the logger to TRACE.

I noticed, that key press is not recognized as it is in the samsung binding, so I cannot use it. Then I played around, with power, mute, volume, power.

Thank you very much for your work!
I hope the trace is helpful.
samsungtv.log (318.2 KB)

Update:
I deleted the model and created it again from the thing, again without the art mode and without advanced channels. I tried the key press again and it worked for key_mute. The rest I have not tried.

@AlexanderVonHumboldt

Thanks for the log, glad to see that everything is now working as expected.

I’m not sure what you meant by:

“key press” is one of the new features that I introduced for the keyCode channel. You use it by sending a command like this -4000,KEY_POWER to the keyCode channel (as a string). This would send a 4 second press of the KEY_POWER key (4000ms). You can use any duration, or key, and you can chain them together. I give full instructions in the documentation in the keyCode section.

There is now support for KEY_AMBIENT to put the TV in ambient mode as well.

I did notice you linked the following channels:

  • sourceName
  • channelName
  • programTitle

These channels will not work on your TV, unless you add your TV to the SmartThings App, and create a SmartThings Personal Access Token, which you then enter in the binding configuration.

Channels that do work on your TV, but are not linked include:

  • sourceApp
  • url
  • stopBrowser

Although url and stopBrowser are fairly limited in what they can do. The sourceApp channel shows you the current app running, and allows you to launch apps by sending the name of the app (eg Netflix) to the channel. Sending "" to the channel closes the current app.

Thanks for taking the time to send me the logs - they were a great help.

Is the keycode MediaTrackNext as found the Samsung developer docs supported by these TVs?
I see it’s not in the KeyCode enum but not sure if that was an oversight or not supported.

Would be very useful if available.

Thanks!

According to the documentation, MediaTrackNext is a long press of the fast forward key:
On the basic remote control:

Table 1. Basic remote control key functions

Key Click Key Name Long Press Key Name
“Rewind” MediaRewind MediaTrackPrevious
“Fast Forward” MediaFastForward MediaTrackNext

So to send this to your TV you would send the following to the keyCode channel:
-2000,KEY_FF
I’m not sure what a “long press” duration is, the above would send a 2 second long press of Fast Forward, you may have to experiment with the duration.

The sitemap entry would be:

Switch item=TV_KeyCode label="Media" mappings=["-2000,KEY_REWIND"="Previous","-2000,KEY_FF"="Next"]

Where TV_KeyCode is the item linked to the keyCode channel.

Try this and let me know if it works.

Hello to all,

Did some testing with the binding and instead of the command to install upnp I installed the Upnp Binding (I guess it is the same thing, right?).
I tested that power, mute and volume works correctly with both of my TV’s but when I power them off by the binding or the remote control the Thing does not offline and after that the channels do not update anymore. If I remove the Thing and add it again, all the channels start working again. I tried to stop openHAB clean the cache and start again, but it does not solve this issue.
This is a strange issue and I do not know where to start looking.
Could you please try and help me with this situation?

Thanks in advanced.

Best regards.

@Nicholas_Waterton it seems that the long press just fastforwards for X seconds.
I will continue to research but it’s possible the long press button presses are not compatible programatically. Reference: Samsung remote (CEC) Long-press working in Android but NOT in Kodi

Has anyone else gotten a Long Press working for something else?

@rjduraocosta

I don’t know if installing the UPNP binding is the same thing or not. Maybe you have to configure the UPNP binding somehow. The problem you are describing sounds as though the samsungtv binding is not seeing the UPNP services.

The UPNP service MediaRenderer is used to detect if the TV is ON or OFF.

When you first add the thing the binding probes the configuration, and if it can connect to a RemoteControlService on one of the common ports, it saves the configuration, marks the TV as ON and starts the various channels.

If you turn the TV off, it will send the off command, but if it doesn’t see a MediaRenderer instance go offline, it won’t make the TV Offline (but the channels will disconnect). The same is true if the TV turns on, if the binding does not see a MediaRenderer service for your TV’s ip address, it doesn’t know the TV is on, and won’t start up the channels.

So I think your problem is that either UPNP is disabled on your network, or you do in fact need to install the upnp transport io as I describe in the instructions.

What model TV’s do you have? do you know what year they are?

@Nicholas_Waterton

Thank you very much for your fast reply. Yesterday evening did some more testing with the binding and strangely the TV’s where not detected at all. So today, as i have a test instance of openhabian in a debian server, I did some test with it. Installed UPNP Binding and your Samsung Binding and everything works as expected with no issues. Also downloaded an Android APP UPnP Tool, to try and see if the TV’s appear when they are ON and disappear when they are OFF, and from what I see and understand the behavior is as expected.

Here are the output’s of the https://ip:8002/api/v2/ for both TV’s:

{"device":{"FrameTVSupport":"false","GamePadSupport":"true","ImeSyncedSupport":"true","Language":"pt_PT","OS":"Tizen","PowerState":"on","TokenAuthSupport":"true","VoiceSupport":"false","WallScreenRatio":"0","WallService":"false","countryCode":"PT","description":"Samsung DTV RCR","developerIP":"0.0.0.0","developerMode":"0","duid":"uuid:7ada6874-9ec5-433f-9859-1ca9b4843420","firmwareVersion":"Unknown","id":"uuid:7ada6874-9ec5-433f-9859-1ca9b4843420","ip":"192.168.1.162","model":"19_MUSEL_UHD_BASIC","modelName":"UE55RU7105KXXC","name":"[TV] Samsung 7 Series (55)","networkType":"wired","resolution":"3840x2160","smartHubAgreement":"true","type":"Samsung SmartTV","udn":"uuid:7ada6874-9ec5-433f-9859-1ca9b4843420","wifiMac":"d0:d0:03:05:86:f3"},"id":"uuid:7ada6874-9ec5-433f-9859-1ca9b4843420","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\":\"false\"}\n","name":"[TV] Samsung 7 Series (55)","remote":"1.0","type":"Samsung SmartTV","uri":"https://192.168.1.162:8002/api/v2/","version":"2.0.25"}

{"device":{"FrameTVSupport":"false","GamePadSupport":"true","ImeSyncedSupport":"true","Language":"pt_PT","OS":"Tizen","PowerState":"on","TokenAuthSupport":"true","VoiceSupport":"true","WallScreenRatio":"0","WallService":"false","countryCode":"PT","description":"Samsung DTV RCR","developerIP":"0.0.0.0","developerMode":"0","duid":"uuid:d08d67ff-a2f8-4d5a-9416-f392c59aeb3d","firmwareVersion":"Unknown","id":"uuid:d08d67ff-a2f8-4d5a-9416-f392c59aeb3d","ip":"192.168.1.163","model":"19_MUSEM_UHD","modelName":"UE65RU8005UXXC","name":"[TV] Samsung 8 Series (65)","networkType":"wired","resolution":"3840x2160","smartHubAgreement":"true","type":"Samsung SmartTV","udn":"uuid:d08d67ff-a2f8-4d5a-9416-f392c59aeb3d","wifiMac":"d4:9d:c0:1d:8a:b2"},"id":"uuid:d08d67ff-a2f8-4d5a-9416-f392c59aeb3d","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 8 Series (65)","remote":"1.0","type":"Samsung SmartTV","uri":"https://192.168.1.163:8002/api/v2/","version":"2.0.25"}

Both models are from 2019.

Today I am going to do further testing and keep you posted on the results.

Thanks again.

Best regards.

@rjduraocosta

That’s odd.

Can you capture a TRACE level log from the problem instance of OH (I need a good 60 seconds of log or more, where the TV’s are discovered, turned on/off) and I’ll take a look.

Hello @Nicholas_Waterton ,

Log captured with one of the TV’s.
samsungtv.log (226.3 KB)

Tried multiple times to switch TV ON/OFF with remote and with binding but the thing did only go OFFLINE once and then never again.

Thank you for your time in looking into this.

Best regards

@rjduraocosta

Thanks for the log. i can see that UPNP is working, and the TV is discovered correctly.

Your TV is not responding to WOL requests (that’s why it won’t turn on). Have you enabled WOL on the TV? also do you have a soundbar connected to your TV? I ask, because I have found that some Samsung TV’s do not respond to WOL packets if they are wired to ethernet, and have a soundbar connected. They do respond to WOL if they are connected via WiFi (even with a soundbar connected). Just more Samsung weirdness. This all assumes you have enabled WOL on the TV of course.

I think the option is under network and is called “Allow power on by Mobile”.

Volume and Mute are working, but when you power off the TV, the MediaRenderer service does not disappear, which is why the TV does not go offline (I think it does disappear, but it doesn’t register via UPNP as having been removed). Hence the TV will not try to turn ON again, as it doesn’t know it’s Off.

So UPNP is behaving oddly on your OH system. I don’t know why. You could try unplugging your TV for 60 seconds, and plugging it back in (I know, but it has been known to sort out some unexplained weirdness in the past).

Also, you don’t need to keep adding and removing the binding (and accepting the connection on your TV) - just going into the Thing configuration and clicking on “save” will restart the binding, without having to redo the tokens or anything. If you do it with the TV on, it should connect to the TV right away.

Try that and watch the logs, you should see:

192.168.1.163: remoteDeviceAdded: MediaRenderer, http://192.168.1.163:9197/dmr, upnpUDN=39537c15-1ed2-4502-a67d-50342b328caa

When the TV turns on (This is what sets the TV Online and ON, and starts the websockets connecting).

You should see:

[DEBUG] [nternal.service.MediaRendererService] - 192.168.1.163: onStatusChanged: status=false
.
.
.
192.168.1.163: Device removed: udn=39537c15-1ed2-4502-a67d-50342b328caa

When the TV turns off (this is what’s missing) - this puts the TV offline and OFF, and shuts down the websockets etc.

I should mention, the first time you turn the TV off, the UPNP services do register as being removed correctly, it’s after the WOL failure and you turn on manually that they don’t register as being removed when you turn the TV off again (they do register being added when the TV turns ON.

Let me know what you find.