kmahon37 / plex-dvr-waker

Plex DVR Waker is a simple command-line tool for waking the computer before the next scheduled recording.
MIT License
8 stars 0 forks source link

Plex DVR Waker disables Shutter #24

Closed solstyce9 closed 4 years ago

solstyce9 commented 4 years ago

Win10, Plex 1.19.3.2852

Just set up my first DVR on Plex and set up Plex DVR Waker (add-task monitor) to wake up my server for scheduled recordings. Seemed to be working fine but realized my Plex system was no longer going to sleep when idle. Checked, and the app I use to have my system go to sleep - Shutter - was disabled. Re-enabled it, and an hour later noticed it was disabled again.

I have Shutter set to monitor outgoing network usage, CPU usage, and mouse/keyboard inactive time and when all conditions are met, put system to sleep (not hibernate), and then any Plex request to the server will wake it back up.

I'm thinking this is a conflict between how Shutter works and how PlexDVRWaker keeps the system awake that is causing Shutter to turn itself off. Hoping you can investigate.

Hate to double-dip in the same ticket, but I was looking to disable PlexDVRWaker for now since I'm still exploring the DVR system, but can't find a folder in Task Scheduler to remove. Can you give me more details on where to find the scheduled tasks to remove?

kmahon37 commented 4 years ago

I am not familiar with Shutter, except for what I see on their website. However, I can tell you how Plex DVR Waker works. Are you using the sync or monitor task? See screenshot below for where the tasks show in Task Scheduler (I'm only using the monitor task on my system).

image

Nothing in Plex DVR Waker is meant to "keep" the computer awake. All it does is wakeup the computer from sleep. My system is set to go to sleep after an hour, and it does.

If you want to see what is keeping your computer awake, you can try running the Windows utility powercfg /requests from an "Administrator" Command Prompt. You may have another culprit.

solstyce9 commented 4 years ago

Interesting. I'm using monitor but I think sync might be more my speed since I use DVR schedules to capture recurring series rather than needing near real time wake timer updates.

Thanks for the screenshot. That's where I was looking but I didn't see a folder for Plex DVR Waker tasks. Even looked in system32\tasks and didn't see anything there either. But when I ran 'Plexdvrwaker.exe list' it did list all the shows scheduled. Makes me think somehow the tasks weren't scheduled correctly. Thinking back, I configured it from a powershell window as administrator rather than a CMD window as admin so perhaps that caused a problem.

Whatever it is, sounds like the problem's on my end. I'll reinstall and try sync this time and from a CMD window and report back. Likely over the weekend once my new antenna arrives.

Appreciate the fast response! Feel free to close this.

Thanks!

PS. Random question- if your Plex server is set to sleep after an hour, how do you keep it from falling asleep while you're streaming content from the server to another device?

kmahon37 commented 4 years ago

It should run fine from either a Powershell or CMD prompt (as far as I know), as long as it is an "administrator" prompt (otherwise you'll get an error from Plex DVR Waker when it tries to create the tasks in Task Scheduler).

I've never had any issues with the computer falling asleep while streaming, but I generally don't stream anything longer than an hour. I know that Plex will keep the computer awake while its recording, but I need to check and see what it does while streaming. I also just found a Plex advanced setting under "Settings -> General" (and then click the Show Advanced button) for "Support Away Mode when preventing system sleep". This is enabled on my system, and it may be what "keeps" the computer awake while recording and streaming.

solstyce9 commented 4 years ago

Hmm, I tried the "Support Away Mode" option earlier but it didn't work for me. I'll stream music for hours off my Plex server and originally had it set to sleep after 15 minutes but it would fall asleep while streaming, hence Shutter.

I had some time this morning to look at this, and it seems to be working correctly now. When I reinstalled, it triggered an alert in Avast which reminded me when I installed the first time Avast triggered several warnings because it hadn't seen the file before. I suspect it blocked the changes to Task Scheduler and that's why I wasn't seeing the folder of Plex DVR Waker tasks.

I set up as a 15 minute sync task this time, and I see the tasks in the scheduler, and my system went back to sleep so it appears to be working fine now. My next scheduled recording is in a few hours, so hopefully it will wake up as expected and Plex will be be able to record.

Thanks!

solstyce9 commented 4 years ago

Well, it's waking as expected, but I'm running into occasional issues with Plex giving me a "No write access to destination" error and the DVR recording failing. It seems intermittent. I think it's happening when the server isn't already awake from me streaming. In the logs I see a warning about a network change

May 27, 2020 21:59:16.452 [11692] DEBUG - Network change.
May 27, 2020 21:59:16.452 [11692] DEBUG - NetworkInterface: Notified of network changed (force=0)
May 27, 2020 21:59:16.489 [11692] DEBUG - Detected primary interface: 192.168.2.3

and then eventually a failure to access the .grab directory on my NAS to make the capture

DEBUG - IsOnSameVolume: failed to open \\nas1\misc\video\recorded tv\.grab: The network path was not found.

I'm wondering if this because the network isn't fully recovered after waking in time to be able to access the NAS folder to do the grab.

Is there an option to wake the system earlier than 15 seconds, e.g. 5 minutes before a scheduled recording? I didn't see one in the documentation.

kmahon37 commented 4 years ago

No, there currently is no option for waking the computer earlier than 15 seconds, but it wouldn't be hard to add. But before I go down that road, for your next couple recordings, can you manually edit the "DVR wake" task in Task Scheduler and set the trigger time to maybe 1-5 minutes before and see if that helps things? I'd like to verify that would actually work for you before I go through adding a new option.

Note: You may have to disable the "DVR sync" or "DVR monitor" tasks while you test this so that they don't overwrite your manual change to the "DVR wake" task.

solstyce9 commented 4 years ago

Thanks for the reminder on disabling the sync task. I'm so sleep dep'd right now I would have missed that. My next recording is at 10pm tonight, so I've disabled the DVR sync task and edited the wake task to wake at 9:56p instead of 9:59 and I'll check the logs in the morning.

solstyce9 commented 4 years ago

Hmm, spent some time yesterday on this. To start I only disabled the Sync job and manually edited the time of the Wake job but I noticed the Wake job start time was still getting updated. I had thought Sync updated the Wake job, but it appears Sync just gets the list of recordings, and Wake checks that list and updates itself. So I disabled Wake also and set up manual wake-at-time-X tasks at 30s, 60s, 90s, 120s before scheduled recordings to see if there was any pattern and if earlier wake times helped.

What I discovered is that Plex DVR is annoyingly unstable and unpredictable. I'm not sure if this is due to Plex, or due to flaky TV reception causing Plex to fail due to bad data feeding into the transcode. In one case I saw my system fall asleep in the middle of the recording window - investigation showed the transcode failed due to an error early in the recording so the system fell asleep as it should. Another I saw hang on transcode and run over its scheduled end time, so the show scheduled immediately after that failed but not until the earlier recording finally sorted itself out. One of the other errors I have no idea what happened because I checked the logs and have logfiles for before that recording and after that recording but not of the actual recording.

I'm completely baffled at what's going on, but for now I'm going to put it down to bad reception until I have time to try an attic antenna.

When / if you have time, I think it would still be nice to be able to configure how soon before the scheduled recording time to wake up. Based on what I've seen so far with Plex DVR I don't trust it and would like to give it 5 minutes to sort itself out and grab a cup of coffee before it has to start a recording...

And don't want to sound unappreciative! Definitely appreciate Plex DVR Waker, and your time and attention to my problems! Thanks!

kmahon37 commented 4 years ago

Sorry, forgot to tell you about this part... the "DVR wake" task will automatically re-update itself 30 seconds after it is triggered. It does this just in case your sync/monitor interval for some reason doesn't refresh the next wakeup time before your next recording time. If you open the "DVR wake" task and look at the command line that it runs, you will see a "delay" argument set to 30 seconds (this is a hard-coded and hidden argument for the application).

The "DVR sync" task will get the list of recordings and update the "DVR wake" task to trigger for the first scheduled recording time. That's all the sync task does.

I do not use Plex's built-in transcoding (I believe it is still "experimental") or commercial removal, so I can't help you much there. Instead I use MCEBuddy to process the videos at a later time (usually while I'm sleeping). It's just something I've used for years even before Plex. I don't have the most powerful machine and I found that even using MCEBuddy to process videos while Plex is recording seems to affect the quality that Plex records, so I always schedule transcoding during times when I usually don't record anything.

Let me think some about the best way to add a new option to increase the pre-wakeup time, because it may affect a few things. Also, it's going to depend on how much spare time I have.

solstyce9 commented 4 years ago

Thanks for the additional info! If it's any easier, instead of an option, just hardcoding the wakeup time to T-60s instead of T-15s might give Plex some breathing room.

I've made several changes to my setup this week - moved antenna to the attic for better reception, and modified my Shutter settings so the CPU and network have to be quiet over 20 minutes instead of 10. I've also added a postprocessing script to convert my TS files to h264 via Handbrake.

I ran one 24 hour test after moving my antenna where I disabled Shutter and all 7 of my scheduled recordings worked without an issue. Problem with changing too much at once - don't know if the problem was sleep-related or antenna-related.

I'm in the middle of a multi-day ripping / encoding session so system won't be sleeping for a few days, but I'll update once it's done and I have a few days' worth of recordings under the new configuration. If I'm still seeing problems, I'll try manually setting the wake timers again to see if it's any better with the new antenna location. Just wanted to send an update that I'm still investigating.

kmahon37 commented 4 years ago

I added a new add-task option for specifying the wakeup time offset via --offset=SECONDS in v2.1.0. It still defaults to 15 seconds, but you can set it to 60 seconds or whatever you like. Hopefully this helps with your setup a little.

solstyce9 commented 4 years ago

Thanks! I upgraded to the latest version and set a 120s offset. Seems to be working fine, just have to run for a while and see if I see any more errors. Appreciate the fix!

Closing since both issues are resolved.

solstyce9 commented 4 years ago

To close the loop on this in case someone else stumbles across this in the future - the "no write access to destination" error was a two-fold problem not related to PlexDVRWaker. What was happening is my system was falling asleep and missing a recording, then when it wakes back up, rather than realizing the missed recording was in the past and shouldn't be attempted, it goes ahead and tries. Since this is in the first second of the system waking up, the network path isn't fully ready, and times out resulting in the "no write access" error. The actual error is two-fold: 1) I need to limit the window between system waking up and recording start time, 2) Plex needs to not try to start a recording where the start and end time was in the past, but if it does, use a more useful error message.

Root cause is pilot error on my part, and Plex assuming the DVR is always running. Thanks again for the new offset option - I'm going to use it to fine tune my sleep / wake schedule to try to keep this from happening...