setInputSource syntax for SamsungTV?

Hello all!

I’m been struggling for the last 2 hours with the syntax of the setInputSource for a Samsung TV

This are the options
setInputSource(mode<enum {AM, CD, FM, HDMI, HDMI1, HDMI2, HDMI3, HDMI4, HDMI5, HDMI6, digitalTv, USB, YouTube, aux, bluetooth, digital, melon, wifi}>)

Tried with setInputSource(HDMI1) … setInputSource(“HDMI1”) etc… but nothing, always returning “the request is malformed” or setInputSource not a valid value…

I’ve tried a lot a loooot of combinations but none works, im really missing how the syntax works… and I can’t find nothing on Google…

Any help on this?

Hi, @Niiky. How are you doing?
From where are you sending this command?
I created a virtual device that uses the mediaInputSource capability, and I can send the command through Postman as follows:

[POST] https://api.smartthings.com/v1/devices/deviceID/commands
{
    "commands": [
        {
            "component": "main",
            "capability": "mediaInputSource",
            "command": "setInputSource",
            "arguments": ["AM"]
        }
    ]
}

Hi, @nayelyz thank you for your response.

I was trying to send that command though smartthings cli : GitHub - SmartThingsCommunity/smartthings-cli: Command Line Interface (CLI) for the SmartThings APIs. Provides CRUD operations for platform artifacts as well as ability to control devices.

But still I had to figure out how to send the command through a google home device, I may try Postman, I will be able to send commands from there to the TV? How it connects?

Thank you very much

This is how I send the command:

smartthings devices:commands deviceID "main:mediaInputSource:setInputSource(\"HDMI\")"

The CLI expects a String value of the command and the ENUM type is also String, that’s why I placed those symbols. I hope it helps :smiley:

1 Like

Wow!!! It works!! Thank you so much!! I

But how did you know how to send it? I was really lost on this, tried a lot of combinations and none worked, using this setInputSource(1) returned error that string was expected then I tried (HDMI) and (“HDMI”) but didnt work either.
Whats the logic on the slashing the quotes?

Thanks again @nayelyz

Anytime, @Niiky! Well, based on this parsing method from the CLI I saw that the values were separated correctly.

So my guess was (because it has happened to me before) that the terminal wasn’t sending the values as expected (Strings) that’s why I wrapped the command with the quotes. As the argument also needs them, you need to escape (\) the character to include it in the String and it won’t be considered as a closure symbol anymore.

1 Like

Thank you again for the explanation!
kind regards

1 Like

Hi @navelyz,
I tried sending the setInputSource command as you explained in the previous post. But I always get an error response. Has the API been changed and I need to adjust something in the request?

HTTP/1.1 409 Conflict 

{
  "requestId": "...",
  "error": {
    "code": "ConflictError",
    "message": "invalid device state",
    "details": []
  }
}

I think you should get the device status and see if it has limited the options you can use.
The capability mediaInputSource has an attribute called supportedInputSources which defines the options accepted by the device and the response of the request seems to point out that’s the reason of the command rejection.

To get the status, you need to make a GET to https://api.smartthings.com/v1/devices/deviceId/status

Thanks for your fast reply. I tried getting the status which returned the values I would expect (e.g. “HDMI1”).

The setInputSource call did work for me until a few weeks ago. Since then I only get responses as described before. I don’t know if it has something to do with the problem but my TV is shown as offline in the SmartThings App. But it is turned on and some commands seem to work. Only the setInputSource fails…

Problem solved itself by simply re-adding the device to my account. Now all commands work as described.

1 Like