SleepTimer like on TV

If you have a question or need help, this is the place to be.

SleepTimer like on TV

Postby wakko » Sun Sep 18, 2011 7:50 pm

Hello.
I don't know, where to place my post, so decided to post it here.

I want to share my "Sleep Timer" solution.
It may looks ugly in the professional's eyes (becouse i'm not a programmer), but it works ok and as expected.
It's imitates behaviour of my TV's "Sleep Timer" button, except, what i've added 5 minutes step for setting up Sleep Timer instead of TV's 10 minutes step.
My solution is based on a Timer plugin.
First of all, you will need to add a Timer plugin. Then, you need to add a python script to the autostart section of your EventGhost configuration file with following content:
Code: Select all
eg.globals.SleepTimerValue = 0
eg.globals.SleepTimerActive = 0
eg.globals.SleepTimerActiveGoodNight = 0

It's just declares and setting up the 3 global variables.
After that, copy following code to your EventGhost config file:
Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1534">
    <Folder Name="SleepTimer" Expanded="True">
        <Macro Name="Begin" id="632" Expanded="True">
            <Event Name="Lirc.Sleep" />
            <Action>
                EventGhost.ShowOSD(u'Sleep Timer {eg.globals.SleepTimerValue}', u'0;-64;0;0;0;700;0;0;0;204;3;2;1;34;Arial', (255, 0, 0), (0, 0, 0), 4, (0, 0), 0, 2.0, True)
            </Action>
            <Action>
                EventGhost.JumpIfDoubleEvent(2.0, XmlIdLink(637))
            </Action>
        </Macro>
        <Folder Name="ProcessingSleepTimer" Expanded="True">
            <Macro Name="ProcessingSleepTimer" id="637" Expanded="True">
                <Action Name="ScriptToProcessingSleepTimer">
                    EventGhost.PythonScript(u"def SleepTimerSet():\n    eg.TriggerEvent(u'StopTicTac')\n    eg.globals.SleepTimerValue = 0\n    eg.globals.SleepTimerActive = 0\n    eg.TriggerEvent(u'TimeToSleep')\n\ndef SleepTimerGoodNightSet():\n    eg.globals.SleepTimerActiveGoodNight = 0\n    eg.TriggerEvent(u'GoodNight')\n    \nif eg.globals.SleepTimerActive == 1 :\n    eg.scheduler.CancelTask(eg.globals.SleepTimer)\n    eg.globals.SleepTimerActive = 0\n\nif eg.globals.SleepTimerActiveGoodNight == 1 :\n    eg.scheduler.CancelTask(eg.globals.SleepTimerGoodNight)\n    eg.globals.SleepTimerActiveGoodNight = 0\n\nTimeUnit = 60\n\ndef StartReRunTimers (TimerTimeUnit):\n    eg.TriggerEvent(u'StartTicTac')\n    eg.globals.SleepTimerValue = TimerTimeUnit\n    eg.globals.SleepTimer = eg.scheduler.AddTask(eg.globals.SleepTimerValue * TimeUnit, SleepTimerSet)\n    eg.globals.SleepTimerGoodNight = eg.scheduler.AddTask((eg.globals.SleepTimerValue * TimeUnit) - TimeUnit, SleepTimerGoodNightSet)\n    eg.globals.SleepTimerActive = 1\n    eg.globals.SleepTimerActiveGoodNight = 1\n\nif eg.globals.SleepTimerValue == 120 :\n    eg.TriggerEvent(u'StopTicTac')\n    eg.globals.SleepTimerValue = 0\nelif eg.globals.SleepTimerValue &lt; 5 :\n    StartReRunTimers(5)\nelif eg.globals.SleepTimerValue &lt; 10 :\n    StartReRunTimers(10)\nelif eg.globals.SleepTimerValue &lt; 15 :\n    StartReRunTimers(15)\nelif eg.globals.SleepTimerValue &lt; 20 :\n    StartReRunTimers(20)\nelif eg.globals.SleepTimerValue &lt; 25 :\n    StartReRunTimers(25)\nelif eg.globals.SleepTimerValue &lt; 30 :\n    StartReRunTimers(30)\nelif eg.globals.SleepTimerValue &lt; 35 :\n    StartReRunTimers(35)\nelif eg.globals.SleepTimerValue &lt; 40 :\n    StartReRunTimers(40)\nelif eg.globals.SleepTimerValue &lt; 45 :\n    StartReRunTimers(45)\nelif eg.globals.SleepTimerValue &lt; 50 :\n    StartReRunTimers(50)\nelif eg.globals.SleepTimerValue &lt; 55 :\n    StartReRunTimers(55)\nelif eg.globals.SleepTimerValue &lt; 60 :\n    StartReRunTimers(60)\nelif eg.globals.SleepTimerValue &lt; 65 :\n    StartReRunTimers(65)\nelif eg.globals.SleepTimerValue &lt; 70 :\n    StartReRunTimers(70)\nelif eg.globals.SleepTimerValue &lt; 75 :\n    StartReRunTimers(75)\nelif eg.globals.SleepTimerValue &lt; 80 :\n    StartReRunTimers(80)\nelif eg.globals.SleepTimerValue &lt; 85 :\n    StartReRunTimers(85)\nelif eg.globals.SleepTimerValue &lt; 90 :\n    StartReRunTimers(90)\nelif eg.globals.SleepTimerValue &lt; 95 :\n    StartReRunTimers(95)\nelif eg.globals.SleepTimerValue &lt; 100 :\n    StartReRunTimers(100)\nelif eg.globals.SleepTimerValue &lt; 105 :\n    StartReRunTimers(105)\nelif eg.globals.SleepTimerValue &lt; 110 :\n    StartReRunTimers(110)\nelif eg.globals.SleepTimerValue &lt; 115 :\n    StartReRunTimers(115)\nelif eg.globals.SleepTimerValue &lt; 120 :\n    StartReRunTimers(120)")
                </Action>
                <Action>
                    EventGhost.NewJumpIf(XmlIdLink(632), 2, False)
                </Action>
            </Macro>
        </Folder>
        <Folder Name="TicTac" Expanded="True">
            <Macro Name="TicTacStart" Expanded="True">
                <Event Name="Main.StartTicTac" />
                <Action>
                    Timer.TimerAction(u'TicTac', 0, 0, 60.0, u'TicTac', False, False, 1, u'00:00:00')
                </Action>
            </Macro>
            <Macro Name="TicTacStop" Expanded="True">
                <Event Name="Main.StopTicTac" />
                <Action>
                    Timer.TimerAction(u'TicTac', 4, 0, 1.0, u'TicTac', False, False, 0, u'00:00:00')
                </Action>
            </Macro>
        </Folder>
        <Folder Name="ReduceEgGlobalsSleepTimerValue" Expanded="True">
            <Macro Name="ReduceEgGlobalsSleepTimerValue" Expanded="True">
                <Event Name="Timer.TicTac" />
                <Action Name="ScriptToReduceEgGlobalsSleepTimerValue">
                    EventGhost.PythonScript(u'if eg.globals.SleepTimerValue != 0 :\n    eg.globals.SleepTimerValue = eg.globals.SleepTimerValue - 1')
                </Action>
            </Macro>
        </Folder>
        <Folder Name="Final" Expanded="True">
            <Macro Name="FinalGoodNight" Expanded="True">
                <Event Name="Main.GoodNight" />
                <Action>
                    EventGhost.ShowOSD(u'Good night!', u'0;-64;0;0;0;700;0;0;0;204;3;2;1;34;Arial', (0, 255, 0), (0, 0, 0), 4, (0, 0), 0, 0.0, True)
                </Action>
            </Macro>
            <Macro Name="FinalSleepTimer" Expanded="True">
                <Event Name="Main.TimeToSleep" />
                <Action>
                    EventGhost.ShowOSD(u'Turning off', u'0;-64;0;0;0;700;0;0;0;204;3;2;1;34;Arial', (255, 0, 0), (0, 0, 0), 4, (0, 0), 0, 0.0, True)
                </Action>
                <Action>
                    System.PowerDown(True)
                </Action>
            </Macro>
        </Folder>
    </Folder>
