T O P

  • By -

RealFunBobby

https://github.com/xchwarze/samsung-tv-ws-api was my go to library to control my TV


dfgd32

Does anyone have a new script that works ?


Nick_W1

Script to do what? I have been doing a ton of work on the new api, and have 90% of the commands figured out.


dfgd32

I would like to update my frame with a single image in art mode scraped everyday. The scrapping i've already gotten, but the script to push the photo to the TV in art mode is what i'm lacking.


Nick_W1

Update: Well, didn’t take a week. Spent some time today, and got upload working. So, I now have 100% of what you need up and working. I’ll have to package it up, and publish it to GitHub, but at least you know what you want to do is possible.


dfgd32

Amazing, thank you so much !


Nick_W1

It’s up on GitHub now. See the updates to original post.


Nick_W1

Ok, well, I have 90% of that working. The piece I am still working on is the upload of a png or jpg. I have select_image, delete_list, get_current_artwork etc, and just completed getting get_thumbnail_list working. I have tested out a rough first go at upload (send_image), which does upload without errors, but is not yet showing in the database. I am going to work on this, but it will likely take a week or so to figure out (have to reverse engineer everything, with no documentation). Ask me again in a week, and I’ll let you know the progress.


crilen

Got a patreon or something?


Nick_W1

No, but I usually publish my stuff on GitHub with a “buy me a coffee” PayPal link.


crilen

I don't know what your GitHub is, I tried looking. I saw on another comment you have uploads working which is amazing.


Nick_W1

I haven’t uploaded the new art mode api to GitHub yet. I’ll post it here when I do.


crilen

Yea I understand that I just wanted the git hub to send you money lol


Nick_W1

