Samsung TV Binding (Beta)

@DocMC

Thanks!. You can send me a beer at Paypal

You do this in one of two ways. You can send the HDMI setting to the TVSamsung6Series75SourceName item, or send the source id (number) to the TVSamsung6Series75SourceId item (as you have figured out). The trick is knowing what to send. Each TV has it’s own way of naming the inputs and assigning id’s. The way to figure out what they are is to display the names when you manually change the inputs (I notice you don’t display the values in your sitemap).

So use this:

Switch item=TVSamsung6Series75SourceName label="Source Name [%s]" mappings=["digitalTv"="digitalTv", "TV"="TV", "AVR-X4500H"="HDMI1", "Synology"="HDMI2", "Denon"="HDMI3"]
Setpoint item=TVSamsung6Series75SourceId label="Source ID [%s]"

When you switch inputs (using your remote), the name/id of that input will be displayed in the openHAB UI - this is the name/id that you have to send to select that input.

For example, this is what I use on my older (N series) TV:

Switch item=TVUN46EH5300_SourceName label="Old TV Input Name [%s]" mappings=["TV"="TV", "HDMI1/DVI"="HDMI 1", "HDMI2"="HDMI 2", "HDMI3"="HDMI 3", "HDMI4"="HDMI 4"]
Switch item=TVUN46EH5300_SourceID label="Old TV Input ID [%s]" mappings=[0="TV", 67="HDMI 1", 68="HDMI 2", 69="HDMI 3", 70="HDMI 4", 80="Browser"]

As my TV uses HDMI1/DVI for HDMI1 and the source ID’s are as shown (this may be different for your TV).

You are right, sending "" should exit the current running app. It is slightly more complicated that that, though as different TV’s start/stop apps in different ways (of course). You can also use the stopBrowser channel to try and exit an app. If you send ON to stopBrowser it sends "" to the app, and sending OFF to stopBrowser sends a long press of EXIT to the app. Try these, see if they work better.

It may be a bug of course.

If you could send me a TRACE log of you starting an app, then sending "" to try and exit the app I might be able to figure out why it’s not exiting.

What should happen is that you send the command to the sourceApp channel with the app name, and when the app is launched, the sourceApp channel receives an update with the current app name (which should be the same as the app name you sent to launch the app). You can trigger a rule off received update of the sourceApp channel item (ie TVSamsung6Series75SourceApp) to send the OK key press, as the update happens when the app has been loaded.

If you send me the log I mentioned above, I’ll take a look - my TV doesn’t notify apps at all (Samsung removed the API in 2020), so it’s hard to test. As you say, you can just program a 5s delay (but that 5s seems to be forever when you are waiting). There is a built in 3 second delay before the sourceApp channel update happens (as most apps seem to take about 3 seconds to launch). I might consider taking the 3s delay out if the API is available - might make things more responsive. Let me know how long it is after the app is launched before you receive the received update trigger.

Thanks again for the help, the more people who can test the binding, the better it will get.

UPDATE:
I have done some testing, and this works.
First, you have to define your Item TVSamsung6Series75SourceApp as autoupdate="false".
ie

String  TVSamsung6Series75SourceApp  "Source App [%s]"   <television>   { channel="samsungtv:tv:family_room:sourceApp", autoupdate="false" }

(using your TV thing name)

Then you can define some rules. These are test rules:

rule "TV App launched"
when
    Item TVSamsung6Series75SourceApp  received command
then
    logInfo("TV_App", "received command: " + receivedCommand)
end

rule "TV App started"
when
    Item TVSamsung6Series75SourceApp  received update
then
    logInfo("TV_App", "received update: " + newState)
    if (newState == "Amazon Prime" ) {
        sendCommand(keyCodeItem, "KEY_ENTER")
    }
end

You have to substitute your keyCode item for keyCodeItem and whatever key you need to send.

I don’t use the OH rules engine, but this seems to work.

NOTE: you may have an issue if you switch between running apps, as when you switch to Amazon Prime (as opposed to launching Amazon Prime), it will send the ENTER key again. This will also happen if you launch the app via the remote control.