Sleep timer?

If you have a question or need help, this is the place to be.
Post Reply
ssl-3
Posts: 4
Joined: Thu May 01, 2014 6:21 am

Sleep timer?

Post by ssl-3 » Thu May 01, 2014 6:56 am

So I was dozing off on my couch the other day listening to the sound of the electric meter spinning and watching a documentary, and thought: "Wouldn't it be great if I could just turn all this stuff off automatically?"

I thought about microcontrollers, I thought about old-school learning remotes with such functionality... And then, I realized I already have everything I need: A nearby low-power computer that is always on, an RS-232 port on my AVR, and a solid-state relay driven by the AVR that disconnects everything worth disconnecting. A quick Google later, and I found EventGhost. 20 minutes after that, I've scared up the correct cable and am issuing basic commands to the AVR over the network with remote desktop. I even had a lot of good luck playing with IR I/O with a random MCE box and an emitter -- I detect a sensible IR remote control for my PS3 in my future, courtesy in part of EventGhost, and maybe even some bug fixes for my picky AVR.

Awesome, and thanks to all who put this together.

But I'm having trouble getting a sleep timer to work. I made a macro with several 900 second sleep intervals (sleep for some time plugin) and an "off" command. This causes EventGhost to, itself, sleep -- in more than one way. A few minutes after executing this macro, EventGhost turns grey in Windows (7, x86) and is unresponsive. It never seems to wake up and issue the off command.

So. Newbie questions:

1. Am I doing it wrong / just not holding my teeth right?

2. Does the sleep plugin fail/crash/whatever for anyone else in a macro when given a long timespan? (It seems to be intended for relatively short delays.)

3. Is EventGhost multithreaded, at all? If I've got a macro (or a Python script, or whatever) waiting for eons in computer-years to do a command, is EventGhost able to process other events and actions? If not, what might be a suitable workaround? (Having discovered it, I have loftier goals for this software than just a simple sleep timer to be activated by whatever means.)

4. It just occurred to me that programmatically, I could have an event trigger an action that enables an time-of-day event that issues an action/macro to turn things off, where time-of-day is current+1.5 hours. This must work, and can't be difficult to code even for a non-programmer as myself, but it seems convoluted, unless 3 (above) is false and difficult to implement (likely, if it wasn't designed with that expectation from the beginning).

Anyhow, thanks for reading this far. I welcome all suggestions and criticism of all types.

ssl-3

kkl
Experienced User
Posts: 317
Joined: Wed May 04, 2011 9:32 pm

Re: Sleep timer?

Post by kkl » Thu May 01, 2014 3:48 pm

Timers in EG are confusing, at least to me. To answer one of your questions, the built-in "Wait some time" action does indeed cause EG to pause other functions while waiting, although events are cached. Let me point you to a couple of threads that might help:

Eventghost wait in minutes+hours?

SchedulGhost plug-in
SchedulGhost is particularly powerful. For your application, check out the Eggtimer functionality.

If you're still stumped after reviewing, ask again.

blaher
Experienced User
Posts: 487
Joined: Thu Nov 17, 2011 1:27 am

Re: Sleep timer?

Post by blaher » Sat May 03, 2014 1:10 am

This sleep timer: viewtopic.php?f=2&t=3447&p=29545&hilit=sleep#p29545? I use it for up to 3 hours quite a bit without issue.

ssl-3
Posts: 4
Joined: Thu May 01, 2014 6:21 am

Re: Sleep timer?

Post by ssl-3 » Mon May 05, 2014 2:21 am

Thanks, both of you, for the suggestions -- reading through all that got the wheels turning the right direction. Every situation is different, so for me (and for now) I wound up using SchedulGhost's Egg Timer functionality and five unique soft buttons on a screen in my Harmony to select a sleep timer of 30, 60, 90, 120 minutes, or cancel sleep altogether.

The macros are simple and repetitious, though it ought to be quite reliable. To schedule a sleep timer, I've got four macros:

Wait for a unique IR event (in my case, I'm using Sony TV codes for buttons 1, 2, 3, 4, since I don't have a Sony TV but do have a remote handy)
Abort all egg timers (can't find a way to abort a specific one), in case another sleep timer macro was recently triggered
Set an egg timer for 30, 60, 90, or 120 minutes depending on if 1, 2, 3, or 4 were received.

When the timer's up, it fires up another macro that simply fires an RS-232 command to my Lexicon receiver to turn off. Which, because of how I've got things wired, turns off everything worth turning off -- TV included. Problem solved! All without a single line of Python on my part.

If a Sony TV 5 event happens, it simply aborts all egg timers, and thus things will stay switched on indefinitely.


Thoughts, if anyone reading this can do anything about these:

It'd be awesome if SchedulGhost could do additive egg timers, wherein an event simply adds a prescribed amount of time to an existing egg timer, or creates it if it does not yet exist. (I think this would make more sense altogether than the existing implementation of egg timers, which stack in parallel even if they're named identically.) This would let my egg/sleep timer work, while also letting me use egg timers for other (totally different) functions, which is currently not possible.

It would also be awesome if SchedulGhost could selectively abort egg timers, and would make perfect sense. They're created and executed by name, and by extension it might make sense that they can be destroyed by name. (Other schedules already have this functionality, it seems.)

EventGhost's "Jump if double event" can work as a substitute for the macros I described above, but it can't ever be reliable on a system that might receive other events. "Jumps to another macro, if the same event that has triggered this macro, happens twice in a given time" is not even a very good description: If another, different event happens during that given time, it fails to jump -- even if the same event does happen within a given time. Even for my own, very simple, purposes, it doesn't work: My MCE IR dongle box frequently generates random events, especially when there is sunlight in the room or the fluorescent-backlit LCD is turned on, though it always does process actual IR commands correctly (I blame an over-bearing AGC circuit). (If "Jump if double event" behaved exactly as in its own description, I could have set up a single button on a remote to do a simple and reliable additive timer using a series of macros, even without explicit additive timer support from SchedulGhost or other similar plugins. But that doesn't work, because its behavior doesn't match -- AFAICT.)

Anyhow, thanks again. :)

User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Sleep timer?

Post by Pako » Mon May 05, 2014 9:33 am

Yes, I might make some changes in SchedulGhost plugin.
But I think it is unnecessary.
For sleep-timer function is as much better to use a script.
It is far more variable - you can set the timer steps completely arbitrarily.
I attach an example of a complete solution.
SleepTimer.png
Python Script:

Code: Select all

if hasattr(eg.globals, "mySleepTimer"):
    try:
        eg.scheduler.CancelTask(eg.globals.mySleepTimer)
    except:
        pass
sleepTime = eg.event.payload
if sleepTime != "Cancel":
    eg.globals.mySleepTimer = eg.scheduler.AddTask(60.0*int(sleepTime), eg.TriggerEvent, "SleepTime", prefix = "SleepTimer")
You only need to add an event to the macro Multitap: Key.

Pako
Attachments
SleepTimer.xml
(1.25 KiB) Downloaded 239 times

ssl-3
Posts: 4
Joined: Thu May 01, 2014 6:21 am

Re: Sleep timer?

Post by ssl-3 » Tue May 13, 2014 6:49 am

Pako -- thanks for the reply.

I was holding off on responding until I learned a bit more about Python and EG (I've hacked around with C and Perl before, but I'm certainly no programmer at such low levels -- even in such high-level languages).

And I really appreciate you posting the code that you did. I might give it a shot depending on how my whole EventGhost scenario plays out eventually, but having used the system for awhile, I think I actually like having dedicated buttons for sleep timers on a dedicated screen on my Harmony remote.

But still, I think Egg Timers should definitely be able to be aborted by name. I think it will make them much more useful: For instance, I have some old X10 gear kicking around. And since we're in-between seasons here, I have a box fan exhausting hot air in the evening, and it'd be awesome if I could tell it to turn off in a few hours based on my own interpretation of what the outside temperature will be (i never want to pull hotter air from outside to the inside). (And yes, this can of course be totally automated, but nevermind that for now.)

Egg timers seem ideal, but since the only abort function is universal, it seems that it must conflict with my sleep timer macros for my AV gear which, given current constraints, begin with killing all egg timers.

It seems like an easy thing to implement. If I spend another week or three on EG+Python, I can probably hammer it out myself, but you're obviously very skilled in the art and I'm certain you'd do a better, more workman-like job. :)

If this is done, egg timers will still stack in parallel. And it will be up to the end-user to decide if that is beneficial behavior or not, by either aborting them by name, or just letting them stack.

User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Sleep timer?

Post by Pako » Sat May 17, 2014 11:19 am

ssl-3 wrote:But still, I think Egg Timers should definitely be able to be aborted by name.
Well, I'll try it.
But I do not promise anything. It depends on how I will be satisfied with it.

Pako

Post Reply