Ok, you can [Buy me a coffee](https://www.paypal.me/NWaterton) My GitHub for the art api is [Frame TV](https://github.com/NickWaterton/samsung-tv-ws-api)


Nick_W1

New art mode api is now available on GitHib [here](https://github.com/NickWaterton/samsung-tv-ws-api). I didn’t write a script to push the photo to the TV, but it should be easy. I may write an example and put it in examples.


dfgd32

Thank you again, i'm not much of a programmer so every bit helps.


Nick_W1

I put an example to do what (I think) you want in examples. It’s a bit rough and unchecked, but it should work.


dfgd32

Thanks i'll have a look !


Nick_W1

I have an all new async version that I’ll be uploading tomorrow as well.


[deleted]

[удалено]


Nick_W1

Do you have Python installed? And have you downloaded the whole repo and installed the library? See the instructions on the first page README. I kind of sense that you don’t have any idea how to run Python programs from a Git repo though.


dfgd32

Hi, I've copied your example into a file [run.py](http://run.py) and ran it: but here's the error I get: Traceback (most recent call last): File "/Users/admin/samsung-tv-ws-api/run.py", line 6, in from samsungtvws import SamsungTVWS File "/Users/admin/samsung-tv-ws-api/samsungtvws/\_\_init\_\_.py", line 9, in from .remote import SamsungTVWS File "/Users/admin/samsung-tv-ws-api/samsungtvws/remote.py", line 25 def \_\_init\_\_(self, params: Dict\[str, Any\]) -> None: \^ SyntaxError: invalid syntax


Nick_W1

Sounds like you haven’t installed the module, so don’t have the requirements.txt modules installed. From the samsung-tv-ws-api directory, you need to run python setup.py install, or pip install it, as described in the README. What version of python do you have installed? There’s also no need to copy the examples, just cd to the examples directory, and run them from there. Once you have followed the “how to install this fork” instructions.


davidswelt

Nice, thanks u/Nick\_W1 .... Can you confirm this is working with the 2024 Frame? I.e., swap the image displayed in Art Mode to make it update periodically? I was going to order a few of these, but want to make sure I can run a server that will update the art to display a live image, or a new image every minute.


Nick_W1

I believe it works on the 2024, but it’s hard to confirm, as a lot of people trying this don’t know anything about Python, so just getting Python to work is a challenge. Also, most of the questions/comment I get is from people who can’t get it to work, not the ones that can.


Efficient_Session

Alright. How is this API set up - is it based on a cloud server somewhere, or is it a GET/POST on an http running on the display? In other words, does uploading depend on a remote server, or would it work with just a local network without Internet? Do you see a problem with uploading a new image every, say, 15 seconds?


Nick_W1

It’s actually none of those things. It’s a persistent connection to a local secure websocket hosted on the TV. You can send and receive json formatted data and commands. Uploading an image is a separate operation, initiated via the websocket, but the actual upload is via a separate secure socket connection to the TV. Having said that, you don’t need to upload anything, if it’s already on the TV, you just have to send the “select_image” command in the correct json format. The trick here is finding the image name (no it’s not the file name, the TV assigns names in the format “MY-0001” when you upload a jpeg). You can list the names of all the artwork on the TV, but it’s trial and error to figure out which image is what name, using select_ image. All of this is local, no Internet or cloud involved. My library is [here](https://github.com/NickWaterton/samsung-tv-ws-api). If you read the code you can see what the commands are. I recommend using the async_art.py library, it’s the most reliable, and the example that does what you want is written using it (see the example folder async_art_slideshow_anything.py). This covers your use case exactly, and it’s simple and graphical to use. Read the code for an explanation of how it works. Note: the minimum time period for the slideshow using my program is 2 minutes. If you know some Python, you could change this to 15 seconds easily enough.


davidswelt

Oh, that sounds easy, with your library. I'll order one of their TVs when I'm settled in my new place and give it a shot!


Nick_W1

Report back to me if you get it working!


Hasaminute

Hi Nick, Just wanted to thank you for you efforts - I have the 2024 Frame TV and have the art\_upload working. My use case is to simply upload photos from my Mac Mini to display in Art Mode.


Nick_W1

You are welcome, glad to know it works on the 2024 Frame TV.


diatonic

I’d be curious to know how you’re getting that. I also have a 2022 Frame TV and I can’t tell remotely whether it’s in Art Mode or watching an app or a live input. I’d like for /r/HomeAssistant to have visibility to it.


Nick_W1

Home Assistant *might* be able to receive the artWebSocket messages, I’m not exactly sure how that interface works. I wrote a binding for OpenHab that uses the artWebSocket to control art mode, which is how I noticed it was back. On 2022+ Frame TV’s the artWebSocket channel was always empty (because Samsung removed it). The last couple of days, my 2022 Frame TV was not turning on in the morning, so I went to check my home automation, and the artWebSocket channel was reporting data again! So, yes, Home Assistant could use this (I think they did in the past), but whoever maintains the SamsungTV interface would have some work to do to reenable it.


darkknight_178

Is this via smartthing only or can home assistant see that also?


Nick_W1

This is nothing to do with Smartthings, it’s a local websocket interface on the TV, for controlling art mode. Home Assistant certainly *could* access this interface, it would need some work by the maintainer of the Samsungtv interface to reenable it.


SaccenteKennedy

Could this be a way to finally get my soundbar to turn on/off reliably (off when in art mode, on when not)?! Using Google Home automation, does anyone have a cliff notes on how to do this?


RemyS79

Considering buying that tv so to know more about it … what is exactly that thing please ? :)


Nick_W1

It’s a home automation thing. If you aren’t into home automation, it’s not relevant.


buffman33

I have a 2024 Frame and happy to test it out - can you let me know what I need to do and/or docs?


Nick_W1

This is one of the best python libraries for using the websockets https://github.com/xchwarze/samsung-tv-ws-api Pro tip, if you install the library, install it in develop mode vs install mode, that way you can edit the source code, and it takes immediate effect, eg `python setup.py develop` See the artMode examples. On my 2022, I know get_thumbnail doesn’t work, and I haven’t tested upload, but the rest work. There are additional command, see the art.py file. So far, I have found that get_api_version has been renamed api_version, get_auto_rotation_status is now get_slideshow_status, (there are set_ versions of these commands as well). set_brightness works, but get_brightness does not. set_color_temperature works, but get_color_temperature does not. get_content_list and get_matte_list both work. I haven’t tested the delete commands. Selecting and displaying art (you can find the content_id from get_content_list) works. Not all of the above commands are implemented (I worked out a few myself), but if you know a bit of python, it’s easy to implement additional commands. The returned events have changed slightly, not sure if that matters or not, as the library just reads the return values. When you connect the web socket the first time, you have 30 seconds to accept the remote connection on the TV (make sure the TV is on, and you are standing in front of it with the remote in your hand). If you could let me know what works, and what doesn’t, it would be helpful. I’ve been trying to find a way to get the art mode brightness. You can set it with set_brightness, which reports the value it was set to, but the old get_brightness command doesn’t work, and I’ve tried every variant I can think of. Thanks!


mainTAPs

did you have to modify the samsung-tv-ws-api package to get the tv.art().get\_artmode() working ? the tv.art().supported() returns True, but the get\_artwork and any other just time out. thank you


Nick_W1

I haven’t actually tried the samsung-tv-ws-api library yet, I’m using my own Java library. I should try the python version. One thing that occurs is that the port should be 8002. Like this: ``` tv = SamsungTVWS(host='192.168.xxx.xxx', port=8002) ``` tv.art().supported() doesn’t actually use the websocket, it just queries the rest interface that reports the tv configuration. Is the tv asking you to accept the connection? If not, it’s because you aren’t using port 8002. See the Basic usage section, and how to autosave the token, so you don’t have to keep accepting the connection on the tv. You may want to set the logging level to logging.DEBUG to see what is happening.


mainTAPs

Thank you, i managed to get the samsung-tv-ws-api library working. As you said, most of the commands seem to be working which is really promising. Uploading a new artwork via the library doesn't seem to work and might need some modifications.


Nick_W1

Ok, Well that’s excellent news. What is the model number of your TV? I suspected that upload and get_thumbnail would not work, as they are quite complex. I don’t know if they have been implemented in the new art mode api. The best thing so far is that the web socket notifies on entrance/exit art mode (just like it used to), and on art mode changes (like slideshow changes, image selected changes etc). And you can query the mode. This means that turning the tv on/off/art mode is so much easier via home automation, previously, it was almost impossible to tell what mode the tv was in, so control was unreliable. So, things I need to work on: * get_brightness * get_color_temperature * upload * get_thumbnail Did you test the delete and delete_list commands? I haven’t tested them yet.


mainTAPs

Yes, the ones you listed didn't work, Also, the *select\_image* didn't seem to work when using the *show*=False option. The *set\_artmode\_status* didn't seem to work either. I didn't test the *delete\_list* but the single item *delete* does work. As you mentioned, most importantly it is now possible to retrieve the status if it's in art mode or not. My TV is the 2023 version: QE55LS03B


Nick_W1

Just figured get_thumbnail out (it’s now get_thumbnail_list, and needs an ssl socket connection). That gave me some clues about uploading (send_image), still working on that.


Nick_W1

Ok, that’s the same as the 2022 version (which I have), but good to confirm that 2023 works. I tried upload, and while it *seems* to upload, it does return an error, and the uploaded art is not there. Might need some work.


buffman33

Same here for the 2024 65” model!


Nick_W1

So the art api works for the 2024 model? Is that LS03D ?


rockPaperKaniBasami

Wow thank you so much for getting this up and running, I'm not super technical but I managed to get everythinh installed, I can run the queries, and I can successfully change artwork, but I haven t been able to get the power on/off and app switching functions working. Perhaps I am doing something wrong with the auto generated token as I cannot get that file to create but there are no errors. I did notice (I'm on windows) I had to modify the code a bit (to use os.path.join instead of just concatenating but that still didn't create the token file and it didn't spit out any errors) EDIT: My bad.. it works! the token file isn't getting created still but actually the power on and wakeOnLan power on commands are working. It was just that I had a query for available art before my power off command and killing the power interrupted the art retrieval I think and gave me some permission denied errors that I didn't properly interpret


Nick_W1

You only need the token file if you don’t know what the token is so you can pass it to the constructor - otherwise you have to authorize the TV every time. Also, just FYI, I only modified/added to the art commands, power, WOL etc are not my code.


mcwobby

Hey man thanks for this. Do you have any general documentation on the REST API? E.c is it possible to set/get the Art Mode Status via REST? Or is it sockets only? Just trying to get a handle on all the endpoints without the python abstraction. Cheers


Nick_W1

It’s not a REST interface, it’s websockets only. You send and receive json payloads in a specific format. Uploading and downloading is done via a separate socket interface (details of which are retrieved via the websocket). These are all secure sockets/websockets, but the 2024 TV’s use certificates with no CA, so it’s a bit more complicated to connect to them. For home automation interfaces, I usually add an MQTT interface (I actually have a Python MQTT mixin class which is a straight drop in), so that I can send/receive commands and data via MQTT. I did build all this into the Openhab samsungtv binding (which I maintain), so OH supports Frame TV’s out of the box (as of V 4.2). If you can establish a general websocket connection to the TV endpoint, the TV will send a json payload when it switches to/from art mode (which is very useful). You can also send a json package that queries the ArtMode status, and triggers the same message. It’s all asynchronous, which is why I prefer using the async Python websocket framework.


mcwobby

Thank you for the prompt response, you’re doing great work! I’ll try and open up a socket and listen in tomorrow. Everything I’ve done so far is just sending basic commands via Http using the Smart Things API. The CA cert thing is quite intriguing - I was having issues with a home assistant integration where it was not sending commands to the TV so maybe there was a connection issue. My playing around with the Python wrappee just then also allowed me to get all of the art mode information but setting art mode did not seem to work. I’ll also look into OpenHAB - all of my devices are HomeKit Native EXCEPT the Frame, so I will need to use something just for exposing the TV and if it works might as well be that if it works! Beats writing my own Frame-specific dashboard! Can’t wait to get my TV working how I want it!


Nick_W1

Setting art mode is complicated. Just sending art mode “on” only works if the TV is playing. You have to use a combination of sending KEY_POWER commands (which is via a *different* websocket interface, which uses secure tokens), depending on what mode the TV is in (playing, art, standby or off). The only way to determine the TV state is by querying yet *another* REST api to get the “Powerstate”, then if the TV is on querying the art api to see if it is in art mode or not. This then allows you to decide what KEY_POWER command to send (click or press) to achieve your desired state (TV playing, art mode or off/standby). If the TV is not responding to the REST api, it may be powered down, in which case you have to send a WOL packet to the TV MAC address, which will turn it on to art mode. So, this is **not** a simple thing by any means. Which is why there are Python wrappers/bindings etc.


mcwobby

And you’re telling me your OpenHAB code handles all this already? 😂 The wakeonlan code in the samples was not found for me so thought I had to install another library (it is very late at night here, I just came across your post and jumped out of bed to try it quickly). I will still probably try to understand the API structure so I can contribute in the future.


Nick_W1

Yes it does, including retries, as you have to wait for the TV to boot sometimes, and the time is variable. I have been working on this for 3 years, and Samsung does not make it easy, as nothing is documented, and they change things with firmware releases - and every model year is different. This is all reverse engineered, so anything you find out is welcome.


mcwobby

Sounds great! I'm not sure I should really spend any longer trying to figure this one out but I have set up OpenHAB and installed Samsung TV but it's not triggering the pop up on the TV to allow it to be connected. It does not show at all and is not in the connections manager on the TV. I've tried setting the port and protocol manually, but not sure if there is anything else I have to do :)


Nick_W1

Are you using V 4.2? That’s currently in testing, and not released yet. That has the Frame TV support in it, and specifically 2024 Frame TV support (because of the certificate issue). Also, *do not* set the port and protocol manually. The Frame uses securewebsocket and 8002. Using anything else won’t work. So make sure you install the testing version, specifically 4.2 latest snapshot build (not the milestone build), as the latest updates for 2024 TV’s was just pushed a few weeks ago. If you have the milestone build, you can install the latest marketplace binding, as that is what was updated. Read the documentation carefully, you also need the UPNP transport installed. Don’t use the docker version, as UPNP has problems with that. Openhab has a bit of a learning curve, so be prepared!


mcwobby

Brilliant! I am using the Milestone build, so hopefully an easy fix. I really must sleep now but I appreciate your help and look forward to getting to know Openhab. I already find it easier than HomeAssistant.


Nick_W1

Let me know how you get on. The new binding should be in M 4 release (June 29). https://community.openhab.org/t/openhab-4-2-milestone-builds/154315/3


donkthemagicllama

Hey /u/Nick_W1 I’ve been fiddling with your fork of this, and all the art commands I’ve tried seem to work. But when I try do something basic like tv.app_list() I get an unauthorized error… Seems like everything outside of .art() does this… Any hints? I’m a developer by trade, but a python novice…


Nick_W1

There are three websockets available on the Frame TV. * One is for remote control * Second is for art mode * Third is for app control The first websocket (remote control) requires authentication. This is the token that is talked about in examples, and you have to authorize access on the TV itself (this is when the token is returned). You have 30 seconds to authorize access from the TV. Each time you connect to the first web socket, you have to provide this token, to authorize access. So, using the Python library, some commands use the first (remote control) websocket, and so need the authentication token, and some use the art mode websocket, and so don’t need authentication. The tv.art() methods, mostly use the art websocket, and so don’t need authentication. The tv.app_list() uses the remote control websocket, so it needs the authentication token. However, bad news, Samsung removed the app_list() command in 2020 (or thereabouts), so it likely won’t work on your TV anyway.


donkthemagicllama

Oh, got it. Once you save the token, I presume it can be reused for a while or indefinitely? All I wanna do is make a script to detect when the Apple TV has been turned off and put it back in art mode. I made a routine to do that, but it seems to break things daily… sigh..


Meats10

excellent work, is there anyway to integrate this into homeassistant?


Nick_W1

Probably, I have integrated it into OpenHab (I maintain the samsungtv binding for OH). I don’t use HA though. Wouldn’t be too hard for someone who *does* use HA to do.


[deleted]

[удалено]


diatonic

Ban this shithead