</EventGhost>

Note, that i'm using Lirc.Sleep event (sleep button on my IR remote) to control Sleep Timer. In your case you will need to redefine it to whatever button of your IR remote.
How to test sleep timer:
To setup sleep timer you need to press defined sleep button on your remote several times, with pause between each press no more that 2 seconds, until desired value will be displayed.
To display, how much time left, press defined button one time.
To switch off sleep timer you need to make a full circle with pressing form 5 to 120 minutes, until value of 0 will be displayed.
To extend timer just press defined button several times, until desired value.

I hope it will be useful for somebody.
User avatar
wakko
 
Posts: 25
Joined: Sat Aug 20, 2011 9:27 pm
Location: Russia, Siberia

Re: SleepTimer like on TV

Postby InterlinkKnight » Sun Jan 15, 2012 11:42 pm

I get this error when i open the configuration file:

ScreenShot - 2012-01-15 - 19.06.26 - 001.jpg
error


i try several combinations of pleasing the code in the configuration file.
User avatar
InterlinkKnight
 
Posts: 28
Joined: Mon Sep 13, 2010 1:17 am

Re: SleepTimer like on TV

Postby InterlinkKnight » Mon Jan 16, 2012 2:21 am

nevermind the last error. was that i forget to open the timer plugin.

I think is great, but how i change the sequence? I want to be 15 minutes, 30, 45, 60, 90, 120
User avatar
InterlinkKnight
 
Posts: 28
Joined: Mon Sep 13, 2010 1:17 am

Re: SleepTimer like on TV

Postby wakko » Sat Jan 21, 2012 12:31 pm

Hi,

You have to comment out redundant for you strings in "ScriptToProcessingSleepTimer" script .
Like: leave both strings with value of 15 and comment out both strings with values of 5 and then 10 above that string.
Comment out (or delete them, if you wish) both strings with values 20 and 25 below the strings with value of 15. And so on.
Thank you for feedback.
User avatar
wakko
 
Posts: 25
Joined: Sat Aug 20, 2011 9:27 pm
Location: Russia, Siberia

Re: SleepTimer like on TV

Postby Allington » Mon Feb 13, 2012 10:33 am

Well, your shared step by step information relating to sleeping timer is nice and I would like to follow these instructions in next week to set up timer on TV.Thanks for sharing such a valuable information with us.
User avatar
Allington
 
Posts: 1
Joined: Thu Dec 01, 2011 11:45 am
Location: USA

Re: SleepTimer like on TV

Postby blaher » Tue Feb 14, 2012 3:47 am

wakko wrote:I hope it will be useful for somebody.

It sure is, thanks very much! I edited out the lines like you suggested above, and now my PC goes to sleep at intervals of 15, 30, 45..3 hours. I had to autohide your last comment of 'Turning Off', because I triggered a Standby, instead of Off, and the message was still there when it resumed. :) Other than that it works really well.

I'm surprised there isn't more demand for a sleep timer type plugin. Cheers.
blaher
Experienced User
 
Posts: 151
Joined: Thu Nov 17, 2011 1:27 am

Re: SleepTimer like on TV

Postby phlox » Thu Jan 10, 2013 9:18 pm

@wakko - nice script, I like it :)

Another user asked me if it's possible to show the timer values on an iMON display (that's a VFD or LCD display available for HTPC cases) - if someone else is interested, here's the modified config
phlox
Plugin Developer
 
Posts: 89
Joined: Wed Jan 11, 2012 3:49 pm

Re: SleepTimer like on TV

Postby wakko » Fri Jan 11, 2013 4:24 pm

phlox wrote:@wakko - nice script, I like it :)

Thank you :)
I'm also thought about script improvement by doing additional maths with variables. Your changes makes script really smaller and more nicer.
But i stopped myself, because in that case it's become too difficult to set up any desired increment value on any number of step. Like: 10, 25, 35, 40.
Glad to see, what people use it.
User avatar
wakko
 
Posts: 25
Joined: Sat Aug 20, 2011 9:27 pm
Location: Russia, Siberia


Return to General Support

Who is online

Users browsing this forum: Bing [Bot] and 3 guests