ollo69 / ha-samsungtv-smart

📺 Home Assistant SamsungTV Smart Component with simplified SmartThings API Support configurable from User Interface.
Apache License 2.0
433 stars 58 forks source link

Samsung G8 Monitor - DisplayPort as InputSource? #274

Open AfcaEric opened 11 months ago

AfcaEric commented 11 months ago

So i have this strange thing. I have a Samsung G8 Monitor. My PC is connected to the mini DisplayPort on the monitor. Now, from the SmartThings webpage, i'm able to call the "samsungvd.mediaInputSource" command with a value of "PC" and it switches to the DisplayPort source. Calling the same command ("samsungvd.mediaInputSource") with the value of "Display Port" (mind the space in between) it works as well.

From this integration in HA, i have 2 devices:

  1. The one from Samsung Smart TV. This one lists only 2 sources: TV and HDMI
  2. The one from SamsungTV Smart. This one only lists my HDMI device (HDMI1, PlayStation 5)

Is there any way i can get it working so i can switch from/to the DisplayPort input?

ollo69 commented 11 months ago

I suppose that Samsung Smart TV is the native integration. This one do not use SmartThings so it just display what is possible via WebSocket (TV/HDMI) SamsungTV Smart (this integration) use SmartThings if you configure token during setup, but I don't know what is samsungvd.mediaInputSource. If you can provide more detail (example and syntax of your call, may be with some screenshot) I could take a look to understand if this command can be implemented.

Anyway I strongly suggest to not have both integration configured, because for sure they interfere with each other.

kaixla commented 11 months ago

Hi @ollo69 I have a smart monitor too. M5 version in my case. I believe the issue is that we cannot link our SmartThings account to this. I have other Samsung regular TVs at home and are listed and can be selected when introducing the Smartthings API Key, but the monitor isn't listed. Therefore if we cannot add the Smartthings integration to the Smart Monitor to control the input source (apart from TV or HDMI).

ollo69 commented 11 months ago

Hi @kaixla,

clear, but seems that @AfcaEric can control his monitor from SmartThings:

Now, from the SmartThings webpage, i'm able to call the "samsungvd.mediaInputSource" command with a value of "PC" and it switches to the DisplayPort source

kaixla commented 11 months ago

Hi @ollo69 what a fast reply! Thanks.

Yes, I can control the monitor from the SmartThings app in my phone.

But unfortunately I cannot use the functionality in this module as I am unable to link it. I can use basic functionality such as on and off, or change from TV to HDMI. But not to select app source, or even HDMI1 or HDMI2.

ollo69 commented 11 months ago

To understand if is possible to do something, you should try to connect to SmartThings with your token using a software like postman and report here available commands and syntax. If some specific command is available to detect additional source and select them, I could try to implement inside integration.

kaixla commented 11 months ago

I would love to help, but I am not an IT expert, and have never worked with APIs. I have made a quick search of Postman and the Smartthings API, but unfortunately I understand very little of it. I have my API token that I could use to test, but I am unable to do what you ask for. If you would like to guide me I would be happy to help. Thanks!

AfcaEric commented 11 months ago

Hi ollo,

Thanks for helping out. I'll try to explain a bit further, but please bear with me since i'm pretty new to Smartthings. Ok, so the monitor is the Samsung G8 OLED. I've started using the Smartthings CLI to see what i would need and found the following (funny) thing:

