core: [0.81.0] Samsung TV not working
Home Assistant release with the issue: 0.81.0b2
Last working Home Assistant release (if known): 0.80.3
Operating environment (Hass.io/Docker/Windows/etc.):
- Hass.io on a Raspberry Pi 3 Model B (32gb SD)
- Hass.io supervisor 138
- HassOS 1.11
Component/platform: samsungtv
Description of problem: Media player not working under 0.81.0b2. It shows off although the TV is on. Reverted back to 0.80.3 and everything started working again. No specific errors in the log.
Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):
media_player:
- platform: samsungtv
host: 192.168.86.67
name: '[TV] Bedroom'
mac: [REDACTED]
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 7
- Comments: 223 (56 by maintainers)
I just wanted to let everyone know I have been working diligently on getting the samsungctl library finished up. I am ironing out some more kinks. Just did a massive addition to the library.
activating voice recognition mouse control text input H and J (2016 and 2015) encrypted TV command support powering on an off 2014+ models power status volume direct input getting the volume mute direct input getting the mute brightness direct input getting the brightness contrast direct input getting the contrast sharpness direct input getting the sharpness aspect ratio getting the aspect ratio tuner channel direct input (<= 2015) getting the tuner channel (<= 2015) getting active source, changing the source OSD (<= 2015) full application support. including but not limited to. listing all installed applications, starting an app, listing app content, application id’s, names, title, metadata, icons, content groups. content, content icons, playing content… and more. and a whole slew of other features.
TV discovery that will locate any TV’s on the network and properly set up all of the configuration information needed to connect to them.
Supports multiple TV’s
Easier loading and saving of config data (allows you to bypass discovery) by use of a Config class. (still backwards compatible with the dictionaries. config files are saved as a flat file and not json data, the files allow for comment lines
Automatic mac address discovery (Linux, Windows, OSX) to send the WOL packets
Removal of the exceptions if you connect and the TV is powered off. so reduced code on the Home Assistant side of things.
Automatic turning on of the TV if you are pairing to the TV. and the TV will return to the state it was at before pairing started once the pairing process is complete. (2014 +)
A really big thing that I think the people that work on home assistant will appreciate. You are not going to have to work very hard to write the code for the GUI. There are so many variations in supported features across the models and years… I threw you guys a bone. one simple property will dump the entire command structure for the TV as a dictionary. in the dictionary will be
function name the function object
for the parameters and the returned values param/value name data type (the actual python data type object, int, float, str, bool…) choices (if any) minimum (if any) maximum (if any) increment/step (if any) default value (if any) This should make it really simple for the GUI controls to be created dynamically.
You can also set up some kind of polling to get events for various things changing on the TV(s)
I also expanded the available key codes. there are now 243. including discrete codes for each source. and they are all nicely organized with descriptions for most of them and another bonus… the keys are grouped together by function with a group name. an example of some of the group names Input Channel Volume Navigation Media Aspect Ratio Picture Mode
If you know how to write python code and you are willing to help. please by all means. I wouldn’t mind the help.
Hi @arsaboo to be honest I fiddled around with the settings a lot till I got it working! So the best I can do is to share with you what I have and you can use it. I also had to change
if config["timeout"] == xtoif config["timeout"] == 5inremote_websocket.pyExtract these 2 folders to yourcustom_componentsfolder via WinSCP https://mega.nz/#!Np01iAgT!DCl9pvl7sZ1odxrsh68R7Dcd2UN9uxScVXBuCNBdyJ8Include this in your
configuration.yamlNow have your TV ON when you restart HA and the TV should ask you to Allow
HomeAssistant. Press Allow. If it doesn’t ask, try to press any button on HA’s frontend to control the TVYou’ll know if it’s working by looking at the
token.txtinsidesamsungctlfolder. There will be an 8 digit token number in there.This working for my NU8000 (2018) model on latest FW Though it’s not showing HA if it is playing anything or it’s idle which is my next problem
Hope you get this working my friend
Hi, I can check status of my tv, but i am not authorized to any changes (volume change, power off). I recived below info: Failed to call service media_player/volume_mute. {‘event’: ‘ms.channel.unauthorized’}
Regards Łukasz
OK so i had a go at altering the addon script for Home Assistant. while I am pretty confident it will work… there are several issues. These issues specifically have to do with the core of Home Assistant. It would be far easier for someone else to make the modifications then I. The largest problem is there are no concessions in Home Assistant for TV’s. there is kind of a band-aide approach of the media_player.MediaPlayerDevice component. This works. but severely handicaps the amount of control that can be offered.
There is no way to implement any kind of a GUI interface for the addition and removal of TV’s it has to be done hard coded. which is not so much of a problem…
here is a link to a very rudimentary way to get samsungctl working in Home Assistant. please be sure to read all of the directions. the specific parts on the script are at the bottom. please post any problems in the issue thread the link is for and not here.
https://github.com/kdschlosser/samsungctl/issues/36
I do believe that at this point in time there really needs to be a dedicated component class for TV’s, having TV’s included in a home automation is not an uncommon occurrence. in all reality it is probably the central component of most peoples setups.
This is going to be a pretty large change to Home Assistant. to add this component. I have written python API’s for a number of major TV manufactures. Samsung TV’s is not the first and nor will it be the last I am sure. I have a pretty decent handle on what should be available in the component class for TV’s
this is just a preliminary list.
This is going to outline some of the basic things that are needed to implement a TV component it also allows for use of custom created methods. This whole thing is a suggestion and not necessarily how it should be done. It does give a good outline of what would be needed. to cover the majority of a TV’s functions and features.
TV
Properties
Methods
open_browser(url) start_voice_recognition() stop_voice_recognition() send_remote_button(button) custom(*args, **kwargs)*
* an instance of the Custom class
Custom Method
Properties
Methods __call__ *
* this method should use the parameters of *args, **kwargs. it is going to handle making sure that all of the passed data (if any) get properly sifted and sorted into the corrct Param class instance. Those instances aree going to vrify the data type and make any conversions necessary and return the proper data. once that is done whatever code that needs to be run in order to get a proper returned value (if needed) is done.the returned values are then passed to the RetVal class instance that is for that piece of returned data for it to do any conversions needed. and then it will return that data.
You can see this whole system in action and working properly in this library
https://github.com/kdschlosser/UPNP_Device/tree/develop
Custom Param/RetVal
Properties
Methods __call__ ***
** returns either
'in'or'out'. this lets us know if it is a Param or a RetVal. the direction is used in the __call__ method to determine how to handle the data being passed.** the data type would be the python data type int, str, bytes, float, or a Content class
*** this method is the workhorse, it is going to do whatever needs to be done in determining that the data passed is of correct type. and make any adjustments as necessary. it will then return the proper data.
Channel
Properties
Methods activate record
Source
Properties
Methods activate __iter__ - iterate over content
Applications
Properties
Methods activate __iter__ - iterate over application to acquire content groups
Application Content Group / Media Folder
Properties
Methods __iter__ - iterate over group to get content
Application Content / Source Media
Properties
Methods activate
Icon
Properties
* returns the icon as a string if download process is not a simple URL
Similar problem here, 2016 model year tv, homeassistant 0.81.0b2, raspberry pi 3b+, hass-os. Homeassistant frontend shows as TV as “unknown” instead of “on”. I can adjust volume, and turn off from the frontend. When TV is off, the frontend correctly shows TV as “off”, however I cannot turn on from frontend, and log shows samsungtv component is taking longer than expected. Reverted to 0.80.3, and all functions, front end display work as expected.
I just recently bought a new Samsung UA65RU7100W and was really hoping to get lucky with this integration. Unfortunately it didn’t come up in any auto-discovery so I then went to manually enter the info in
configuration.yamlWhat I found works wasI changed the port to 8002 but that broke the power state and there was no other bits working either.
I am using Home-assistant Docker container and it didn’t even give me the authorization message on the TV so I did a wget from my docker host
wget http://xxx.xxx.xxx.xxx:8001and then found that this gave me the authorization message on the TV. I accepted this but still no luck. the media controls come up with error{'event': 'ms.channel.unauthorized'}each time.If I browse to
http://xxx.xxx.xxx.xxx:8001with an approved IP it now gives me a 401 error. Googling hasn’t helped but I am guessing that I need to have some sort of username and password for the TV? I believe this could be the missing bit to make this module work but I can’t be certain. hopefully this helps someone else in troubleshooting and resolving this issue.I also am using hassio on raspberry pi3b+. This is not a problem. All versions of homeassistant are available for download in github. Link for 0.80.3: https://github.com/home-assistant/home-assistant/archive/0.80.3.zip Extract the samsungtv.py file from \home-assistant-0.80.3.zip\home-assistant-0.80.3\homeassistant\components\media_player And place in your homeassistant \config\custom_components\media_player
I use the hassio addon “Samba share” to access the \config folder on the raspberry pi from my windows computer.
Great work @kdschlosser, hope to see this incorporated in HA soon.
I’m on 0.82.1 and only the Turn ON/OFF works while turning ON the TV (turn OFF does not work). I have a 2017 Samsung QLED TV QE65Q8FAMT on the latest firmware. Any news when this will be fixed ? Thanks guys.
@cnschulz To get this to work you can create a “custom component” to override the library:
Create folder \config\custom_components\samsungctl -> Add all files\folders from the fixed samsungctl library here
Make a copy of homeassistant’s samsungtv.py component. Change the three import statements referencing samsungctl to be:
import custom_components.samsungctl as samsungctl
(below are in def init) from custom_components.samsungctl import exceptions from custom_components.samsungctl import Remote
put that file here: \config\custom_components\media_player
experiencing the same issues…not sure what changed
I can also power on TV, but others are unauthorized, power off also
@AlexeyUkolov Sorry i dont upload all files try this https://github.com/xchwarze/ha-samsungtv-custom/releases/tag/v1.1.1 tested OK in HA 0.100.1 in Samsung MU6300
I’m not running HASS.IO but I got that working using
custom_components:samsungctlfolder from the modified version of the library under your/config/custom_components/pathsamsungtvcomponent with my patch above.samsungtv/media_player.pyfile’s import statement forsamsungctllibrary to use custom_components’ version:A side note for those wishing to do the same: I run HA dockerized under a non-root user and @eclair4151’s code depends on
token.txtfile created in library’s folder - if your user lacks write permissions, you’ll be continuously prompted by your TV to allow pairing. Solution for me was to runsamsungctlcommand under root manually once to generate the file and afterwards it all just works. Not sure if this file will need to be updated later down the road but we shall see.I have never been able to turn the TV on with HA, only turn it off.
Seems like new websocket with ssl support implemented here - https://github.com/kdschlosser/samsungctl
Just tried to downgrade samsungtv.py to the: _https://github.com/home-assistant/home-assistant/archive/0.80.3.zip_ version. And this fixes the problem for me.
to override the built in component, it needs to be placed here: /config/custom_components/media_player/samsungtv.py
Running Home assistant 0.83.2, media_player.samsung_tv_remote would always stay in “off” state. After downgrade, the component works again.
I have a Samsung UE55H6475 , firmware 2880
thanks @AlexeyUkolov ! I am working on it but without the documentation of samsung.remote.control it is very difficult to achieve. Maybe if I got the binary of samsung.remote.control (tizen binary from tv) I could add several improvements
Did it work using
wake_on_lan.send_magic_packetas a turn on action with your WebOS TV? If so, maybe try using https://www.home-assistant.io/components/universal/ with your Samsung TV as its only child and override only theturn_onaction.Within the docker container the file is located at
/usr/src/app/homeassistant/components/samsungtv/media_player.py. You can copy the component files to a location on your host, modify them and mount the host directory with-v "/path/on/host/samsungtv:/usr/src/app/homeassistant/components/samsungtv". This way, the modified files will persist between updates. You need to monitor the home assistant repo for larger changes to the files though, or things might break.So, just a side-node… this works… kinda. Having the token saved to token.txt has one big issue: If you have multiple Samsung TVs, the whole thing breaks down.
I am still working on the library. My suggestion is to use the develop branch of my repo. It has the most up to date code. I usually make 2-3 changes a day sometimes more,
I am still trying to hammer out the power portion of the program.
I seem to have broke the portion of the program that handles the encrypted TV’s (H and J - 2014 & 2015) I am not sure when I broke it. I am going to have to have someone with one of those TV’s to go back in the commit history and try each and every one until it works again. then I will be able to compare the code. So until that time the H and J TV’s are not going to work correctly.
I have a ES8000 from 2012 and this is also affecting my deployment of 0.90.2. Mine always reports when the TV turns on OK, but if I use Samsung’s SmartHub then HA reports the TV has switched off!
Yeah, with the current master branch, I can see the state.
Edit: It is not turning the tv off for me. Edit 2: The state is also not correctly being reported. I guess we need to make the develop branch work. That has a lot of additional fixes.
please move all chatter about testing the replacement for samsungtv.py to #20795. w are kind of off topic using this issue to discuss this. and there also seems to be quite a but of confusion as to what is going on.
ok sweet. now I have an example of how to save and load a Samsung specific config file.
I just have to think of a mechanism to be able to specify what TV’s to add. The only thing that I guess would be needed is to add an entry into the yaml file for Home Assistant that would have an IP, name and description of the TV.
OK so here is the skinny… No one seems to be getting this single thing.
the only thing needed for you to get a TV added is the host… that is all nothing else. let samsungctl do what i coded it to do, figure out all of the rest of the stuff for you. this way there is no confusion to what year TV needs what settings.
this
I can make an assumption on the US ks9005 one. UN??KS9005 the ?? is the size of the TV. if it is a K series TV then the connection is going to be a NON SSL websocket connection on port 8001.
that is what your yaml settings should look like. DO NOT add anything else it will get done for you automatically. Give me a little bit of time to modify the code again to write the config file for samsungctl instead of trying to alter the yaml file.
Sorry I’ve been on holiday from my leave for the last week 😉 Also just waiting for the new library name/publishing on PyPip etc, but should be able to pick it up in another week. Having a play with what new functionality we can include at the same time.
updated to 0.81.0 and the issue is still there