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

Turn on not always work on Q7/Q9 2018 model #5

Closed
dzungpv opened this issue Jan 5, 2020 · 26 comments
Closed

Turn on not always work on Q7/Q9 2018 model #5

dzungpv opened this issue Jan 5, 2020 · 26 comments

Comments

@dzungpv
Copy link

dzungpv commented Jan 5, 2020

I have two TV Q7FN 55" and Q9FN 65", this is the only component work.
But i have problem with turn on.

LAN not work on my TV, it only work for wireless LAN, so in order for ON command work i do following on TV Settings:
Settings > General > Network settings > Expert settings > Power on with mobile (turn on) and enable IP remote .

It work fine with OFF command, but when it off press on, sometime work and sometime not.

I try the command and see that it use only KEY_POWER for both on/off, and some time the component not update correct state. So how to fix the problems?
Update: Smarthings App use same API and could show accurate state of the TVs and both of my TV could not use WOL to turn on.

@jaruba
Copy link
Owner

jaruba commented Jan 5, 2020

I have a 2017 TV and a 2019 TV. The 2019 TV works to turn it on through WiFi only, the 2017 TV needed to be connected through LAN in order to be turned on, even considering it has WiFi capabilities.

So, the model of the TV is very important here too. As one of my TVs stops the WiFi card when it is stopped, another does not.

Also note that when you turn the tv off, it may look like it's turning off instantly, but takes some time for it to actually turn off in the background.. as far as i know, the tv stays on in the background for a "grace period" after you close it, but I may be wrong.

With this said, there are some issues with getting the correct states, I do believe this and hope to improve it in time.

@dzungpv
Copy link
Author

dzungpv commented Jan 5, 2020

I have a 2017 TV and a 2019 TV. The 2019 TV works to turn it on through WiFi only, the 2017 TV needed to be connected through LAN in order to be turned on, even considering it has WiFi capabilities.

So, the model of the TV is very important here too. As one of my TVs stops the WiFi card when it is stopped, another does not.

Also note that when you turn the tv off, it may look like it's turning off instantly, but takes some time for it to actually turn off in the background.. as far as i know, the tv stays on in the background for a "grace period" after you close it, but I may be wrong.

With this said, there are some issues with getting the correct states, I do believe this and hope to improve it in time.

I have tested with dedicate WOL app on PC, there is a grace period after, TV turn off, ti still running on the background so WOL on command will not work in this time, instead use KEY_POWER will make it on. So we can add the additional command KEY_POWER a long with WOL, if after WOL timeout and TV not ON?

@jaruba
Copy link
Owner

jaruba commented Jan 5, 2020

That sounds reasonable, if we can make some solid logic for it.

Hacks like these tend to come back and bite you in the ass after some time.

@dzungpv
Copy link
Author

dzungpv commented Jan 5, 2020

Other bug with your fork is on off state not update accurate you can use remote/app control to turn on, later turn off, it will not update in the hass. But i see when tv off, hass show it on but volume/up down disable, so when vol disable is is Off?
I try with original repos. It show accurate state when use remove: i tested qled procotol

@jaruba
Copy link
Owner

jaruba commented Jan 10, 2020

i think if you set:

update_method: "ping"

in your config, it might fix the on / off state issues you've been having

@jaruba
Copy link
Owner

jaruba commented Jan 10, 2020

About using "KEY_POWER" in case WOL fails, I'm starting to see numerous issues with this:

  • it takes a long time for the states to change, and this can vary from one TV to another, so we can't make foolproof logic for it
  • "KEY_POWER" handles both power on and power off, it's basically toggling the state, not setting it.. so if the logic fails, we might turn off the TV as soon as it turns on with WOL, which might create more issues then it solves
  • only Turn On does not work after Turn Off (for a grace period), the states though, are actually correct, because the TV is actually On, just the screen is turned off, if you Turn it Off A SECOND TIME from HA, then it will actually turn off the TV completely and you can Turn it On normally with WOL

All this might be seem visually confusing if someone is just spamming the power button from the HA panel.. But the states and methods do seem to work correctly, at least in the few tests with my 2019 TV.