With Smartthings CLI i find the following 2 capabilities of interest (omitted the rest that's not interesting in this one):

Capabilities:
────────────────────────────────────
 6   mediaInputSource
 20  samsungvd.mediaInputSource
────────────────────────────────────

For the default "mediaInputSource", it lists the following and you can see DisplayPort is missing:

─────────────────────────────
 1  setInputSource(mode<enum
      - AM
      - CD
      - FM
      - HDMI
      - HDMI1
      - HDMI2
      - HDMI3
      - HDMI4
      - HDMI5
      - HDMI6
      - digitalTv
      - USB
      - YouTube
      - aux
      - bluetooth
      - digital
      - melon
      - wifi>)
─────────────────────────────

For the samsungvd.mediaInputSource (which seems to use the same 'mediaInputSource' command but in a slight different way, it gives me the free option to input something:

Commands:
───────────────────────────────
 1  setInputSource(id<string>)
───────────────────────────────

? Enter command 1
? Enter command arguments (id) "PC"

If i enter "PC" or "Display Port" here, it works fine.

Unfortunately, i'm not a scripter/programmer, but if there somehow would be a way to use the setInputSource that's being used in your Smartthings.py script (COMMAND_SET_SOURCE variable) the same way it would be used through the samsungvd.mediaInputSource capability (which in turn looks to me as it uses the same setInputSource command but in a different syntax), i think we would have the complete freedom to create our own Source list.

Not sure if it would be helpful, but i think i'm able to dump the JSON or XML code that's being run with these commands. So if that could be helpful, please let me know.

I think it's safe to say that this is just deficiency from the Smartthings API, but the possibility is there. I hope this made any sense. If not, please feel free to tell me what i could help out with

ollo69 commented 11 months ago

Not sure if it would be helpful, but i think i'm able to dump the JSON or XML code that's being run with these commands. So if that could be helpful, please let me know.

Yes, it could help. Please attach it

AfcaEric commented 11 months ago

Sure, hopefully this is what you are looking for:

mediaInputSource:

{
    "id": "mediaInputSource",
    "version": 1,
    "status": "live",
    "name": "Media Input Source",
    "ephemeral": false,
    "attributes": {
        "supportedInputSources": {
            "schema": {
                "type": "object",
                "properties": {
                    "value": {
                        "items": {
                            "title": "MediaSource",
                            "enum": [
                                "AM",
                                "CD",
                                "FM",
                                "HDMI",
                                "HDMI1",
                                "HDMI2",
                                "HDMI3",
                                "HDMI4",
                                "HDMI5",
                                "HDMI6",
                                "digitalTv",
                                "USB",
                                "YouTube",
                                "aux",
                                "bluetooth",
                                "digital",
                                "melon",
                                "wifi"
                            ],
                            "type": "string"
                        },
                        "type": "array"
                    }
                },
                "additionalProperties": false,
                "required": [
                    "value"
                ]
            },
            "enumCommands": []
        },
        "inputSource": {
            "schema": {
                "type": "object",
                "properties": {
                    "value": {
                        "title": "MediaSource",
                        "enum": [
                            "AM",
                            "CD",
                            "FM",
                            "HDMI",
                            "HDMI1",
                            "HDMI2",
                            "HDMI3",
                            "HDMI4",
                            "HDMI5",
                            "HDMI6",
                            "digitalTv",
                            "USB",
                            "YouTube",
                            "aux",
                            "bluetooth",
                            "digital",
                            "melon",
                            "wifi"
                        ],
                        "type": "string"
                    }
                },
                "additionalProperties": false,
                "required": [
                    "value"
                ]
            },
            "setter": "setInputSource",
            "enumCommands": []
        }
    },
    "commands": {
        "setInputSource": {
            "name": "setInputSource",
            "arguments": [
                {
                    "name": "mode",
                    "optional": false,
                    "schema": {
                        "title": "MediaSource",
                        "enum": [
                            "AM",
                            "CD",
                            "FM",
                            "HDMI",
                            "HDMI1",
                            "HDMI2",
                            "HDMI3",
                            "HDMI4",
                            "HDMI5",
                            "HDMI6",
                            "digitalTv",
                            "USB",
                            "YouTube",
                            "aux",
                            "bluetooth",
                            "digital",
                            "melon",
                            "wifi"
                        ],
                        "type": "string"
                    }
                }
            ]
        }
    }
}

samsungvd.mediaInputSource:

{
    "id": "samsungvd.mediaInputSource",
    "version": 1,
    "status": "proposed",
    "name": "Media Input Source",
    "ephemeral": false,
    "attributes": {
        "supportedInputSourcesMap": {
            "schema": {
                "type": "object",
                "properties": {
                    "value": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "properties": {
                                "id": {
                                    "type": "string"
                                },
                                "name": {
                                    "type": "string"
                                }
                            }
                        },
                        "required": []
                    }
                },
                "additionalProperties": false,
                "required": []
            },
            "enumCommands": []
        },
        "inputSource": {
            "schema": {
                "type": "object",
                "properties": {
                    "value": {
                        "type": "string"
                    }
                },
                "additionalProperties": false,
                "required": [
                    "value"
                ]
            },
            "enumCommands": []
        }
    },
    "commands": {
        "setInputSource": {
            "name": "setInputSource",
            "arguments": [
                {
                    "name": "id",
                    "optional": false,
                    "schema": {
                        "type": "string"
                    }
                }
            ]
        }
    }
}
github-actions[bot] commented 9 months ago

This issue is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] commented 9 months ago

This issue was closed because it has been stalled for 7 days with no activity.

ollo69 commented 9 months ago

Reopen this adding FT label, I just do not have any time to take a look...

veeroohre commented 9 months ago

Would be great to get the ability to switch to DP. I'd like to do it, too. My use case is that I'm switching a lot between my PC and my work laptop. Using the remote is pain so I plan to use an Ikea switch to do just that. Unfortunately I cannot do it yet. As @AfcaEric wrote it's possible via the SmartThings website.

Maybe the attached screenshot from the SmartThings page is useful...

image

branislavbudzak commented 9 months ago

I have the same issue but with USB-C port on my Samsung M7 Smart Monitor, where I am connecting my Macbook. So it will be cool to be able to switch inputs. HDMI port where I have my Xbox is working, but USB-C is not for some reason and under attributes it is always showing HDMI1 even if I have USB-C opened.

germn commented 8 months ago

Some useful info for those who has OLED G8 and wants to use it with HA:

1) You can use SmartThings API to switch to Display Port:

curl -X POST 'https://api.smartthings.com/v1/devices/DEVICE_ID/commands' -H 'Authorization: Bearer API_TOKEN' --data '{"commands":[{"component":"main","capability":"samsungvd.mediaInputSource","command":"setInputSource","arguments":["PC"]}]}' Get and replace above DEVICE_ID from https://api.smartthings.com/v1/devices (you need an auth on smartthings.com) and API_TOKEN from https://account.smartthings.com/tokens

2) You can use standard HA Samsung Smart TV integration and provided remote service to switch to USB:

service: remote.send_command
target:
  device_id: ID_FOR_REMOTE
data:
  command:
    - KEY_HDMI  # It says HDMI, yes, but it actually switches to USB ¯\_(ツ)_/¯

I don't remember where I got ID_FOR_REMOTE from :(

Surprisingly, I didn't manage to switch to USB using API despite USB being a valid MediaSource for both mediaInputSource and samsungvd.mediaInputSource.


Anyway, it's enough to switch between Display Port / USB. The API call can be wrapped with https://www.home-assistant.io/integrations/rest_command/

My results:

secrets.yaml

display_uid: jhjghjghjghjghjghjghjghjghj
display_api_url: https://api.smartthings.com/v1/devices/ghjghjhgjhgjhgjghjghj/commands
display_api_auth: "Bearer ghjhgjhgjghjhgjghjghj"

configuration.yaml

rest_command:
  34_odyssey_oled_g8_api:
    url: !secret display_api_url
    method: POST
    headers:
      authorization: !secret display_api_auth
    payload: '{"commands":[{"component":"main","capability":"{{capability}}","command":"{{command}}","arguments":["{{arguments}}"]}]}'
    content_type: "application/json; charset=utf-8"
    verify_ssl: false

scripts I use

  display_to_desktop:
    sequence:
      - service: rest_command.34_odyssey_oled_g8_api
        data:
          capability: "samsungvd.mediaInputSource"
          command: "setInputSource"
          arguments: "PC"
      - service: script.display_remove_popup

  display_to_macbook:
    sequence:
      - service: remote.send_command
        target:
          device_id: !secret display_uid
        data:
          command:
            - KEY_HDMI
      - service: script.display_remove_popup

  display_remove_popup:
    sequence:
      - delay:
          milliseconds: 500
      - service: remote.send_command
        target:
          device_id: !secret display_uid
        data:
          command:
            - KEY_RETURN
ollo69 commented 8 months ago

Based on information collected in this thread I released a new version that support the key code "ST_PC" via SmartThings. Please check a let me know if it works as expected.

veeroohre commented 8 months ago

Switch to Display Port does not work for me with "ST_PC". It switches to HDMI1.

Using curl -X POST 'https://api.smartthings.com/v1/devices/DEVICE-ID/commands' -H 'Authorization: Bearer API-Token' --data '{"commands":[{"component":"main","capability":"samsungvd.mediaInputSource","command":"setInputSource","arguments":["Spiele-PC"]}]}' works.

ollo69 commented 8 months ago

Why Spiele-PC. This is the name that you assign to the input? Can you just rename it PC and try again from integration?

veeroohre commented 8 months ago

Yes, I renamed it.

After renaming to "PC" it still switches to HDMI1 and not DisplayPort.

ollo69 commented 8 months ago

But after renaming did you try to change the input using curl command?

ollo69 commented 8 months ago

Anyway I released a new version where I rewrite this command to be more generic. You can now use, for instance, ST_VD:Spiele-PC to activate the input Spiele-PC. In this way this is more generic a is possible to use any input name (of course it must exist on the TV).

Tested my side and it work properly, I wait for yours feed-back.

veeroohre commented 8 months ago

I works now, but only if I rename the source to e. g. "Spiele-PC". If it's the default name "PC" it still switches to HDMI1 and not DisplayPort.

Thank you for your help!

rusty6285 commented 7 months ago

Thanks folks, I wasnt unable to figure out how to send this via API command, but I can confirm that using a script that sends the command 'ST_VD:PCdp' as a 'Remote: Send Command' to the entity works perfectly! just be sure to rename the displayport input to that first.

I'm hoping the renamed input sticks on this new firmware, I had an issue of it always reverting last time I did this.. fingers crossed

simonysck commented 6 months ago

@branislavbudzak, @germn

I figured out how to switch to USB-C directly on Samsung Odyssey G8 without using 'KEY_HDMI' which actually switches between inputs. The trick is to send the command 'ST_VD:name of your USB-C' It seems like ST_VD recognized the name you give the inputs instead of the nature of the input. To change the name , go to Home > Connected Devices (should be on the left) > Sources (and pick the USB-C, then press down) >Edit and type what you want it to call in the Edit Name textbox. In my case, I called it ' Laptop'.

Then in the source list configuration , I wrote USB-C: ST_VD:Laptop and it switches to USB-C everytime. If I am already on USB-C, the monitor shows that you are on USB-C again on the top

ahass-thedev commented 1 month ago

This is what I was able to get to work in home assistant:

rest_command: set_samsung_input_source: url: 'https://api.smartthings.com/v1/devices/{{ device_id }}/commands' method: POST headers: Authorization: 'Bearer YOUR_ACCESS_TOKEN' Content-Type: 'application/json' payload: > { "commands": [ { "component": "main", "capability": "samsungvd.mediaInputSource", "command": "setInputSource", "arguments": [ "Display Port" ] } ] } content_type: 'application/json'

You can use

curl -X GET https://api.smartthings.com/v1/devices/{deviceId}/components/main/capabilities/samsungvd.mediaInputSource/status \ -H "Authorization: Bearer {accessToken}"

to get the supportedInputSourcesMap for your device and then use the id value to set the arguments in the call

ismakov-dh commented 1 week ago

Turns out that samsung uses some weird name for USB-C input by default. I realised that after many hours spent sniffing and digging Smart Things requests. Also in my case the tv resets the USB-C input source name to the default value after power off. So if anyone has problem switching to the USB-C port, try logging into the Smart Things web UI with browser developer tools opened. Find WebSocket connection in network tab of developer tools and expand api/cloud/status event. It will have an array of attributes describing active input source. Here you will find the name that you should use as setInputSource command argument.

Screenshot 2024-09-07 at 05 15 40

Perhaps this is also applicable to the Display Port input source

Sheugel commented 4 days ago

Hi, Can you elaborate how you got the name to be used to trigger the USB-C source? I don't see these attributes in Chrome developer tools. Thanks

ismakov-dh commented 4 days ago

Hi, Can you elaborate how you got the name to be used to trigger the USB-C source? I don't see these attributes in Chrome developer tools. Thanks

Hi👋 Open dev tools and navigate to the smart things website, do all steps (logging in, etc.) until you see the page with the list of your devices with power switch buttons. Then in the network tab of dev tools choose WebSocket connections filter, there you should see single connection. Fall into it to see messages and search for large incoming message, there will be the name

You also can open smart things first, then dev tools and refresh the page

Sheugel commented 3 days ago

Thanks, I got it working!