how to wake/sleep macbook pro with mythtv

For discussion of topics specific to MythTV on OSX
Post Reply
fra2015
Newcomer
Posts: 3
Joined: Wed Oct 14, 2015 8:55 pm
United States of America

how to wake/sleep macbook pro with mythtv

Post by fra2015 »

Hello,

First, thanks a bunch for a wonderful product! I've had mythtv on a linux box for 10 years now. Not a single glitch!!! Absolutely loved it!! Until yesterday, the power supply failed and I thought instead of getting a new power supply and such, I'd like to try and install this on a macbook pro I anyway had hooked up to the TV and been using to watch movies, etc.

Using the prebuilt installer and following instructions on https://www.mythtv.org/wiki/MacPorts, I installed mythtv on the macbook. So far, it all went smoothly.
I'm getting the HDHomeRun Plus this Friday and will hopefully finish the installation and it'll be just as smooth as it has been so far.

I just have one question, in anticipation of Friday.

I usually have the mac with its lid shut. Like I said above, it is hooked up to a TV and I control it either using a wireless keyboard (that also has a trackpad) or by opening the lid and working directly with it.

My question is about what to do now that mythtv is on it. Do I adjust its settings so that it never goes to sleep, and then I can close the lid and still have the mac awake (maybe I'll need an app for that, I'm not sure. I can search, if that's the way to go). Or is there a better way to do this, e.g. by having it somehow go to sleep as usual, when it's idle, but then wake up in time for a recording. I have no idea how to make this latter thing happen on the Mac (especially if I'm closing the lid)! And also, what if it is asleep, I open the lid and stick a DVD in, watch a movie (not using mythtv, but by just opening the DVD using VLC, e.g.) and then when I'm done I put it back to sleep. Will it now wake for a recording?
Not sure at all. Maybe keeping the mac awake 24/7 is the only way??

Those who installed mythtv on a mac laptop: what did you do about this?
Any advice is most welcome.
User avatar
pvr4me
Senior
Posts: 763
Joined: Fri Feb 07, 2014 7:25 pm
Location: near Toronto, Canada
Contact:
Canada

Re: how to wake/sleep macbook pro with mythtv

Post by pvr4me »

Good questions...unfortunately, I don't know the answers.

My main Myth machine is a Mac Mini and I have it set to never sleep. OS X is really strong on energy management. I believe my Mini only supposed to draw 7 watts while idle (excluding the external drives). I keep meaning to borrow my brother's Kill-A-Watt to check but have never actually done so.

You can get more information on OS X sleep at:

https://support.apple.com/en-ca/HT201714

Why don't you try it out? Schedule a recording that you don't care about and put the MBP to sleep. Check after the recording is supposed to start.

Craig
Formerly the MacPorts guy.
fra2015
Newcomer
Posts: 3
Joined: Wed Oct 14, 2015 8:55 pm
United States of America

Re: how to wake/sleep macbook pro with mythtv

Post by fra2015 »

I installed the whole thing. Went pretty smoothly!

Last two things on my agenda: schedule emails sent out before and after recordings, informing me of the upcoming recordings.
I know how to get a list of the upcoming recordings using the myth_upcoming_recordings.pl script e.g. (Is there a better way? Would be nice to also get the tv guide status, i.e. number of days data is available for, but that's not too important).
I guess to have the script that sends the emails executed before/after recordings, I should use the Events section in myth-setup, right? Anyway. I'll sort it out. This is not the point of my post.

Then there is this sleep/wake issue. Here's what seems to be going on:

If I put the mac to sleep manually, it just sleeps blissfully and misses any recordings.
If I close the lid and the frontend is running, it keeps it from going to sleep, but I can see that it is using some CPU power pretty often (e.g. can hear the fan going every now and then).
If I exit the frontend and close the lid (or just leave the computer) it goes idle and goes to sleep.

One simple solution would be then: exit the frontend when I'm done watching, and then install an app that prevents the mac from sleeping while the lid is closed. Close the lid and forget about it.
The backend will still be on, the mac is not going to sleep, so it records and does everything it needs to do, until I come back to watch or schedule recordings. At that point I fire up mythfrontend and do my thing.

Would be nice to have a solution where the mac can go to sleep, though. Since I anyway exit mythfrontend when I'm not using it, it seems the only thing I need to figure it is how to time the mac's wake up time and have the mac wake up at that time after it goes to sleep (for whatever reason, whether manual or after being idle, etc).

There is a command line to tell the mac to wake up at a specific time: sudo pmset schedule wake "12/26/2009 00:00:00"
And to cancel it sudo pmset schedule cancel wake "12/26/2009 00:00:00"
I already tried the command lines and they do work.

So maybe the solution is to do one of the following:

A. have a crontab job running say every minute querying mythbackend for when the next scheduled recording is supposed to and recording the time in some tmp file, compare the time with the previous one that was in that tmp file (e.g. create first a copy tmp.old of that tmp file), and if the time has changed, then cancel the existing wake time and add the new one.

or, even more elegant:

B. don't use a crontab job but do the above (erasing old wake time and setting up a new one) whenever something changes in the recordings.


Now my question: is there a way to have the backend (or frontend) run a shell script whenever something changes in the recording schedules?

Thanks!
User avatar
pvr4me
Senior
Posts: 763
Joined: Fri Feb 07, 2014 7:25 pm
Location: near Toronto, Canada
Contact:
Canada

Re: how to wake/sleep macbook pro with mythtv

Post by pvr4me »

fra2015 wrote:I installed the whole thing. Went pretty smoothly!

Last two things on my agenda: schedule emails sent out before and after recordings, informing me of the upcoming recordings.
I know how to get a list of the upcoming recordings using the myth_upcoming_recordings.pl script e.g. (Is there a better way? Would be nice to also get the tv guide status, i.e. number of days data is available for, but that's not too important).
I guess to have the script that sends the emails executed before/after recordings, I should use the Events section in myth-setup, right? Anyway. I'll sort it out. This is not the point of my post.
What is the purpose of the before/after emails?

You can get also get the list of upcoming recordings through 'mythbackend --printsched' and other ways. You could also just use curl to get the backend status info via http. Again, it would help to know what you really want to do.
Then there is this sleep/wake issue. Here's what seems to be going on:

If I put the mac to sleep manually, it just sleeps blissfully and misses any recordings.
If I close the lid and the frontend is running, it keeps it from going to sleep, but I can see that it is using some CPU power pretty often (e.g. can hear the fan going every now and then).
If I exit the frontend and close the lid (or just leave the computer) it goes idle and goes to sleep.

One simple solution would be then: exit the frontend when I'm done watching, and then install an app that prevents the mac from sleeping while the lid is closed. Close the lid and forget about it.
The backend will still be on, the mac is not going to sleep, so it records and does everything it needs to do, until I come back to watch or schedule recordings. At that point I fire up mythfrontend and do my thing.

Would be nice to have a solution where the mac can go to sleep, though. Since I anyway exit mythfrontend when I'm not using it, it seems the only thing I need to figure it is how to time the mac's wake up time and have the mac wake up at that time after it goes to sleep (for whatever reason, whether manual or after being idle, etc).

There is a command line to tell the mac to wake up at a specific time: sudo pmset schedule wake "12/26/2009 00:00:00"
And to cancel it sudo pmset schedule cancel wake "12/26/2009 00:00:00"
I already tried the command lines and they do work.

So maybe the solution is to do one of the following:

A. have a crontab job running say every minute querying mythbackend for when the next scheduled recording is supposed to and recording the time in some tmp file, compare the time with the previous one that was in that tmp file (e.g. create first a copy tmp.old of that tmp file), and if the time has changed, then cancel the existing wake time and add the new one.

or, even more elegant:

B. don't use a crontab job but do the above (erasing old wake time and setting up a new one) whenever something changes in the recordings.
The MBP is hooked up to your TV, no? Full time? I presume you've got an external drive for recordings? (It is strongly NOT recommended to record to the boot volume!) The drive is going to have to stay powered on, even if it spins down. Why not just leave mythfrontend running all the time so the machine doesn't go fully asleep? I think the power draw is pretty small.

If you really want to power on/off, you'll need to use mythshutdown to check status since various jobs could be running or about to run. You may be able to use mythwelcome as well--I've never tested and I don't know that anyone else running it on OS X.

As I said, OS X is really quite good at power management by itself. I think the savings you'll achieve are going to be pretty small, in the real world.
Now my question: is there a way to have the backend (or frontend) run a shell script whenever something changes in the recording schedules?
I'm not aware of anything like this. The closest I know of is the "Scheduler ran" System Event. I think it runs after every recording plus after mythfilldatabase.

Craig
Formerly the MacPorts guy.
fra2015
Newcomer
Posts: 3
Joined: Wed Oct 14, 2015 8:55 pm
United States of America

Re: how to wake/sleep macbook pro with mythtv

Post by fra2015 »

I ended up coding a small shell script that does what A says. Namely, it uses myth_upcoming_recordings.pl to pull the time of the next recording. Then it uses the date command to subtract 5 minutes from that time. Then it compares to the previously stored version (from a minute ago) and if there has been a change it resets the wake time using pmset.
It wasn't too hard to code and it runs in the background without any issues.
(And it doesn't really use pmset unless the time of the next recording changes. Only then does it set a new wake up time.)

I also coded a script that pulls the whole list of scheduled recordings and also conflicts (again using myth_upcoming_recordings.pl), as well as the scheduled wake up times (using pmset -g sched). It then compares the current version of this status report to the previous one and sends me an email if it changes.
The cron job also runs this script every minute, but of course changes are very rare. E.g. they happen when I schedule something new or remove something old (but then I don't really need that email, heh heh) or when a recording starts (then the status says Recording instead of WillRecord) or when it is finished (then it is gone from the list and the wake time is updated too).

This seems to work for now. I'll test it for some time, and if it has any problems I'll try to figure out how to use mythshutdown. Or just decide to leave mythfrontend on and stop the mac from sleeping.

One thing that came to mind is that mythfilldatabase is probably ran by the frontend, right? So we'll see how often it'll be updated if I only turn mythfrontend on while I watch. It used to work with my earlier linux set up (mythwelcome would turn the thing off once a recording is done and I would turn it off once I'm done watching) and I didn't seem to have any issues with mythfilldatabase not running often enough. But we'll see.
User avatar
pvr4me
Senior
Posts: 763
Joined: Fri Feb 07, 2014 7:25 pm
Location: near Toronto, Canada
Contact:
Canada

Re: how to wake/sleep macbook pro with mythtv

Post by pvr4me »

fra2015 wrote:...One thing that came to mind is that mythfilldatabase is probably ran by the frontend, right? So we'll see how often it'll be updated if I only turn mythfrontend on while I watch. It used to work with my earlier linux set up (mythwelcome would turn the thing off once a recording is done and I would turn it off once I'm done watching) and I didn't seem to have any issues with mythfilldatabase not running often enough. But we'll see.
Normally mythbackend kicks off mythfilldatabase. By default it uses the time suggested by SchedulesDirect but there are setting where you can change that behaviour. Some people do set up a cron job to run mfd at a time of their choosing--in such cases, mythbackend doesn't have to be running; just the database.

Otherwise, I'm glad you've got things working to your satisfaction.

Craig
Formerly the MacPorts guy.
MoisiePants
Junior
Posts: 54
Joined: Sat Jul 23, 2016 11:41 am
Great Britain

Re: how to wake/sleep macbook pro with mythtv

Post by MoisiePants »

fra2015 wrote:I ended up coding a small shell script that does what A says. Namely, it uses myth_upcoming_recordings.pl to pull the time of the next recording. Then it uses the date command to subtract 5 minutes from that time. Then it compares to the previously stored version (from a minute ago) and if there has been a change it resets the wake time using pmset.
Hello fra2015,

Would you mind sharing your script for this? It sounds exactly like what I want to achieve: I have Myth running on a iMac, and it kicks out quite a lot of heat - even when I'm doing nothing.

Thanks,

Pants.
Post Reply