Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opening Youtube URL feature not working #145

Closed
dibyadip-das opened this issue Mar 21, 2022 · 53 comments
Closed

Opening Youtube URL feature not working #145

dibyadip-das opened this issue Mar 21, 2022 · 53 comments

Comments

@dibyadip-das
Copy link

Describe the bug
Cannot cast youtube URLs as mentioned in the 4th point of release notes.
image

I used the below config. Let me know in case any modification is required.
image

Expected behavior
Open youtube URL

Screenshots
If applicable, add screenshots to help explain your problem.

Environment details:

  • Environment (HASSIO, Raspbian, etc): HASSIO
  • Home Assistant version installed: 2022.3.5
  • Component version installed: 0.6.0
  • Last know working version: NA
  • TV model: Samsung The Frame 55"

Output of HA logs
Paste the relavant output of the HA log here.

N/A

Additional context
N/A

@ollo69
Copy link
Owner

ollo69 commented Mar 21, 2022

Do you have errors in the log? Can you please attach diagnostic info?

@dibyadip-das
Copy link
Author

I only got one error. Here is the diagnostic info

Logger: homeassistant.core
Source: custom_components/samsungtv_smart/api/smartthings.py:310
Integration: SamsungTV Smart ([documentation](https://github.com/ollo69/ha-samsungtv-smart), [issues](https://github.com/ollo69/ha-samsungtv-smart/issues))
First occurred: 17:13:07 (1 occurrences)
Last logged: 17:13:07

Error executing service: <ServiceCall media_player.turn_on (c:1de0eb2cf2c4ba5147db4965e73615e7): entity_id=['media_player.samsung_the_frame_tv']>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1654, in catch_exceptions
    await coro_or_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1673, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 668, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 949, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 705, in _handle_entity_call
    await result
  File "/config/custom_components/samsungtv_smart/media_player.py", line 1166, in async_turn_on
    await self._async_turn_on()
  File "/config/custom_components/samsungtv_smart/media_player.py", line 1150, in _async_turn_on
    if not await self._async_power_on(set_art_mode):
  File "/config/custom_components/samsungtv_smart/media_player.py", line 1134, in _async_power_on
    await self._st.async_turn_on()
  File "/config/custom_components/samsungtv_smart/api/smartthings.py", line 450, in async_turn_on
    await self._async_send_command(data_cmd)
  File "/config/custom_components/samsungtv_smart/api/smartthings.py", line 310, in _async_send_command
    async with self._session.post(
  File "/usr/local/lib/python3.9/site-packages/aiohttp/client.py", line 1138, in __aenter__
    self._resp = await self._coro
  File "/usr/local/lib/python3.9/site-packages/aiohttp/client.py", line 640, in _request
    resp.raise_for_status()
  File "/usr/local/lib/python3.9/site-packages/aiohttp/client_reqrep.py", line 1004, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 409, message='Conflict', url=URL('https://api.smartthings.com/v1/devices/f9eb372a-14ff-1c5c-d6c4-529e55cdbc63/commands')

@ollo69
Copy link
Owner

ollo69 commented Mar 21, 2022

I don't see diagnostic file attached here.

@dibyadip-das
Copy link
Author

Sorry, it took me some time to figure out how to get the file. Finally, I managed to download it. Here is the diagnostics file:
config_entry-samsungtv_smart-3aa340110551c8a2d412edbc3d92d0f9.json.txt

@ollo69
Copy link
Owner

ollo69 commented Mar 22, 2022

Please generate diagnostic file when TV is turned on.

@dibyadip-das
Copy link
Author

dibyadip-das commented Mar 22, 2022

Here you go. This diagnostic info has been collected after I turned on the television.
config_entry-samsungtv_smart-41198c96ed275ec2a7213a7012058f4c.json.txt

@ollo69
Copy link
Owner

ollo69 commented Mar 26, 2022

You need to configure an app to launch YouTube in app_list to have this feature available.

@dibyadip-das
Copy link
Author

Still, the feature is not working 😢

I added the app_list in config.yaml. As a result, I could see the app list under the sources

@ollo69
Copy link
Owner

ollo69 commented Mar 26, 2022

You see, but is properly configured? If you select the app from the list, is launched on the TV?

@dibyadip-das
Copy link
Author

Yes, I tried with YouTube and Spotify and both of them seem to work. Netflix and PrimeVideo are not working.

@ollo69
Copy link
Owner

ollo69 commented Mar 26, 2022

Hard to find the issue in this case. Please enable debug log for integration, try to use the feature and than attach log file to this thread.

@CriscoSwitch
Copy link

CriscoSwitch commented Apr 20, 2022

I'm having the same issue with my Samsung UN65TU7000FXZA. HA version 2022.4.5, SamsungTV Smart v0.6.3. Calling the service in Developer Mode in HA doesn't throw an error, but does nothing on my TV. Diagnostic file below:

config_entry-samsungtv_smart-f1068c8a40015fdd261c744428cbc23d.json (2).txt

Using the following to call the service:

data:
  media_content_id: https://www.youtube.com/watch?v=9N58uy3ezvA
  media_content_type: url
target:
  entity_id: media_player.living_room_tv

Below is a relevant snippet of the debug logs. To test, I switched to the Netflix app with a remote, then called the service for the URL, which did nothing. I then called the YouTube app itself, which worked as expected. Looks like the following line is the culprit here:
2022-04-20 03:08:23 DEBUG (MainThread) [custom_components.samsungtv_smart.api.upnp] 500, message='Internal Server Error', url=URL('http:https://10.11.15.14:9197/upnp/control/AVTransport1')

debuglogs.txt

@eperezf
Copy link

eperezf commented Jun 21, 2022

Can confirm, using a Samsung QN55Q60AAGXZS, HA version 2022.6.6, SamsungTV Smart 0.7.2. TV is not opening the YouTube video sent as url media type.

Using the service calling:

service: media_player.play_media
data:
  media_content_id: http:https://youtube.com/watch?v=YUhLIEhATuM
  media_content_type: url
target:
  entity_id: media_player.tv_living

I get the following messages in the log:

2022-06-21 15:35:20 DEBUG (MainThread) [custom_components.samsungtv_smart.api.upnp] 500, message='Internal Server Error', url=URL('http:https://192.168.100.46:9197/upnp/control/AVTransport1')
2022-06-21 15:35:20 DEBUG (MainThread) [custom_components.samsungtv_smart.media_player] Youtube video ID not found
2022-06-21 15:35:20 DEBUG (SyncWorker_6) [custom_components.samsungtv_smart.api.samsungws] Opening url in browser http:https://youtube.com/watch?v=YUhLIEhATuM
2022-06-21 15:35:20 DEBUG (SyncWorker_6) [custom_components.samsungtv_smart.api.samsungws] Sending run app app_id: org.tizen.browser app_type: NATIVE_LAUNCH meta_tag: http:https://youtube.com/watch?v=YUhLIEhATuM

There seem to be multiple things happening here. A 500 error in the UPNP control, not detecting the URL as a YouTube video and also not opening the browser with the URL.

It seems that it also doesn't detect the browser as an app because I al so get this debug message when listing the apps:

2022-06-21 15:35:10 DEBUG (SamsungControl) [custom_components.samsungtv_smart.api.samsungws] {'id': '3201606009684', 'result': {'id': '3201606009684', 'name': 'Spotify - Music and Podcasts', 'running': True, 'version': '2.1.33', 'visible': False}}
2022-06-21 15:35:10 DEBUG (SamsungControl) [custom_components.samsungtv_smart.api.samsungws] {'id': '111299001912', 'result': {'id': '111299001912', 'name': 'YouTube', 'running': True, 'version': '2.1.507', 'visible': False}}
2022-06-21 15:35:10 DEBUG (SamsungControl) [custom_components.samsungtv_smart.api.samsungws] {'id': 'kIciSQlYEM.plex', 'result': {'id': 'kIciSQlYEM.plex', 'name': 'Plex', 'running': False, 'version': '5.32.1', 'visible': False}}
2022-06-21 15:35:10 DEBUG (SamsungControl) [custom_components.samsungtv_smart.api.samsungws] {'error': {'code': 404, 'details': '', 'message': 'Not found error.', 'status': 404}, 'id': 'org.tizen.browser'}

Although when opening the browser it is detected as org.tizen.browser

@majorpeter
Copy link

majorpeter commented Jun 22, 2022

I had the same issue. Looked for the error message Youtube video ID not found in the code and found this block:

        if b"v" not in url_query:
            _LOGGER.debug("Youtube video ID not found")
            return None

        video_id = str(url_query[b"v"][0])

Changed the part b"v" to 'v' (so bytes type to str) and it fixed it.

I thought it was that the value types functions changed in Python recently. I'm running Home Assistant on this Python version:

Python 3.9.9 (main, Mar 12 2022, 01:17:00) 
[Clang 10.0.1 ([email protected]:llvm/llvm-project.git llvmorg-10.0.1-0-gef32c611a on freebsd12

According to the documentation it has been str for the last 7 years. Maybe in and array subscript operations were auto converting in earlier Pythons and are stricter now, dunno how to search for that information.

Anyways, @ollo69, I'd advise changing this in master also, since the docs say it's str.

Also I think this relates to #127

@dibyadip-das
Copy link
Author

Still, this feature is not working. Anyone has any update on this ?

@github-actions
Copy link

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 github-actions bot added the Stale label Nov 23, 2022
@dibyadip-das
Copy link
Author

Still after so many revisions, I cannot get this feature to work on my Samsung Frame 2021

@github-actions github-actions bot removed the Stale label Nov 24, 2022
@fherreror
Copy link

I had the same issue. Looked for the error message Youtube video ID not found in the code and found this block:

        if b"v" not in url_query:
            _LOGGER.debug("Youtube video ID not found")
            return None

        video_id = str(url_query[b"v"][0])

Changed the part b"v" to 'v' (so bytes type to str) and it fixed it.

I thought it was that the value types functions changed in Python recently. I'm running Home Assistant on this Python version:

Python 3.9.9 (main, Mar 12 2022, 01:17:00) 
[Clang 10.0.1 ([email protected]:llvm/llvm-project.git llvmorg-10.0.1-0-gef32c611a on freebsd12

According to the documentation it has been str for the last 7 years. Maybe in and array subscript operations were auto converting in earlier Pythons and are stricter now, dunno how to search for that information.

Anyways, @ollo69, I'd advise changing this in master also, since the docs say it's str.

Also I think this relates to #127

This worked nicely for solving the problem with not identifying the url as Youtube url nor obtaining video ID.

However, after solving this, nothing happens, the app is not launched:

2022-12-15 21:36:23.436 INFO (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Running websocket_api script 2022-12-15 21:36:23.436 INFO (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Executing step call service 2022-12-15 21:36:24.004 DEBUG (MainThread) [custom_components.samsungtv_smart.api.upnp] 500, message='Internal Server Error', url=URL('http:https://192.168.1.46:9197/upnp/control/AVTransport1') 2022-12-15 21:36:24.005 DEBUG (MainThread) [custom_components.samsungtv_smart.media_player] Youtube video ID: L_LUpnjgPso 2022-12-15 21:36:24.006 DEBUG (SyncWorker_16) [custom_components.samsungtv_smart.api.samsungws] Sending run app app_id: 9Ur5IzDKqV.TizenYouTube app_type: DEEP_LINK meta_tag: L_LUpnjgPso

Youtube is correctly configured, as I can launch youtube app in the TV from the integration. However, "run app" with youtube link does nothing in the TV.

The Internal Server Error with upnp still remains

@Jozefik
Copy link

Jozefik commented Dec 28, 2022

I had the same issue. Looked for the error message Youtube video ID not found in the code and found this block:

        if b"v" not in url_query:
            _LOGGER.debug("Youtube video ID not found")
            return None

        video_id = str(url_query[b"v"][0])

Changed the part b"v" to 'v' (so bytes type to str) and it fixed it.
I thought it was that the value types functions changed in Python recently. I'm running Home Assistant on this Python version:

Python 3.9.9 (main, Mar 12 2022, 01:17:00) 
[Clang 10.0.1 ([email protected]:llvm/llvm-project.git llvmorg-10.0.1-0-gef32c611a on freebsd12

According to the documentation it has been str for the last 7 years. Maybe in and array subscript operations were auto converting in earlier Pythons and are stricter now, dunno how to search for that information.
Anyways, @ollo69, I'd advise changing this in master also, since the docs say it's str.
Also I think this relates to #127

This worked nicely for solving the problem with not identifying the url as Youtube url nor obtaining video ID.

However, after solving this, nothing happens, the app is not launched:

2022-12-15 21:36:23.436 INFO (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Running websocket_api script 2022-12-15 21:36:23.436 INFO (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Executing step call service 2022-12-15 21:36:24.004 DEBUG (MainThread) [custom_components.samsungtv_smart.api.upnp] 500, message='Internal Server Error', url=URL('http:https://192.168.1.46:9197/upnp/control/AVTransport1') 2022-12-15 21:36:24.005 DEBUG (MainThread) [custom_components.samsungtv_smart.media_player] Youtube video ID: L_LUpnjgPso 2022-12-15 21:36:24.006 DEBUG (SyncWorker_16) [custom_components.samsungtv_smart.api.samsungws] Sending run app app_id: 9Ur5IzDKqV.TizenYouTube app_type: DEEP_LINK meta_tag: L_LUpnjgPso

Youtube is correctly configured, as I can launch youtube app in the TV from the integration. However, "run app" with youtube link does nothing in the TV.

The Internal Server Error with upnp still remains

Same thing. I fixed the Youtube video ID not found but Internal server error is still present

@ollo69
Copy link
Owner

ollo69 commented Jan 1, 2023

I fixed in last release the query string parsing as suggested in this thread. Unfortunately if TV do not react properly to the launch request with app_type: DEEP_LINK and meta_tag: <video_id> I don't know how to fix this. With my TV this command is working properly.

@marcioibm
Copy link

With the last release YouTube app opens on QN90B, but it stops at the home screen and won't open the video from the url

@fherreror
Copy link

I still have the same issue. Youtube app opens correctly when selecting from app_list, but it is impossible to launch any video.

However, I have found this doc about a youtube api used to control youtube on TV from an external device, which could be used to cast a video from HA. And it is a youtube API, not related to samsung, so I think it will work better on any TV with a youtube app.
I think youtube app has to been opened in the TV first, but it can be done with run_app

This is the link, in case @ollo69 wants to take a look. Maybe it could be implemented in the integration as a new feature
https://github.com/henriquekano/youtube-lounge-api/wiki

@ollo69
Copy link
Owner

ollo69 commented Jan 17, 2023

Thanks @fherreror,

looks like a full protocol to implement. I'll do some tests on next days and will give you a feedback.

@fherreror
Copy link

fherreror commented Jan 17, 2023

Thanks @fherreror,

looks like a full protocol to implement. I'll do some tests on next days and will give you a feedback.

@ollo69 I have also found this implementation of the protocol, though written in Go. It may be useful:

https://github.com/MarcoLucidi01/ytcast

I have been testing the protocol.
First, with youtube app on, you have to make a GET requets at:
http:https://LOCAL_TV_IP:8080/ws/apps/YouTube

It returns a XML response, in which it includes <screenID>BUNCHOFLETTERSANDNUMBERS</screenID>

With this screenID (that I think is the same always), you have to retrieve the Lounge token (lounge seems to be the youtube concept for Room, linking screens with "remotes", remotes being the devices connected to control Youtube).
You make a POST request to:
https://www.youtube.com/api/lounge/pairing/get_lounge_token_batch
content-type: x-www-form-urlencoded
screen_ids: SCREENID_OBTEINED_BEFORE

This throws a XML answer with the lounge token. This token expires, so you have to refresh it from time to time.

Then you have to create the connection to the screen, get events on what is playing on youtube, etc.

Then you can send commands to control YT. They are listed in the annex of the wiki I linked before.

Finally you have to disconnect from the TV using the other command.

This is what I have been able to discover until now. However I think that the implementation in the link in this post is well defined.
I hope this can help.

@fherreror
Copy link

I found this other implementation in python, much simpler than the previous one:
https://github.com/ur1katz/casttube/

In this one, you only need the screenId that you can obtain as described in my previous post (and I can confirm that screenId is mantained along time, as it is the same now than some hours ago, and I have turn off TV many times).

@ollo69
Copy link
Owner

ollo69 commented Jan 17, 2023

Thanks again, I will start some test this w.e.
Just wondering if this logic is valid also for others apps, for example to get the video running in Netflix and the ability to understand the current status (playing, pause, etc)

fherreror added a commit to fherreror/ha-samsungtv-smart that referenced this issue Jan 26, 2023
Added doc for casting videos to Youtube, as described here: ollo69#145 (comment)
@ollo69
Copy link
Owner

ollo69 commented Jan 26, 2023

However, you have to have the youtube app open before calling the service. Maybe, it could be implemented as a new feature, that when you call a youtube URL, the integration first opens the youtube app and then plays the desired video.

This is already implemented, and it works on my TV. Are you able to open the YouTube app from integration or you use the TV remote for this? Did you configure YouTube app in apps list?

PS. Thanks for PR, I will review this w.e.

@fherreror
Copy link

However, you have to have the youtube app open before calling the service. Maybe, it could be implemented as a new feature, that when you call a youtube URL, the integration first opens the youtube app and then plays the desired video.

This is already implemented, and it works on my TV. Are you able to open the YouTube app from integration or you use the TV remote for this? Did you configure YouTube app in apps list?

PS. Thanks for PR, I will review this w.e.

You are right. It works.
The problem I found is that integration does not update TV source when I change to TV, it keeps stuck showing Youtube as running app/source, so when I call the service again, the integration thinks youtube is already open and does not try to open it again. i.e. I run youtube, and integration shows youtube as playing source. I change to TV, TV changes, but integration keep showing youtube as running app.
I think, this may be related to this: #214
e.g.: I have change to TV input like 5 minutes ago. In smart things, it shows the correct chanel. However in integration it keeps saying Youtube.
I have noticed that when I change source to any other app, integration does update source, but when only when I change to TV it does not.
Maybe I have to configure TV sources or sth like that?

@fherreror
Copy link

More info about the problem:
With TV source on, the attributes of the entity are:

source_list: TV, PC, Netflix, Prime Video, Spotify, YouTube, Rakuten TV, Movistar +
ip_address: XXXXXX
device_class: tv
icon: mdi:television
friendly_name: Televisor Samsung
supported_features: 221117
sound_mode_list: Amplificar, Estándar, Sonido adaptable
picture_mode: Estándar
picture_mode_list: Dinámico, Estándar, FILMMAKER MODE, Natural, Película
volume_level: 0.11
is_volume_muted: false
media_content_type: app
app_id: 9Ur5IzDKqV.TizenYouTube
source: YouTube
sound_mode: Estándar
media_title: YouTube
entity_picture: /api/media_player_proxy/media_player.televisor_samsung?token=XXXX&cache=XXXX

I think integration does not update info when change to Live TV, only when changing to app

@ollo69
Copy link
Owner

ollo69 commented Jan 26, 2023

Yes, it is because app still running in background. Probably if you exit from the app instead of just switching the source, information are updated. I will make some more analysis this weekend to see if I can better determinate open (and not running) app.

@fherreror
Copy link

Yes, it is because app still running in background. Probably if you exit from the app instead of just switching the source, information are updated. I will make some more analysis this weekend to see if I can better determinate open (and not running) app.

I've made some more tests.
The problem is YouTube App.
Before I open YouTube app. I change from TV Live to Netflix, then change to TV Live, and integration shows the change.
Now I open YouTube by sending a video. Now I change to TV Live and integration keeps showing YouTube.
Now I change to Netflix. Integration shows Netflix. I change again to TV Live, and integration shows YouTube!! (not netflix)
I have even tried and exit YouTube app from inside (it asked me if I wanted to close YouTube app), but it keeps showing YouTube.
Before last update I had no problem. Maybe last update has changed something in how it manages YouTube app?

ollo69 added a commit that referenced this issue Jan 28, 2023
* Update README.md

Added doc for casting videos to Youtube, as described here: #145 (comment)

---------

Co-authored-by: ollo69 <[email protected]>
@ollo69
Copy link
Owner

ollo69 commented Jan 28, 2023

@fherreror,

this problem is more generic and related to wrong information that SmartThings do not update.
In last release (v0.1.11) I review a little bit running app status detection, that now should be more reliable and faster. Please try it and let me know if it fix the issue.

@fherreror
Copy link

fherreror commented Jan 29, 2023

Thanks for all.
However, the problem persists. I have been doing more tests.
When TV turns on, integration shows TV and channel name without problem. But after I launch any app, either with the TV remote or with the integration, whenever I change back to Live TV, integration keeps stuck in last app or Youtube (probably because, as you have said, they are running in background).
It is not a problem of waiting, because it never changes back to live TV in integration.
I think the problem is that when Smartthings communicates LIVE TV, integration does not update.
For example, in logs I see this:

2023-01-29 19:16:29.368 DEBUG (MainThread) [custom_components.samsungtv_smart.api.smartthings] {'main': {'logType': {'value': '["errCode","dump"]'}, 'mndt': {'value': '2020-01-01'}, 'mnfv': {'value': '---'}, 'supportsPowerOnByOcf': {'value': 'true'}, 'mnhw': {'value': ''}, 'data': {'value': None}, 'di': {'value': 'XXXX'}, 'supportedPlaybackCommands': {'value': '["play","pause","stop","fastForward","rewind"]'}, 'supportedInputSources': {'value': '["digitalTv","HDMI2"]'}, 'mnsl': {'value': None}, 'supportedPictureModesMap': {'value': '[{"id":"modeDynamic","name":"Dinámico"},{"id":"modeStandard","name":"Estándar"},{"id":"modeFilmmakerMode","name":"FILMMAKER MODE"},{"id":"modeNatural","name":"Natural"},{"id":"modeMovie","name":"Película"}]'}, 'dmv': {'value': 'res.1.1.0,sh.1.1.0'}, 'error': {'value': None}, 'switch': {'value': 'on'}, 'dumpType': {'value': 'id'}, 'vid': {'value': 'VD-STV_2018_K'}, 'endpoint': {'value': 'NONE'}, 'mnpv': {'value': '5.5'}, 'supportedPictureModes': {'value': '["Dinámico","Estándar","FILMMAKER MODE","Natural","Película"]'}, 'firmwareVersion': {'value': '3.4.0'}, 'icv': {'value': 'core.1.1.0'}, 'supportedSoundModes': {'value': '["Amplificar","Estándar","Sonido adaptable"]'}, 'st': {'value': '2022-12-12T23:14:43Z'}, 'minVersion': {'value': '1.0'}, 'pictureMode': {'value': 'Estándar'}, 'supportedSoundModesMap': {'value': '[{"id":"modeAmplify","name":"Amplificar"},{"id":"modeStandard","name":"Estándar"},{"id":"modeAdaptive","name":"Sonido adaptable"}]'}, 'disabledCapabilities': {'value': '["samsungvd.ambient","samsungvd.ambient18","samsungvd.ambientContent"]'}, 'soundMode': {'value': 'Estándar'}, 'setupId': {'value': '101'}, 'playbackStatus': {'value': None}, 'supportedTrackControlCommands': {'value': None}, 'mute': {'value': 'unmuted'}, 'protocolType': {'value': 'ble_ocf'}, 'supportedAmbientApps': {'value': '[]'}, 'n': {'value': 'Televisión Samsung'}, 'mnId': {'value': '0AJK'}, 'mnmo': {'value': 'UE65TU7172UXXH'}, 'volume': {'value': '10', 'unit': '%'}, 'tvChannel': {'value': '1'}, 'mnmn': {'value': 'Samsung Electronics'}, 'mnml': {'value': None}, 'supportedInputSourcesMap': {'value': '[{"id":"dtv","name":"TV"},{"id":"HDMI2","name":"PC"}]'}, 'tvChannelName': {'value': 'La 1 HD'}, 'mnos': {'value': 'Tizen'}, 'signinPermission': {'value': None}, 'pi': {'value': 'XXXX'}, 'inputSource': {'value': 'dtv'}}}

So, as you see, integration gets that TV is on Live TV and even chanel name.

However, in entity status, I get this:

source_list:
  - TV
  - PC
  - Netflix
  - Prime Video
  - Spotify
  - YouTube
  - Rakuten TV
  - Movistar +
sound_mode_list:
  - Amplificar
  - Estándar
  - Sonido adaptable
volume_level: 0.1
is_volume_muted: false
media_content_type: app
media_title: YouTube
app_id: 9Ur5IzDKqV.TizenYouTube
source: YouTube
sound_mode: Estándar
ip_address: XXXX
picture_mode: Estándar
picture_mode_list:
  - Dinámico
  - Estándar
  - FILMMAKER MODE
  - Natural
  - Película
device_class: tv
entity_picture: >-
  /api/media_player_proxy/media_player.televisor_samsung?token=xxx&cache=xx
icon: mdi:television
friendly_name: Televisor Samsung
supported_features: 221117

Some versions ago, it worked with no problem. It used to take some seconds to update, but it updated at the end. Now, it does not update.
I have not been able to reproduce the previous state, as I only can downgrade to 10.1, in which the problem already exists.

I am going to see If I can get some more info on what the problem may be, but I am not sure where the code updates the entity state.

@ollo69
Copy link
Owner

ollo69 commented Jan 29, 2023

Nothing changed integration side about app detection from many version. What probably is changed is SmartThings that do not refresh anymore the information.
In last release I give more weight to information provided locally by TV, we should check what TV is providing (you should enable debug log for this).
Another important point is how your application list is configured: did you put for the app both the local app id and st app id separated by slash (e.g. youtube should be: 111299001912/9Ur5IzDKqV.TizenYouTube)? This is really important for change in last release.

@fherreror
Copy link

Hi:
Yes, This is my app list:

Netflix: 3201907018807/org.tizen.netflix-app
Prime Video: 3201910019365/org.tizen.primevideo
Spotify: "3201606009684"
YouTube: 111299001912/9Ur5IzDKqV.TizenYouTube
Rakuten TV: "3201511006428"
Movistar +: m52SXlMi8Y.YOMVITIZEN

Debug is enabled. In my previous post I included what debug was showing, which reflected all the info.

I have installed development environment, and I think I have found the problem (though I am not sure how to fix it).

When I change to TV Live, the self object updates with source TV/HDMI.

Then, _get_running_app is called, and this is where TV/HDMI is overwritten. This method detects that there is an app running and so, it overwrites running app.
Curious thing is that if I wait some seconds (the time I use for running code line by line), then, it works fine. It is as if is_app_running takes a bit to register that previous app is not running. i.e., as if _get_running_app is called before is_app_running registers that the app is not running anymore.

Anyway, before calling _get_running_app, the selg object has the correct info TV/HDMI, and is _get_running_up the method that overwrites it.
Maybe it could be implemented something to check if source is TV/HDMI or sth like this?

@ollo69
Copy link
Owner

ollo69 commented Jan 29, 2023

You should provide some more logs because status of the apps are returned by the ws channel when the status of running app changes. Of course, if your TV do not update this information this is the issue.
Behavior of _get_running_app is correct. It use information from TV ws channel and SmartThings to determinate running app. If SmartThings say that YouTube is running and TV say nothing, YouTube is running! I really cannot immaginate any other rule for this. The info TV/HDMI just means no info.
In any case _get_running_app is called when the status of running app change (event) and on polling (every 15 secs.) I expect that the event is raised when the status change, but if this not happen we still have the poll. So if your integration continue to say that YouTube is running, timing is not the issue.
Debug logs taken when the app is started and stopped should help.

@fherreror
Copy link

These are the logs. In this logs, I changed first from TV to Netflix and then again to TV. TV changed source ok, integration did not.

2023-01-29 21:56:11.643 DEBUG (MainThread) [custom_components.samsungtv_smart.api.smartthings] {'main': {'logType': {'value': '["errCode","dump"]'}, 'mndt': {'value': '2020-01-01'}, 'mnfv': {'value': 'T-KTSU2DEUC-2400.9'}, 'supportsPowerOnByOcf': {'value': 'true'}, 'mnhw': {'value': ''}, 'data': {'value': None}, 'di': {'value': 'XXX'}, 'supportedPlaybackCommands': {'value': '["play","pause","stop","fastForward","rewind"]'}, 'supportedInputSources': {'value': '["digitalTv","HDMI2"]'}, 'mnsl': {'value': None}, 'supportedPictureModesMap': {'value': '[{"id":"modeDynamic","name":"Dinámico"},{"id":"modeStandard","name":"Estándar"},{"id":"modeFilmmakerMode","name":"FILMMAKER MODE"},{"id":"modeNatural","name":"Natural"},{"id":"modeMovie","name":"Película"}]'}, 'dmv': {'value': 'res.1.1.0,sh.1.1.0'}, 'error': {'value': None}, 'switch': {'value': 'on'}, 'dumpType': {'value': 'id'}, 'vid': {'value': 'VD-STV_2018_K'}, 'endpoint': {'value': 'NONE'}, 'mnpv': {'value': '5.5'}, 'supportedPictureModes': {'value': '["Dinámico","Estándar","FILMMAKER MODE","Natural","Película"]'}, 'firmwareVersion': {'value': '3.4.0'}, 'icv': {'value': 'core.1.1.0'}, 'supportedSoundModes': {'value': '["Amplificar","Estándar","Sonido adaptable"]'}, 'st': {'value': '2022-12-12T23:14:43Z'}, 'minVersion': {'value': '1.0'}, 'pictureMode': {'value': 'Estándar'}, 'supportedSoundModesMap': {'value': '[{"id":"modeAmplify","name":"Amplificar"},{"id":"modeStandard","name":"Estándar"},{"id":"modeAdaptive","name":"Sonido adaptable"}]'}, 'disabledCapabilities': {'value': '["samsungvd.ambient","samsungvd.ambient18","samsungvd.ambientContent"]'}, 'soundMode': {'value': 'Estándar'}, 'setupId': {'value': '101'}, 'playbackStatus': {'value': None}, 'supportedTrackControlCommands': {'value': None}, 'mute': {'value': 'unmuted'}, 'protocolType': {'value': 'ble_ocf'}, 'supportedAmbientApps': {'value': '[]'}, 'n': {'value': 'Televisión Samsung'}, 'mnId': {'value': '0AJK'}, 'mnmo': {'value': 'UE65TU7172UXXH'}, 'volume': {'value': '10', 'unit': '%'}, 'tvChannel': {'value': '1'}, 'mnmn': {'value': 'Samsung Electronics'}, 'mnml': {'value': None}, 'supportedInputSourcesMap': {'value': '[{"id":"dtv","name":"TV"},{"id":"HDMI2","name":"PC"}]'}, 'tvChannelName': {'value': 'La 1 HD'}, 'mnos': {'value': 'Tizen'}, 'signinPermission': {'value': None}, 'pi': {'value': 'XXX'}, 'inputSource': {'value': 'dtv'}}}
2023-01-29 21:56:13.349 DEBUG (SamsungRemote) [custom_components.samsungtv_smart.api.samsungws] Received WS remote ping b'\x00', sending pong
2023-01-29 21:56:13.350 DEBUG (SamsungArt) [custom_components.samsungtv_smart.api.samsungws] Received WS art ping b'\x00', sending pong
2023-01-29 21:56:13.352 DEBUG (SamsungControl) [custom_components.samsungtv_smart.api.samsungws] Received WS control ping b'\x00', sending pong
2023-01-29 21:56:19.352 DEBUG (SamsungRemote) [custom_components.samsungtv_smart.api.samsungws] Received WS remote ping b'\x00', sending pong
2023-01-29 21:56:19.355 DEBUG (SamsungControl) [custom_components.samsungtv_smart.api.samsungws] Received WS control ping b'\x00', sending pong
2023-01-29 21:56:19.357 DEBUG (SamsungArt) [custom_components.samsungtv_smart.api.samsungws] Received WS art ping b'\x00', sending pong
2023-01-29 21:56:20.814 DEBUG (SyncWorker_29) [custom_components.samsungtv_smart.api.samsungws] Sending run app app_id: 3201907018807 app_type: DEEP_LINK meta_tag: 
2023-01-29 21:56:20.881 DEBUG (MainThread) [custom_components.samsungtv_smart.api.smartthings] {'deviceId': 'XXX', 'state': 'ONLINE', 'lastUpdatedDate': '2023-01-29T20:16:20.313Z'}
2023-01-29 21:56:21.976 DEBUG (MainThread) [custom_components.samsungtv_smart.api.smartthings] {'main': {'logType': {'value': '["errCode","dump"]'}, 'mndt': {'value': '2020-01-01'}, 'mnfv': {'value': 'T-KTSU2DEUC-2400.9'}, 'supportsPowerOnByOcf': {'value': 'true'}, 'mnhw': {'value': ''}, 'data': {'value': None}, 'di': {'value': 'XXX'}, 'supportedPlaybackCommands': {'value': '["play","pause","stop","fastForward","rewind"]'}, 'supportedInputSources': {'value': '["digitalTv","HDMI2"]'}, 'mnsl': {'value': None}, 'supportedPictureModesMap': {'value': '[{"id":"modeDynamic","name":"Dinámico"},{"id":"modeStandard","name":"Estándar"},{"id":"modeFilmmakerMode","name":"FILMMAKER MODE"},{"id":"modeNatural","name":"Natural"},{"id":"modeMovie","name":"Película"}]'}, 'dmv': {'value': 'res.1.1.0,sh.1.1.0'}, 'error': {'value': None}, 'switch': {'value': 'on'}, 'dumpType': {'value': 'id'}, 'vid': {'value': 'VD-STV_2018_K'}, 'endpoint': {'value': 'NONE'}, 'mnpv': {'value': '5.5'}, 'supportedPictureModes': {'value': '["Dinámico","Estándar","FILMMAKER MODE","Natural","Película"]'}, 'firmwareVersion': {'value': '3.4.0'}, 'icv': {'value': 'core.1.1.0'}, 'supportedSoundModes': {'value': '["Amplificar","Estándar","Sonido adaptable"]'}, 'st': {'value': '2022-12-12T23:14:43Z'}, 'minVersion': {'value': '1.0'}, 'pictureMode': {'value': 'Estándar'}, 'supportedSoundModesMap': {'value': '[{"id":"modeAmplify","name":"Amplificar"},{"id":"modeStandard","name":"Estándar"},{"id":"modeAdaptive","name":"Sonido adaptable"}]'}, 'disabledCapabilities': {'value': '["samsungvd.ambient","samsungvd.ambient18","samsungvd.ambientContent"]'}, 'soundMode': {'value': 'Estándar'}, 'setupId': {'value': '101'}, 'playbackStatus': {'value': None}, 'supportedTrackControlCommands': {'value': None}, 'mute': {'value': 'unmuted'}, 'protocolType': {'value': 'ble_ocf'}, 'supportedAmbientApps': {'value': '[]'}, 'n': {'value': 'Televisión Samsung'}, 'mnId': {'value': '0AJK'}, 'mnmo': {'value': 'UE65TU7172UXXH'}, 'volume': {'value': '10', 'unit': '%'}, 'tvChannel': {'value': '1'}, 'mnmn': {'value': 'Samsung Electronics'}, 'mnml': {'value': None}, 'supportedInputSourcesMap': {'value': '[{"id":"dtv","name":"TV"},{"id":"HDMI2","name":"PC"}]'}, 'tvChannelName': {'value': 'La 1 HD'}, 'mnos': {'value': 'Tizen'}, 'signinPermission': {'value': None}, 'pi': {'value': 'XXX'}, 'inputSource': {'value': 'dtv'}}}
2023-01-29 21:56:22.285 DEBUG (SamsungControl) [custom_components.samsungtv_smart.api.samsungws] {'id': '3201907018807', 'result': True}
2023-01-29 21:56:22.285 DEBUG (SamsungControl) [custom_components.samsungtv_smart.api.samsungws] app running: 3201907018807
2023-01-29 21:56:24.833 DEBUG (MainThread) [custom_components.samsungtv_smart.media_player] status_changed_callback called
2023-01-29 21:56:24.863 DEBUG (MainThread) [custom_components.samsungtv_smart.media_player] New media title is: Netflix, old media title is: <none>, running app is: Netflix
2023-01-29 21:56:25.356 DEBUG (SamsungArt) [custom_components.samsungtv_smart.api.samsungws] Received WS art ping b'\x00', sending pong
2023-01-29 21:56:25.357 DEBUG (SamsungRemote) [custom_components.samsungtv_smart.api.samsungws] Received WS remote ping b'\x00', sending pong
2023-01-29 21:56:28.287 DEBUG (SamsungControl) [custom_components.samsungtv_smart.api.samsungws] Received WS control ping b'\x00', sending pong
2023-01-29 21:56:31.358 DEBUG (SamsungArt) [custom_components.samsungtv_smart.api.samsungws] Received WS art ping b'\x00', sending pong
2023-01-29 21:56:31.361 DEBUG (SamsungRemote) [custom_components.samsungtv_smart.api.samsungws] Received WS remote ping b'\x00', sending pong
2023-01-29 21:56:33.775 DEBUG (MainThread) [custom_components.samsungtv_smart.api.smartthings] {'deviceId': 'XXX', 'state': 'ONLINE', 'lastUpdatedDate': '2023-01-29T20:16:20.313Z'}
2023-01-29 21:56:33.834 DEBUG (MainThread) [custom_components.samsungtv_smart.api.smartthings] {'main': {'logType': {'value': '["errCode","dump"]'}, 'mndt': {'value': '2020-01-01'}, 'mnfv': {'value': 'T-KTSU2DEUC-2400.9'}, 'supportsPowerOnByOcf': {'value': 'true'}, 'mnhw': {'value': ''}, 'data': {'value': None}, 'di': {'value': 'XXX'}, 'supportedPlaybackCommands': {'value': '["play","pause","stop","fastForward","rewind"]'}, 'supportedInputSources': {'value': '["digitalTv","HDMI2"]'}, 'mnsl': {'value': None}, 'supportedPictureModesMap': {'value': '[{"id":"modeDynamic","name":"Dinámico"},{"id":"modeStandard","name":"Estándar"},{"id":"modeFilmmakerMode","name":"FILMMAKER MODE"},{"id":"modeNatural","name":"Natural"},{"id":"modeMovie","name":"Película"}]'}, 'dmv': {'value': 'res.1.1.0,sh.1.1.0'}, 'error': {'value': None}, 'switch': {'value': 'on'}, 'dumpType': {'value': 'id'}, 'vid': {'value': 'VD-STV_2018_K'}, 'endpoint': {'value': 'NONE'}, 'mnpv': {'value': '5.5'}, 'supportedPictureModes': {'value': '["Dinámico","Estándar","FILMMAKER MODE","Natural","Película"]'}, 'firmwareVersion': {'value': '3.4.0'}, 'icv': {'value': 'core.1.1.0'}, 'supportedSoundModes': {'value': '["Amplificar","Estándar","Sonido adaptable"]'}, 'st': {'value': '2022-12-12T23:14:43Z'}, 'minVersion': {'value': '1.0'}, 'pictureMode': {'value': 'Estándar'}, 'supportedSoundModesMap': {'value': '[{"id":"modeAmplify","name":"Amplificar"},{"id":"modeStandard","name":"Estándar"},{"id":"modeAdaptive","name":"Sonido adaptable"}]'}, 'disabledCapabilities': {'value': '["samsungvd.ambient","samsungvd.ambient18","samsungvd.ambientContent"]'}, 'soundMode': {'value': 'Estándar'}, 'setupId': {'value': '101'}, 'playbackStatus': {'value': None}, 'supportedTrackControlCommands': {'value': None}, 'mute': {'value': 'unmuted'}, 'protocolType': {'value': 'ble_ocf'}, 'supportedAmbientApps': {'value': '[]'}, 'n': {'value': 'Televisión Samsung'}, 'mnId': {'value': '0AJK'}, 'mnmo': {'value': 'UE65TU7172UXXH'}, 'volume': {'value': '10', 'unit': '%'}, 'tvChannel': {'value': '1'}, 'mnmn': {'value': 'Samsung Electronics'}, 'mnml': {'value': None}, 'supportedInputSourcesMap': {'value': '[{"id":"dtv","name":"TV"},{"id":"HDMI2","name":"PC"}]'}, 'tvChannelName': {'value': 'La 1 HD'}, 'mnos': {'value': 'Tizen'}, 'signinPermission': {'value': None}, 'pi': {'value': 'XXX'}, 'inputSource': {'value': 'dtv'}}}
2023-01-29 21:56:34.288 DEBUG (SamsungControl) [custom_components.samsungtv_smart.api.samsungws] Received WS control ping b'\x00', sending pong
2023-01-29 21:56:37.360 DEBUG (SamsungRemote) [custom_components.samsungtv_smart.api.samsungws] Received WS remote ping b'\x00', sending pong
2023-01-29 21:56:37.361 DEBUG (SamsungArt) [custom_components.samsungtv_smart.api.samsungws] Received WS art ping b'\x00', sending pong
2023-01-29 21:56:40.289 DEBUG (SamsungControl) [custom_components.samsungtv_smart.api.samsungws] Received WS control ping b'\x00', sending pong
2023-01-29 21:56:40.606 DEBUG (MainThread) [custom_components.samsungtv_smart.api.smartthings] {'deviceId': 'XXX', 'state': 'ONLINE', 'lastUpdatedDate': '2023-01-29T20:16:20.313Z'}
2023-01-29 21:56:40.665 DEBUG (MainThread) [custom_components.samsungtv_smart.api.smartthings] {'main': {'logType': {'value': '["errCode","dump"]'}, 'mndt': {'value': '2020-01-01'}, 'mnfv': {'value': 'T-KTSU2DEUC-2400.9'}, 'supportsPowerOnByOcf': {'value': 'true'}, 'mnhw': {'value': ''}, 'data': {'value': None}, 'di': {'value': 'XXX'}, 'supportedPlaybackCommands': {'value': '["play","pause","stop","fastForward","rewind"]'}, 'supportedInputSources': {'value': '["digitalTv","HDMI2"]'}, 'mnsl': {'value': None}, 'supportedPictureModesMap': {'value': '[{"id":"modeDynamic","name":"Dinámico"},{"id":"modeStandard","name":"Estándar"},{"id":"modeFilmmakerMode","name":"FILMMAKER MODE"},{"id":"modeNatural","name":"Natural"},{"id":"modeMovie","name":"Película"}]'}, 'dmv': {'value': 'res.1.1.0,sh.1.1.0'}, 'error': {'value': None}, 'switch': {'value': 'on'}, 'dumpType': {'value': 'id'}, 'vid': {'value': 'VD-STV_2018_K'}, 'endpoint': {'value': 'NONE'}, 'mnpv': {'value': '5.5'}, 'supportedPictureModes': {'value': '["Dinámico","Estándar","FILMMAKER MODE","Natural","Película"]'}, 'firmwareVersion': {'value': '3.4.0'}, 'icv': {'value': 'core.1.1.0'}, 'supportedSoundModes': {'value': '["Amplificar","Estándar","Sonido adaptable"]'}, 'st': {'value': '2022-12-12T23:14:43Z'}, 'minVersion': {'value': '1.0'}, 'pictureMode': {'value': 'Estándar'}, 'supportedSoundModesMap': {'value': '[{"id":"modeAmplify","name":"Amplificar"},{"id":"modeStandard","name":"Estándar"},{"id":"modeAdaptive","name":"Sonido adaptable"}]'}, 'disabledCapabilities': {'value': '["samsungvd.ambient","samsungvd.ambient18","samsungvd.ambientContent"]'}, 'soundMode': {'value': 'Estándar'}, 'setupId': {'value': '101'}, 'playbackStatus': {'value': None}, 'supportedTrackControlCommands': {'value': None}, 'mute': {'value': 'unmuted'}, 'protocolType': {'value': 'ble_ocf'}, 'supportedAmbientApps': {'value': '[]'}, 'n': {'value': 'Televisión Samsung'}, 'mnId': {'value': '0AJK'}, 'mnmo': {'value': 'UE65TU7172UXXH'}, 'volume': {'value': '10', 'unit': '%'}, 'tvChannel': {'value': '1'}, 'mnmn': {'value': 'Samsung Electronics'}, 'mnml': {'value': None}, 'supportedInputSourcesMap': {'value': '[{"id":"dtv","name":"TV"},{"id":"HDMI2","name":"PC"}]'}, 'tvChannelName': {'value': 'La 1 HD'}, 'mnos': {'value': 'Tizen'}, 'signinPermission': {'value': None}, 'pi': {'value': 'XXX'}, 'inputSource': {'value': 'dtv'}}}
2023-01-29 21:56:43.363 DEBUG (SamsungArt) [custom_components.samsungtv_smart.api.samsungws] Received WS art ping b'\x00', sending pong
2023-01-29 21:56:43.364 DEBUG (SamsungRemote) [custom_components.samsungtv_smart.api.samsungws] Received WS remote ping b'\x00', sending pong
2023-01-29 21:56:46.291 DEBUG (SamsungControl) [custom_components.samsungtv_smart.api.samsungws] Received WS control ping b'\x00', sending pong
2023-01-29 21:56:49.365 DEBUG (SamsungArt) [custom_components.samsungtv_smart.api.samsungws] Received WS art ping b'\x00', sending pong
2023-01-29 21:56:49.367 DEBUG (SamsungRemote) [custom_components.samsungtv_smart.api.samsungws] Received WS remote ping b'\x00', sending pong
2023-01-29 21:56:52.293 DEBUG (SamsungControl) [custom_components.samsungtv_smart.api.samsungws] Received WS control ping b'\x00', sending pong
2023-01-29 21:56:55.367 DEBUG (SamsungArt) [custom_components.samsungtv_smart.api.samsungws] Received WS art ping b'\x00', sending pong
2023-01-29 21:56:55.370 DEBUG (SamsungRemote) [custom_components.samsungtv_smart.api.samsungws] Received WS remote ping b'\x00', sending pong
2023-01-29 21:56:55.608 DEBUG (MainThread) [custom_components.samsungtv_smart.api.smartthings] {'deviceId': 'XXX', 'state': 'ONLINE', 'lastUpdatedDate': '2023-01-29T20:16:20.313Z'}
2023-01-29 21:56:56.688 DEBUG (MainThread) [custom_components.samsungtv_smart.api.smartthings] {'main': {'logType': {'value': '["errCode","dump"]'}, 'mndt': {'value': '2020-01-01'}, 'mnfv': {'value': 'T-KTSU2DEUC-2400.9'}, 'supportsPowerOnByOcf': {'value': 'true'}, 'mnhw': {'value': ''}, 'data': {'value': None}, 'di': {'value': 'XXX'}, 'supportedPlaybackCommands': {'value': '["play","pause","stop","fastForward","rewind"]'}, 'supportedInputSources': {'value': '["digitalTv","HDMI2"]'}, 'mnsl': {'value': None}, 'supportedPictureModesMap': {'value': '[{"id":"modeDynamic","name":"Dinámico"},{"id":"modeStandard","name":"Estándar"},{"id":"modeFilmmakerMode","name":"FILMMAKER MODE"},{"id":"modeNatural","name":"Natural"},{"id":"modeMovie","name":"Película"}]'}, 'dmv': {'value': 'res.1.1.0,sh.1.1.0'}, 'error': {'value': None}, 'switch': {'value': 'on'}, 'dumpType': {'value': 'id'}, 'vid': {'value': 'VD-STV_2018_K'}, 'endpoint': {'value': 'NONE'}, 'mnpv': {'value': '5.5'}, 'supportedPictureModes': {'value': '["Dinámico","Estándar","FILMMAKER MODE","Natural","Película"]'}, 'firmwareVersion': {'value': '3.4.0'}, 'icv': {'value': 'core.1.1.0'}, 'supportedSoundModes': {'value': '["Amplificar","Estándar","Sonido adaptable"]'}, 'st': {'value': '2022-12-12T23:14:43Z'}, 'minVersion': {'value': '1.0'}, 'pictureMode': {'value': 'Estándar'}, 'supportedSoundModesMap': {'value': '[{"id":"modeAmplify","name":"Amplificar"},{"id":"modeStandard","name":"Estándar"},{"id":"modeAdaptive","name":"Sonido adaptable"}]'}, 'disabledCapabilities': {'value': '["samsungvd.ambient","samsungvd.ambient18","samsungvd.ambientContent"]'}, 'soundMode': {'value': 'Estándar'}, 'setupId': {'value': '101'}, 'playbackStatus': {'value': None}, 'supportedTrackControlCommands': {'value': None}, 'mute': {'value': 'unmuted'}, 'protocolType': {'value': 'ble_ocf'}, 'supportedAmbientApps': {'value': '[]'}, 'n': {'value': 'Televisión Samsung'}, 'mnId': {'value': '0AJK'}, 'mnmo': {'value': 'UE65TU7172UXXH'}, 'volume': {'value': '10', 'unit': '%'}, 'tvChannel': {'value': '1'}, 'mnmn': {'value': 'Samsung Electronics'}, 'mnml': {'value': None}, 'supportedInputSourcesMap': {'value': '[{"id":"dtv","name":"TV"},{"id":"HDMI2","name":"PC"}]'}, 'tvChannelName': {'value': 'La 1 HD'}, 'mnos': {'value': 'Tizen'}, 'signinPermission': {'value': None}, 'pi': {'value': 'XXX'}, 'inputSource': {'value': 'dtv'}}}
2023-01-29 21:56:58.295 DEBUG (SamsungControl) [custom_components.samsungtv_smart.api.samsungws] Received WS control ping b'\x00', sending pong
2023-01-29 21:57:01.370 DEBUG (SamsungRemote) [custom_components.samsungtv_smart.api.samsungws] Received WS remote ping b'\x00', sending pong
2023-01-29 21:57:01.375 DEBUG (SamsungArt) [custom_components.samsungtv_smart.api.samsungws] Received WS art ping b'\x00', sending pong
2023-01-29 21:57:04.297 DEBUG (SamsungControl) [custom_components.samsungtv_smart.api.samsungws] Received WS control ping b'\x00', sending pong
2023-01-29 21:57:07.372 DEBUG (SamsungRemote) [custom_components.samsungtv_smart.api.samsungws] Received WS remote ping b'\x00', sending pong
2023-01-29 21:57:07.375 DEBUG (SamsungArt) [custom_components.samsungtv_smart.api.samsungws] Received WS art ping b'\x00', sending pong
2023-01-29 21:57:10.299 DEBUG (SamsungControl) [custom_components.samsungtv_smart.api.samsungws] Received WS control ping b'\x00', sending pong

What I don't understand is why logs show that integration knows that current source is dtv and even channel name, but entity does not "refresh" with this info.

@fherreror
Copy link

More logs:

2023-01-29 22:26:10.771 DEBUG (MainThread) [custom_components.samsungtv_smart.api.smartthings] {'deviceId': 'XXX', 'state': 'ONLINE', 'lastUpdatedDate': '2023-01-29T21:11:40.723Z'}
2023-01-29 22:26:11.897 DEBUG (MainThread) [custom_components.samsungtv_smart.api.smartthings] {'main': {'logType': {'value': '["errCode","dump"]'}, 'mndt': {'value': '2020-01-01'}, 'mnfv': {'value': 'T-KTSU2DEUC-2400.9'}, 'supportsPowerOnByOcf': {'value': 'true'}, 'mnhw': {'value': ''}, 'data': {'value': None}, 'di': {'value': 'XXX'}, 'supportedPlaybackCommands': {'value': '["play","pause","stop","fastForward","rewind"]'}, 'supportedInputSources': {'value': '["digitalTv","HDMI2"]'}, 'mnsl': {'value': None}, 'supportedPictureModesMap': {'value': '[{"id":"modeDynamic","name":"Dinámico"},{"id":"modeStandard","name":"Estándar"},{"id":"modeFilmmakerMode","name":"FILMMAKER MODE"},{"id":"modeNatural","name":"Natural"},{"id":"modeMovie","name":"Película"}]'}, 'dmv': {'value': 'res.1.1.0,sh.1.1.0'}, 'error': {'value': None}, 'switch': {'value': 'on'}, 'dumpType': {'value': 'id'}, 'vid': {'value': 'VD-STV_2018_K'}, 'endpoint': {'value': 'NONE'}, 'mnpv': {'value': '5.5'}, 'supportedPictureModes': {'value': '["Dinámico","Estándar","FILMMAKER MODE","Natural","Película"]'}, 'firmwareVersion': {'value': '3.4.0'}, 'icv': {'value': 'core.1.1.0'}, 'supportedSoundModes': {'value': '["Amplificar","Estándar","Sonido adaptable"]'}, 'st': {'value': '2022-12-12T23:14:43Z'}, 'minVersion': {'value': '1.0'}, 'pictureMode': {'value': 'Estándar'}, 'supportedSoundModesMap': {'value': '[{"id":"modeAmplify","name":"Amplificar"},{"id":"modeStandard","name":"Estándar"},{"id":"modeAdaptive","name":"Sonido adaptable"}]'}, 'disabledCapabilities': {'value': '["samsungvd.ambient","samsungvd.ambient18","samsungvd.ambientContent"]'}, 'soundMode': {'value': 'Estándar'}, 'setupId': {'value': '101'}, 'playbackStatus': {'value': None}, 'supportedTrackControlCommands': {'value': None}, 'mute': {'value': 'unmuted'}, 'protocolType': {'value': 'ble_ocf'}, 'supportedAmbientApps': {'value': '[]'}, 'n': {'value': 'Televisión Samsung'}, 'mnId': {'value': '0AJK'}, 'mnmo': {'value': 'UE65TU7172UXXH'}, 'volume': {'value': '10', 'unit': '%'}, 'tvChannel': {'value': ''}, 'mnmn': {'value': 'Samsung Electronics'}, 'mnml': {'value': None}, 'supportedInputSourcesMap': {'value': '[{"id":"dtv","name":"TV"},{"id":"HDMI2","name":"PC"}]'}, 'tvChannelName': {'value': 'org.tizen.netflix-app'}, 'mnos': {'value': 'Tizen'}, 'signinPermission': {'value': None}, 'pi': {'value': 'XXX'}, 'inputSource': {'value': 'dtv'}}}
2023-01-29 22:26:12.660 DEBUG (SamsungControl) [custom_components.samsungtv_smart.api.samsungws] Received WS control ping b'\x00', sending pong
2023-01-29 22:26:15.580 DEBUG (SamsungArt) [custom_components.samsungtv_smart.api.samsungws] Received WS art ping b'\x00', sending pong
2023-01-29 22:26:15.582 DEBUG (SamsungRemote) [custom_components.samsungtv_smart.api.samsungws] Received WS remote ping b'\x00', sending pong
2023-01-29 22:26:17.060 DEBUG (MainThread) [custom_components.samsungtv_smart.api.smartthings] {'deviceId': 'XXX', 'state': 'ONLINE', 'lastUpdatedDate': '2023-01-29T21:11:40.723Z'}
2023-01-29 22:26:17.119 DEBUG (MainThread) [custom_components.samsungtv_smart.api.smartthings] {'main': {'logType': {'value': '["errCode","dump"]'}, 'mndt': {'value': '2020-01-01'}, 'mnfv': {'value': 'T-KTSU2DEUC-2400.9'}, 'supportsPowerOnByOcf': {'value': 'true'}, 'mnhw': {'value': ''}, 'data': {'value': None}, 'di': {'value': 'XXX'}, 'supportedPlaybackCommands': {'value': '["play","pause","stop","fastForward","rewind"]'}, 'supportedInputSources': {'value': '["digitalTv","HDMI2"]'}, 'mnsl': {'value': None}, 'supportedPictureModesMap': {'value': '[{"id":"modeDynamic","name":"Dinámico"},{"id":"modeStandard","name":"Estándar"},{"id":"modeFilmmakerMode","name":"FILMMAKER MODE"},{"id":"modeNatural","name":"Natural"},{"id":"modeMovie","name":"Película"}]'}, 'dmv': {'value': 'res.1.1.0,sh.1.1.0'}, 'error': {'value': None}, 'switch': {'value': 'on'}, 'dumpType': {'value': 'id'}, 'vid': {'value': 'VD-STV_2018_K'}, 'endpoint': {'value': 'NONE'}, 'mnpv': {'value': '5.5'}, 'supportedPictureModes': {'value': '["Dinámico","Estándar","FILMMAKER MODE","Natural","Película"]'}, 'firmwareVersion': {'value': '3.4.0'}, 'icv': {'value': 'core.1.1.0'}, 'supportedSoundModes': {'value': '["Amplificar","Estándar","Sonido adaptable"]'}, 'st': {'value': '2022-12-12T23:14:43Z'}, 'minVersion': {'value': '1.0'}, 'pictureMode': {'value': 'Estándar'}, 'supportedSoundModesMap': {'value': '[{"id":"modeAmplify","name":"Amplificar"},{"id":"modeStandard","name":"Estándar"},{"id":"modeAdaptive","name":"Sonido adaptable"}]'}, 'disabledCapabilities': {'value': '["samsungvd.ambient","samsungvd.ambient18","samsungvd.ambientContent"]'}, 'soundMode': {'value': 'Estándar'}, 'setupId': {'value': '101'}, 'playbackStatus': {'value': None}, 'supportedTrackControlCommands': {'value': None}, 'mute': {'value': 'unmuted'}, 'protocolType': {'value': 'ble_ocf'}, 'supportedAmbientApps': {'value': '[]'}, 'n': {'value': 'Televisión Samsung'}, 'mnId': {'value': '0AJK'}, 'mnmo': {'value': 'UE65TU7172UXXH'}, 'volume': {'value': '10', 'unit': '%'}, 'tvChannel': {'value': ''}, 'mnmn': {'value': 'Samsung Electronics'}, 'mnml': {'value': None}, 'supportedInputSourcesMap': {'value': '[{"id":"dtv","name":"TV"},{"id":"HDMI2","name":"PC"}]'}, 'tvChannelName': {'value': 'org.tizen.netflix-app'}, 'mnos': {'value': 'Tizen'}, 'signinPermission': {'value': None}, 'pi': {'value': 'XXX'}, 'inputSource': {'value': 'dtv'}}}
2023-01-29 22:26:18.662 DEBUG (SamsungControl) [custom_components.samsungtv_smart.api.samsungws] Received WS control ping b'\x00', sending pong
2023-01-29 22:26:21.582 DEBUG (SamsungArt) [custom_components.samsungtv_smart.api.samsungws] Received WS art ping b'\x00', sending pong
2023-01-29 22:26:21.584 DEBUG (SamsungRemote) [custom_components.samsungtv_smart.api.samsungws] Received WS remote ping b'\x00', sending pong
2023-01-29 22:26:24.664 DEBUG (SamsungControl) [custom_components.samsungtv_smart.api.samsungws] Received WS control ping b'\x00', sending pong
2023-01-29 22:26:25.780 DEBUG (MainThread) [custom_components.samsungtv_smart.api.smartthings] {'deviceId': 'XXX', 'state': 'ONLINE', 'lastUpdatedDate': '2023-01-29T21:11:40.723Z'}
2023-01-29 22:26:26.855 DEBUG (MainThread) [custom_components.samsungtv_smart.api.smartthings] {'main': {'logType': {'value': '["errCode","dump"]'}, 'mndt': {'value': '2020-01-01'}, 'mnfv': {'value': 'T-KTSU2DEUC-2400.9'}, 'supportsPowerOnByOcf': {'value': 'true'}, 'mnhw': {'value': ''}, 'data': {'value': None}, 'di': {'value': 'XXX'}, 'supportedPlaybackCommands': {'value': '["play","pause","stop","fastForward","rewind"]'}, 'supportedInputSources': {'value': '["digitalTv","HDMI2"]'}, 'mnsl': {'value': None}, 'supportedPictureModesMap': {'value': '[{"id":"modeDynamic","name":"Dinámico"},{"id":"modeStandard","name":"Estándar"},{"id":"modeFilmmakerMode","name":"FILMMAKER MODE"},{"id":"modeNatural","name":"Natural"},{"id":"modeMovie","name":"Película"}]'}, 'dmv': {'value': 'res.1.1.0,sh.1.1.0'}, 'error': {'value': None}, 'switch': {'value': 'on'}, 'dumpType': {'value': 'id'}, 'vid': {'value': 'VD-STV_2018_K'}, 'endpoint': {'value': 'NONE'}, 'mnpv': {'value': '5.5'}, 'supportedPictureModes': {'value': '["Dinámico","Estándar","FILMMAKER MODE","Natural","Película"]'}, 'firmwareVersion': {'value': '3.4.0'}, 'icv': {'value': 'core.1.1.0'}, 'supportedSoundModes': {'value': '["Amplificar","Estándar","Sonido adaptable"]'}, 'st': {'value': '2022-12-12T23:14:43Z'}, 'minVersion': {'value': '1.0'}, 'pictureMode': {'value': 'Estándar'}, 'supportedSoundModesMap': {'value': '[{"id":"modeAmplify","name":"Amplificar"},{"id":"modeStandard","name":"Estándar"},{"id":"modeAdaptive","name":"Sonido adaptable"}]'}, 'disabledCapabilities': {'value': '["samsungvd.ambient","samsungvd.ambient18","samsungvd.ambientContent"]'}, 'soundMode': {'value': 'Estándar'}, 'setupId': {'value': '101'}, 'playbackStatus': {'value': None}, 'supportedTrackControlCommands': {'value': None}, 'mute': {'value': 'unmuted'}, 'protocolType': {'value': 'ble_ocf'}, 'supportedAmbientApps': {'value': '[]'}, 'n': {'value': 'Televisión Samsung'}, 'mnId': {'value': '0AJK'}, 'mnmo': {'value': 'UE65TU7172UXXH'}, 'volume': {'value': '10', 'unit': '%'}, 'tvChannel': {'value': '1'}, 'mnmn': {'value': 'Samsung Electronics'}, 'mnml': {'value': None}, 'supportedInputSourcesMap': {'value': '[{"id":"dtv","name":"TV"},{"id":"HDMI2","name":"PC"}]'}, 'tvChannelName': {'value': 'La 1 HD'}, 'mnos': {'value': 'Tizen'}, 'signinPermission': {'value': None}, 'pi': {'value': 'XXX'}, 'inputSource': {'value': 'dtv'}}}
2023-01-29 22:26:27.584 DEBUG (SamsungRemote) [custom_components.samsungtv_smart.api.samsungws] Received WS remote ping b'\x00', sending pong
2023-01-29 22:26:27.587 DEBUG (SamsungArt) [custom_components.samsungtv_smart.api.samsungws] Received WS art ping b'\x00', sending pong
2023-01-29 22:26:30.666 DEBUG (SamsungControl) [custom_components.samsungtv_smart.api.samsungws] Received WS control ping b'\x00', sending pong
2023-01-29 22:26:33.586 DEBUG (SamsungRemote) [custom_components.samsungtv_smart.api.samsungws] Received WS remote ping b'\x00', sending pong
2023-01-29 22:26:33.588 DEBUG (SamsungArt) [custom_components.samsungtv_smart.api.samsungws] Received WS art ping b'\x00', sending pong
2023-01-29 22:26:36.669 DEBUG (SamsungControl) [custom_components.samsungtv_smart.api.samsungws] Received WS control ping b'\x00', sending pong
2023-01-29 22:26:39.588 DEBUG (SamsungArt) [custom_components.samsungtv_smart.api.samsungws] Received WS art ping b'\x00', sending pong
2023-01-29 22:26:39.590 DEBUG (SamsungRemote) [custom_components.samsungtv_smart.api.samsungws] Received WS remote ping b'\x00', sending pong

As soon as I Change from app to TV Live, the debug logs show the change with almost no delay. ¿Is this coming from TV or from SmartThings?
I'm seeing that when TV LIVE is on, TVChannel has a numeric value (number of channel) and TVChannelName is the name of the channel. On the other hand, when an app is running, TVChannel has an empty value and TVChannelName is the name of the app (the alphanumeric app_id). Maybe, this could be used for identifying when is LIVE or APP.

BTW, in my previous post, when I mentioned _get_running_app I was refering to the one in media_player, not in SamsungWS.

@ollo69
Copy link
Owner

ollo69 commented Jan 29, 2023

For what I can see seems that information returned by ws channel are very limited. Give me some more time to analyze this situation (btw totally different from information returned by my TV), it could be that require a different management, I was assuming that the problem was in SmartThings, but probably is in limited information from ws.

BTW, in my previous post, when I mentioned _get_running_app I was refering to the one in media_player, not in SamsungWS.

yes, this was clear to me

@fherreror
Copy link

Ok Thanks. If you need me to make any additional test or to get any additional data, just tell me.

@ollo69
Copy link
Owner

ollo69 commented Jan 30, 2023

Can you check if changing the source from TV remote provide different output in the log compared to changing source from HA? I saw in #224 some different behavior in ws response but I do not understand the reason.
Can you also attach diagnostics so that I can check your settings?

@fherreror
Copy link

fherreror commented Jan 30, 2023

ok. Yes, it is showing different behaviour.
When I change source with the TV remote, entity shows de correct app in app_id, but source does not change:

source_list:
  - TV
  - PC
  - Netflix
  - Prime Video
  - Spotify
  - YouTube
  - Rakuten TV
  - Movistar +
sound_mode_list:
  - Amplificar
  - Estándar
  - Sonido adaptable
ip_address: 192.168.1.46
picture_mode: Estándar
picture_mode_list:
  - Dinámico
  - Estándar
  - FILMMAKER MODE
  - Natural
  - Película
device_class: tv
icon: mdi:television
friendly_name: Televisor Samsung
supported_features: 221117
volume_level: 0.07
is_volume_muted: false
media_content_type: video
app_id: org.tizen.netflix-app
source: TV/HDMI
sound_mode: Estándar

As you can see, app_id changes to Netflix, but source remains in TV/HDMI.
If I change to LIVE TV with TV remote, entity updates correctly:

source_list:
  - TV
  - PC
  - Netflix
  - Prime Video
  - Spotify
  - YouTube
  - Rakuten TV
  - Movistar +
sound_mode_list:
  - Amplificar
  - Estándar
  - Sonido adaptable
ip_address: 192.168.1.46
picture_mode: Estándar
picture_mode_list:
  - Dinámico
  - Estándar
  - FILMMAKER MODE
  - Natural
  - Película
device_class: tv
icon: mdi:television
friendly_name: Televisor Samsung
supported_features: 221117
volume_level: 0.07
is_volume_muted: false
media_content_type: video
app_id: TV/HDMI
source: TV/HDMI
sound_mode: Estándar
media_title: La 1 HD
entity_picture_local: >-
  /api/media_player_proxy/media_player.televisor_samsung?token=XXX&cache=XXX
entity_picture: >-
  https://jaruba.github.io/channel-logos/export/transparent-color/dN6GTZyNY32q2onfrvJ2iAeE4su.png

Here go the debug logs changing app with TV remote and the diagnostics file:

DIAGNOSTICS.txt

LOG CHANGING TV REMOTE 30-1-23.txt

@ollo69
Copy link
Owner

ollo69 commented Jan 31, 2023

@fherreror,

please install last beta release v0.11.4b1 and let me know if it fix the issue. I expect that now running app come only from SmartThings, could be a little bit more slower but should work.
It should be good understand what happen in #224, because it seems that suddenly TV start providing app information required but not able to understand the cause,

@fherreror
Copy link

@ollo69 now it works.
app_id updates correctly, either changing with integration or with remote (with remote it takes some seconds, but it's ok).
The only thing now is that app_id updates, but source remains always in TV/HDMI, so in lovelace card, when an app is running, there is no info on what is running (no logo nor media_title).
This is an example of entity attributes when netflix is running:

source_list:
  - TV
  - PC
  - Netflix
  - Prime Video
  - Spotify
  - YouTube
  - Rakuten TV
  - Movistar +
sound_mode_list:
  - Amplificar
  - Estándar
  - Sonido adaptable
volume_level: 0.17
is_volume_muted: false
media_content_type: video
app_id: org.tizen.netflix-app
source: TV/HDMI
sound_mode: Estándar
ip_address: 192.168.XX
picture_mode: Estándar
picture_mode_list:
  - Dinámico
  - Estándar
  - FILMMAKER MODE
  - Natural
  - Película
device_class: tv
icon: mdi:television
friendly_name: Televisor Samsung
supported_features: 221117

@ollo69
Copy link
Owner

ollo69 commented Jan 31, 2023

Strange also this. The only reason is that netflix(in this case) is excluded from running app, but this can happen only if message from web socket was received, message that I don't see in your previous logs.
I suspect that this message is received only on specific conditions that I still not identify. Can you restart Hass, collect logs for some minutes (changing source both from TV remote and app) and than attach it to this thread. 10-15 minutes of logs should be good.

@fherreror
Copy link

Here it goes.
home-assistant_2023-01-31T16-58-22.179Z.log

As I see, in WS input source remains always the same when an app is launched (as it is not changed, actually), and what is changed is channelName.
Maybe, it could be implemented sth like this:

If channelName in app_list --> there is an app running --> set source = app(channel_name) and set app_id=app_id(channel_name)
Else --> set source = inputSource (TV, HDMI, or whatever) and set app_id= inputSource

Anyway, at this moment, the only thing not working in my case is that when I change to any app, Source in atributes is not changed and media info is not updated.

@ollo69
Copy link
Owner

ollo69 commented Jan 31, 2023

I think that I found the issue. This was something introduced in v0.10.0! Because my TV returns spontaneously list of running apps on every changes, in code review I forgot to call a specific method to query app status on interval. Unfortunately not all model works in the same ways. Please try last release and let me know if it works or still there are issue.

@fherreror
Copy link

Yes!! Now it works!! Than you so much for all the effort!!

@dibyadip-das
Copy link
Author

Thank you @ollo69 This is amazing. I can now open YouTube links in The Frame TV 2021.

@ollo69
Copy link
Owner

ollo69 commented Feb 5, 2023

I close this, feature now is working. Thanks everybody for support and suggestion, open a new issue if you found some new related problems.

@ollo69 ollo69 closed this as completed Feb 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants