-
Notifications
You must be signed in to change notification settings - Fork 41
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
Prevent power on (and any other commands) when PC is not connected to the TV #158
Comments
Hi @thomasfw I think the answer is "yes and no". I understand what you want to achieve, but it's not entirely straightforward to implement full "discoverability" of connected HDMI-devices. Firstly, the option you mention indeed only works to prevent powering off the display when the display has been set by the user to another input/app. The reason a similar option does not exist for powering on, is because communication is not possible with the TV when it is off (unless "always ready" is enabled on supported models)., So, generally speaking, the logic cannot assume that communication is always possible with the display. Then, to know the windows internal state of connected devices, windows/ the graphics card(s) must be queried for connected devices. I've researched that a bit already when I implemented the multi display topology feature. I think there is indeed the potential for more effective management of HDMI-connections but it becomes complex for a windows service to get access to the required lower-level info. I think there is more to discover, but when I last looked at this I concluded at the time that to dig further I'd probably need to write a display device driver, which is arguably no simple feat. For now however, there is the multi display topology option which should do some of what you need - if you have a 2-series or later display. There is one caveat though, when the PC is powering on from being fully off (i e when loading the lgtv companion service), all devices will power on initially until after the user login process when the user mode daemon loads and can discover which devices are currently connected and ensure they are powered on/off accordingly. Some other ways to achieve what you want, is to disable the automatic management of the device and either bind a keyboard shortcut to a script which power on the LG on and enable automatic management - so you can manually trigger it when you need it. Or for a bit more automation you could attempt to write a script which automate the HDMI-connected/disconnected state, ie monitor the connected/disconnected state of output devices and use lgtv companion to power on/off accordingly. Yes, this requires implementing your own solution or using other third party solutions to enumerate active displays and I'm not sure you can achieve more than what the topology feature already does, since it needs to be done in user mode. So, I hope that answers your question in the shortest amount of words :) |
@JPersson77 many thanks for the explanation, and thanks for your work on this. I see that this would require a substantial amount of work. In my case (using LG C1 so unfortunately can’t use the multi display topology option) it sounds like a custom script and disabling auto management would be the best option, like you say. Regarding disabling the app’s automatic management though, how do I stop the app/service from starting automatically when Windows boots? If I use If I can reliably disable all automatic management permanently, I can then make use of the cli to handle things for my use case. Is this possible? |
Hi again, Yes sure. You can simply uncheck the checkbox on the main UI per device to disable automatic management. Then you can use -autoenable and the CLI etc |
Ah yes I somehow missed that checkbox. Thanks again, I'll close this now. |
Hi @JPersson77, not sure if there's been a regression since this discussion, but when I disable 'Automatically manage this device' in the UI the TV still powers on at startup. |
Hi again, can you confirm that you clicked the "apply" button after unchecking the checkbox? |
Actually, I suspect the issue might've had more to do with my use of the cli However, I am still struggling to conditionally power on the TV and toggle automatic management using the cli. My startup script is essentially as below, and I have 'Automatically manage this device' disabled in the UI. // On windows startup:
if ( LGTVIsConnected() ) {
run("LGTV Companion.exe -poweron Device1 -autoenable Device1")
} else {
run("LGTV Companion.exe -autodisable Device1")
}
function LGTVIsConnected(): bool {
// Checks list of connected displays
} The scenario below explains the issue:
I'm assuming that when I call |
Hi, Yeah you are right. -autoenable and -autodisable is per session only s d overrides the global option, and so it is not reflected in the global options in the UI. It will persist until the service is restarted, which happens at system boot or after clicking "apply", but not after resuming from sleep/hibernate. So it depends a little what you mean by "switching on the PC". Is it resume from sleep or an actual boot? |
Ah, so from my perspective I've been doing a full shutdown, but after checking the logs and some googling I see that Windows 10/11 has fast startup enabled by default, which saves the OS state across shutdown/startup. You can see this in the first log below ( Seeing as this is the default power setting in Windows, maybe the LGTVCompanion service can be updated to detect this on startup and manually restart itself if necessary before doing anything else.. if that's possible. I've left fast startup disabled for now but would prefer to leave it on if it's possible to find a fix for this. Fast Startup Enabled (windows default)
You can see that the power on command is sent after the system is turned on again as the service didn't restart. There are some other errors after this point in the log but the TV did switch on. 📄 Log Output
Fast Startup DisabledAfter temporarily disabling fast startup in Windows, I followed the same steps and confirm that the LGTVCompanion service restarted on startup, and the LG TV did not switch on.
📄 Log Output (no fast startup)
Also not sure if this is related to disabling fast startup, but the TV is no longer switching off when I power down the PC, as you can see in the log. I'll look into this some more anyway. |
Hey, yeah that would explain the observed behaviour. Starting with the last issue - I can see that, with fast startup disabled, the app had issues leading to 1) the app cpuld not determine whether the shutdown was a reboot or shutdown and 2) the app could not turn the TV off due to communications errors. Both of these can likely be fixed by setting the shutdown timing to "delayed" and/or enabling persistent connections. Regarding the restart of the service. The service is already loaded in memory and operating, so enforcing a restart on resume from hibernate/fast boot is not really desirable. Thinking out loud, here are some ways, to achieve what you want. I will think about a nice implementation for a) and b) however. c) you can work with immediately if you'd like. Can you share the code for detecting availability of the TV (function LGTVIsConnected()) ? |
Thanks for the reply. Option (a) sounds logical to me, assuming it would Distinguish Fast Startup from Wake-from-Hibernation and sleep. Imo My isLGTVConnected()
{
; This is the string we search for in connected monitor names:
LGTVNameIdentifier := "LG TV"
WmiMonitorNames:=Map(), i:=0
Wmi:=ComObjGet("winmgmts:\\.\root\WMI")
For MonitorID in Wmi.ExecQuery("SELECT * FROM WmiMonitorID WHERE Active=TRUE")
{
if (!MonitorID.UserFriendlyName) {
continue
}
UserFriendlyName := ""
For N in MonitorID.UserFriendlyName.Clone() {
UserFriendlyName .= Chr(N)
}
WmiMonitorNames[++i] := UserFriendlyName
}
hasConnectedLGTV := false
For key, monitorName in WmiMonitorNames {
if ( InStr(monitorName, LGTVNameIdentifier, False) > 0 ) {
hasConnectedLGTV := true
Break
}
}
return hasConnectedLGTV
} Going back to the separate shutdown issue, I've switched shutdown timing to delayed but still having the same issue. How do I go about enabling persistent connections? 📄 Log Output (delayed shutdown)
|
Your system now properly detected a shutdown so that is an improvement. Persistent connections are enabled in the device configuration here: Thanks for the code! Going to think about what the WMI approach can add and if it should be combined with the current topology support. As well as options a), b) as discussed above. At the moment I don't think it's much desirable to create additional routines around "fast boot", as that will add nothing to the core functionality. Still I understand that there is a difference in what -autodisable/enable does, so it should be handled better. Your link is interesting but I can't help shuddering at the thought of integrating a device kernel driver to read system IRP's 😊 |
Bumping this issue, I extensively use my laptop for work and personal. When I'm using it for work in the morning I'll plug it in and my LG C4 will switch automagically, which is great and exactly what I desire, but outside of work whenever I power on my laptop for personal use in my apartment, it switches off my desktop to the HDMI it would be plugged into (Laptop), but since it isn't connected my LG C4 just switches to an HDMI that has no active connection. Forcing me to switch it back to my desktop HDMI source manually. Gets quite annoying after sometime, to the point that it's probably easier just to remove LGTV Companion completely from my Laptop and rely on manual source switching. I did think of some other logical solutions that might minimize the above but wouldn't rely on recognizing what type of display is connected to which port, these would be configuration options in the LG TV Companion UI
|
Is it possible to prevent LGTVCompanion from powering on the TV when the PC isn't connected to it?
I frequently move my pc between two displays (one being the LG TV), and the LG TV powers on at startup even when I'm not connected to it.
I've enabled the
Process power and screen off events only when the display input source is set to HDMI:
setting. Does this only apply to power/screen off, and not the power on command? Either way it doesn't seem to stop the on command from being sent to the TV when i'm not connected to it. Presumably this also wouldn't prevent the on/off command being sent if another device (or nothing at all) is plugged into the configured HDMI.I see that I can retrieve the TV's
serialNumber
withLGTVCli.exe -request system/getSystemInfo
. Maybe this can be used to verify that the TV selected in LGTVCompanion is currently connected to the PC. For example, by checking Window's connected display(s) serial number(s) match the selected display before sending the power/screen on/off (and any other automatic) commands?The text was updated successfully, but these errors were encountered: