Jump to content

Wake Up for Recordings


bjs339

Recommended Posts

bjs339

I created a Windows service that wakes up your computer for scheduled recordings. This allows you to let your computer go to sleep when not in use, but still wake up when it needs to. I've been using it for a few weeks now and it's been working pretty well. The app is attached, and source code is at https://github.com/bjs339/Emby-Wakeup-Trigger.

 

To install, unzip the contents to any location on the PC (I put mine under C:\Program Files\Emby Wakeup Trigger). Double-click on the install.bat file, and it will create a service called "Emby Wakeup Trigger". As long as that service runs under an account with Admin privileges, it should be able to do what it needs to.

When the service starts, it reads the location of your Emby home from the Emby Server service. It then uses the .NET FileSystemWatcher to watch for changes to the timers.json file that Emby uses to store recording information. When an entry is added to that file with a Status = New, it creates a scheduled task to wake the computer at show time, including any pre-padding. Note that this was created by simply watching Emby behavior and piggy-backing off of it, so a change to Emby Server could potentially break it.

If you're interested, give it a try and let me know how it goes.

 

Edit: Attachment updated 1/31/18

EmbyWakeupTrigger.zip

Edited by bjs339
  • Like 3
Link to comment
Share on other sites

Cool stuff, that's very interesting! What api is it using? Does that api require admin or is it something around the service that requires admin?

Link to comment
Share on other sites

bjs339

The part that watches for changes in the file uses the .NET FileSystemWatcher, and the scheduled task is created with http://taskscheduler.codeplex.com/. I'm not exactly sure what permissions the task scheduler requires. I've always run it as administrator. Not exactly sure what you need to create a scheduled task.

 

I forgot to mention in the previous post, but I tested the main parts on Windows 7, 8.1, and 10. It should work on any modern version of Windows.

Edited by bjs339
  • Like 1
Link to comment
Share on other sites

bjs339

Good question - I actually don't know that any of it does. I wrote that it requires admin privileges because I haven't tested it without, and didn't want that to trip anyone up. But I don't actually know that admin is required. Thinking about it now, I can't think of a reason that it would be.

Link to comment
Share on other sites

Try it out and if you can get that to work without admin rights then we can look at just building it in. Thanks.

Link to comment
Share on other sites

bjs339

I was mistaken - I'm actually running this service under the Local System account, same as the Emby Server service is running under. I only used an admin account to install the service. I think that means you'd be able to do the same as part of the core app. That would be great.

Link to comment
Share on other sites

inzombyac

This service looks promising as it will solve a need for me to put the server to sleep when not recording and not streaming.  When I run the service I cannot update the guide.  The scheduled task fails indicating that the timers.json is in use and cannot be updated.  Any thoughts?

System.IO.IOException: The process cannot access the file 'C:\Users\User\AppData\Roaming\MediaBrowser-Server\data\livetv\timers.json' because it is being used by another process.
Link to comment
Share on other sites

bjs339

The service writes errors to the Event Viewer > Windows Logs > Application. Do you see anything there?

 

It should only read timers.json when there's a change, and then be done with it. I think that file keeps records of previously recorded shows, so that file can grow rather large. I wonder if there's a timing issue parsing through all the entries in that file. I'll look into a way to make that more efficient.

Link to comment
Share on other sites

bjs339

@@inzombyac - Try the exe in the attached zip. It uses timers.json for less time and has improved parsing. You don't need to re-install the service; just unzip and overwrite your existing EmbyWakeupTrigger.exe with the new one. You'll probably have to stop the service temporarily to do it.

EmbyWakeupTrigger.zip

Link to comment
Share on other sites

inzombyac

I looked at the event viewer and Emby Wakeup Trigger was also reporting access issues to the file.  I'll try the new version and let you know.

Link to comment
Share on other sites

inzombyac

Same issue with the new version.  Both Emby and Emby Wakeup Trigger report access issues to the timers.json file in their respective logs.  Would there be a way to limit the access to timers.json to be on a schedule?  For example, if it checked every 30-60 minutes that would give the guide refresh task enough time to complete (it takes ~5 minutes for my server).  I am not adding that many new recordings, so I don't need to check often.

 

Is there a way to run this tool as a one off process instead of a continuous service and do a full check of timers.json?  If so I could schedule this to run outside of my guide update window.

Link to comment
Share on other sites

bjs339

I can look into creating an executable that you can run on demand. That shouldn't be difficult, just a matter of repackaging the existing code in a different way.

 

As far as your current problem, I wonder if something has a lock on that file and hasn't let go. You could try rebooting. Does Emby have an access problem even when the service is stopped?

  • Like 1
Link to comment
Share on other sites

inzombyac

I tried the reboot and running Emby and Emby Wakeup Trigger as different level users.  When I stop Emby Wakeup Trigger, I can update the guide.  Just can't run the Emby guide update and this service at the same time.  If there are more things you want me to try I'll be glad to. In any event, the tool is creating the wake up timers as expected so I'm happy.

Link to comment
Share on other sites

bjs339

Here's a modified version of the app that you can run on your own, outside of a service. You can set this up to run as a scheduled task once a day, or however you'd like. It does not use a service.

 

I have no idea why you'd get a conflict with the other version. I double-checked the FileSystemWatcher documentation and it shouldn't lock the file the way I'm using it. And I wouldn't think the guide update would even use timers.json, but apparently there is some type of conflict. If others report the same I'll look into it further.

Emby Wakeup Trigger Not Service.zip

Edited by bjs339
  • Like 1
Link to comment
Share on other sites

I personally would just drop the filesystemwatcher. Realistically all you need to do is poll the contents of the file a couple times a day.

 

But I am interested to know the results of running this standalone without a windows service. If it goes well then that tells me that perhaps admin rights aren't needed after all. Thanks.

Link to comment
Share on other sites

bjs339

Most recent update to original post can be run in either of two ways: as a service or as standalone executable. If using install.bat to install service, it adds a "--service" parameter to the service, which tells it to use the FileSystemWatcher. Or, just run it manually or set up your own scheduled task to run the .exe on its own. This will run on demand and then exit.

  • Like 1
Link to comment
Share on other sites

  • 1 month later...
bjs339

twos50,

Are you running it as a service or as a scheduled task, or manually? If you're running it as a service or you've executed the tool after scheduling recordings and you still don't see them, check the Event Viewer under Windows Logs > Application for messages. You can filter by the source "Emby Wakeup Trigger".

 

When the scheduled task for the show is created it doesn't have a meaningful name, just a guid as placeholder, but you can see your show description under the task description.

 

Blair

Link to comment
Share on other sites

twos50

@@bjs339

Ok thanks, I will take a look.  

But to tell you the truth, I had to delete my Emby server service and the Emby Wakeup Trigger.

After I ran the Emby Wakeup Trigger, the server wouldn't allow the computer to sleep(by the timer, not manually).  

The server runs fine when I select "run on login" option.  But running with the service started and being able to allow computer to sleep is the preferred option.

 

So now I'm trying to figure out how to recreate the Emby Server Service so that I may start all over.  

I've tried to create an Emby service from the cmd prompt, utilizing "googled searches on how to create a service",  but it's not working for me after even following directions of "making sure the binPath is in quotes" and such...

 

Any suggestions anyone??

Link to comment
Share on other sites

  • 5 months later...

Is there a way to post the EXE to the github folders? The Emby web forum appears to be having issues and won't let logged in users download the executable/zip in the first post. (Or perhaps it just does not like my account? :) ) I didn't really want to install visual studio just to build my own if i can keep from doing that.. 

 

And yes, i notified the forum help about the issue. I'm waiting on them to fix it still..

Link to comment
Share on other sites

Good day,

 

I removed the attachment in the first post since it not a complete upload when it was attach.

 

My best

Edited by Abobader
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...