And the case of someone wanting to turn a TV back on a short time after turning it off should be rare enough..

@dzungpv
Copy link
Author

dzungpv commented Jan 10, 2020

About using "KEY_POWER" in case WOL fails, I'm starting to see numerous issues with this:

  • it takes a long time for the states to change, and this can vary from one TV to another, so we can't make foolproof logic for it
  • "KEY_POWER" handles both power on and power off, it's basically toggling the state, not setting it.. so if the logic fails, we might turn off the TV as soon as it turns on with WOL, which might create more issues then it solves
  • only Turn On does not work after Turn Off (for a grace period), the states though, are actually correct, because the TV is actually On, just the screen is turned off, if you Turn it Off A SECOND TIME from HA, then it will actually turn off the TV completely and you can Turn it On normally with WOL

All this might be seem visually confusing if someone is just spamming the power button from the HA panel.. But the states and methods do seem to work correctly, at least in the few tests with my 2019 TV.

And the case of someone wanting to turn a TV back on a short time after turning it off should be rare enough..

I have test this my my 2 TVs, WOL only turn on, so if ping TV off and then send KEY_POWER follow by WOL, it work but with some delay cause by "ping"

@dzungpv
Copy link
Author

dzungpv commented Jan 10, 2020

But smarthings app work all the time, i connect it to smarthings HA component, appear as switch.

@jaruba
Copy link
Owner

jaruba commented Jan 10, 2020

@dzungpv doesn't the smartthings app use Bluetooth to connect to the TVs?

@dzungpv
Copy link
Author

dzungpv commented Jan 10, 2020

@jaruba i test by turn off bluetooth, and bluetooth only use when TV on, when it off must use WOW for my TVs or IR remote

@jaruba
Copy link
Owner

jaruba commented Jan 10, 2020

I do love how smartthings shows the input :(

And I am stubborn..

@dzungpv
Copy link
Author

dzungpv commented Jan 10, 2020

@jaruba on tizen tv it intergrate smarthing, api connected to server. So it connected to smarthings app through it.

@jaruba
Copy link
Owner

jaruba commented Jan 10, 2020

Yeah, SmartThings uses a the cloud API, not the local API..

@jaruba
Copy link
Owner

jaruba commented Jan 10, 2020

There's a lot of useful data in the cloud api.. obviously..

"name": "supportedInputSources",
...
"value": "[\"digitalTv\",\"TV\",\"HDMI1\",\"Chromecast\",\"HDMI2\",\"PC\",\"HDMI3\",\"Apple TV\"]",
"name": "inputSource",
...
"value": "digitalTv",

It would take a lot of effort implementing cloud support though..

@jaruba
Copy link
Owner

jaruba commented Jan 10, 2020

I feel like a SmartThings TV component would fit best in it's own custom component though, as it would fix all issues from this component which uses only the local APIs.

So this might be completely out of the scope of this component.

@pegatron89
Copy link

pegatron89 commented Jan 24, 2020

I have been playing around with the smarthings API. Looks promising. I can currently get:
State on or off
current source (HDMI1 or HDMI2 or HDMI3...)
Turn tv off (not on 👎 )
Set/get vol / mute
change between hdmis
get the individual hdmi labels you have set on the tv
current app running if any
current TV channel (not tested as i use virgin media into hdmi. but its there)

looks like there may be a way to run an app but havent tried it yet as only discovered the app name earlier today. Going to try making it run with a new custom component tonight. no clue how but i will give it a try.

it looks like if you knew what you are doing you add it with the HA smarthings integration, i dont see why not, I am just learning python so its all new to me.

@jaruba
Copy link
Owner

jaruba commented Jan 25, 2020

@pegatron89 I'm not a python developer either, but I can code in anything if needed..

You really did do a lot of work on this, I'm curious about your component, might be able to help with it.

it looks like if you knew what you are doing you add it with the HA smarthings integration, i dont see why not, I am just learning python so its all new to me.

I've never tested HA's smartthings integration, so I'm not sure how that works. It may or may not be possible to add it there, as there's also a smartthings hub, so I'm unsure if that integration is supposed to be for the Cloud API, for emulating the hub, or for both..

@pegatron89
Copy link

I will put the code I have on my GitHub today. I didn't get a chance to try the media player component last night but will try this afternoon.

@pegatron89
Copy link

https://github.com/pegatron89/smartthingstv

You will need to get a smartthingsapi key from here

If you un-comment the function get_devices() it will give you your device IDs, Then add them to the DEVICE_ID variable and then the rest will work also

@jaruba
Copy link
Owner

jaruba commented Jan 25, 2020

@pegatron89 thanks, i know about the api key, i've already researched the subject on my own as i was planning on making such a component too

@pegatron89
Copy link

I have pretty much got the integration working with HA now. On / Off State is much quicker than any of the other components.

Currently:

  • On off state
  • current volume
  • Step volume up or down by 1
  • Turn TV off
  • Play / Pause stop etc commands work. But no way of knowing if anything is playing on any apps.
  • Show Current source (HDMI1 OR HDMI2 OR TV OR APP NAME)

Todo:
Add API key to config
Use API key to get and store device IDs locally
Generate source list for HA
Change source
Set Volume

I have the commands ready for the Change source and set volume, I just have no clue how to change part of the command to user input. eg:

COMMAND_SET_VOL = {"commands":[{"component": "main","capability": "audioVolume","command": "setVolume","arguments": [X]}]}

X being user input.

1 thing i found though, which is a pain in the ass.. I cant see anyway of launching an app. You can look at the capabilities here , When i check which are compatible with my tv there are;

"id": "switch", - Sets on off
 "id": "refresh", - Syncs data from tv to smartthings
"id": "ocf", - Not sure
"id": "audioVolume", Volume
"id": "execute", - Not sure
"id": "tvChannel", - Tv Channel, And app name*
 "id": "mediaInputSource", Set / check current Source
"id": "audioMute", - Check / set mute
 "id": "mediaPlayback", - Not sure havent tried
 "id": "custom.error", - Not sure
"id": "custom.picturemode", - Set picture mode
"id": "custom.soundmode", - Set sound mode
 "id": "custom.accessibility", - Not sure
  "id": "custom.launchapp", - Nothing**
 "id": "custom.recording", - Not Sure
 "id": "custom.tvsearch", - Not sure

*App name appears like; "KIciSQlYEM.Plex" on 1 of my samsungs and different on another.
** Cant find any documentation for this command. Tried sending various combinations to see if i could get it working but nothing.

Anyway, I will upload all my stuff to my github today and leave it here if you want to have a look.

@jaruba
Copy link
Owner

jaruba commented Feb 6, 2020

@pegatron89 That's amazing work, I personally did not have time yet to test it, I hope I'll find some time for it soon though. As I think I'd use it / work on it for a more complete Samsung TV component.

@jaruba
Copy link
Owner

jaruba commented Feb 6, 2020

1 thing i found though, which is a pain in the ass.. I cant see anyway of launching an app. You can look at the capabilities here , When i check which are compatible with my tv there are;

I'd even make a Frankenstein component using stuff from both cloud and local to get complete control if needed. The local API still works well in a lot of cases and will definitely be faster at some commands then using the Cloud API.

@pegatron89
Copy link

I have changed the code and removed the commands for the moment. I am rewriting the commands to 1 single command (hopefully) once I get that everything else should be ok.

Yeah no problem let me know if there are any issues you find or any way of changing it to work better.

@jaruba
Copy link
Owner

jaruba commented Feb 9, 2020

@pegatron89

*App name appears like; "KIciSQlYEM.Plex" on 1 of my samsungs and different on another.

Look at these:

These codes all work with the Samsung TVs afaik.

@jaruba
Copy link
Owner

jaruba commented Feb 16, 2020

Newest release includes the SmartThings API, you'll need to set api_key and device_id to enable it. The SmartThings API adds many new things, and also fixes this issue.

@jaruba jaruba closed this as completed Feb 16, 2020
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

3 participants