Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

SleepTimer like on TV

If you have a question or need help, this is the place to be.
User avatar
wakko
Posts: 33
Joined: Sat Aug 20, 2011 9:27 pm
Location: Russia, Siberia

SleepTimer like on TV

Post by wakko »

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 < 5 :\n    StartReRunTimers(5)\nelif eg.globals.SleepTimerValue < 10 :\n    StartReRunTimers(10)\nelif eg.globals.SleepTimerValue < 15 :\n    StartReRunTimers(15)\nelif eg.globals.SleepTimerValue < 20 :\n    StartReRunTimers(20)\nelif eg.globals.SleepTimerValue < 25 :\n    StartReRunTimers(25)\nelif eg.globals.SleepTimerValue < 30 :\n    StartReRunTimers(30)\nelif eg.globals.SleepTimerValue < 35 :\n    StartReRunTimers(35)\nelif eg.globals.SleepTimerValue < 40 :\n    StartReRunTimers(40)\nelif eg.globals.SleepTimerValue < 45 :\n    StartReRunTimers(45)\nelif eg.globals.SleepTimerValue < 50 :\n    StartReRunTimers(50)\nelif eg.globals.SleepTimerValue < 55 :\n    StartReRunTimers(55)\nelif eg.globals.SleepTimerValue < 60 :\n    StartReRunTimers(60)\nelif eg.globals.SleepTimerValue < 65 :\n    StartReRunTimers(65)\nelif eg.globals.SleepTimerValue < 70 :\n    StartReRunTimers(70)\nelif eg.globals.SleepTimerValue < 75 :\n    StartReRunTimers(75)\nelif eg.globals.SleepTimerValue < 80 :\n    StartReRunTimers(80)\nelif eg.globals.SleepTimerValue < 85 :\n    StartReRunTimers(85)\nelif eg.globals.SleepTimerValue < 90 :\n    StartReRunTimers(90)\nelif eg.globals.SleepTimerValue < 95 :\n    StartReRunTimers(95)\nelif eg.globals.SleepTimerValue < 100 :\n    StartReRunTimers(100)\nelif eg.globals.SleepTimerValue < 105 :\n    StartReRunTimers(105)\nelif eg.globals.SleepTimerValue < 110 :\n    StartReRunTimers(110)\nelif eg.globals.SleepTimerValue < 115 :\n    StartReRunTimers(115)\nelif eg.globals.SleepTimerValue < 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
InterlinkKnight
Posts: 29
Joined: Mon Sep 13, 2010 1:17 am
Contact:

Re: SleepTimer like on TV

Post by InterlinkKnight »

I get this error when i open the configuration file:
error
error
i try several combinations of pleasing the code in the configuration file.
User avatar
InterlinkKnight
Posts: 29
Joined: Mon Sep 13, 2010 1:17 am
Contact:

Re: SleepTimer like on TV

Post by InterlinkKnight »

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
wakko
Posts: 33
Joined: Sat Aug 20, 2011 9:27 pm
Location: Russia, Siberia

Re: SleepTimer like on TV

Post by wakko »

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
Allington
Posts: 1
Joined: Thu Dec 01, 2011 11:45 am
Location: USA
Contact:

Re: SleepTimer like on TV

Post by Allington »

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.
blaher
Experienced User
Posts: 487
Joined: Thu Nov 17, 2011 1:27 am

Re: SleepTimer like on TV

Post by blaher »

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.
phlox
Plugin Developer
Posts: 90
Joined: Wed Jan 11, 2012 3:49 pm

Re: SleepTimer like on TV

Post by phlox »

@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
User avatar
wakko
Posts: 33
Joined: Sat Aug 20, 2011 9:27 pm
Location: Russia, Siberia

Re: SleepTimer like on TV

Post by wakko »

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.
Zhan
Posts: 5
Joined: Sat Jan 11, 2014 12:49 pm

Re: SleepTimer like on TV

Post by Zhan »

Hi,

I try to run this script but I get this errors in the log window:
  • Begin
    Show OSD: Sleep Timer {eg.globals.SleepTimerValue}
    Error in Action: "Show OSD: Sleep Timer {eg.globals.SleepTimerValue}"
    Traceback (most recent call last) (1630):
    File "C:\Program Files (x86)\EventGhost\eg\Classes\ActionBase.py", line 170, in CallWrapper
    return self(*args)
    File "C:\Program Files (x86)\EventGhost\plugins\EventGhost\ShowOSD.py", line 385, in __call__
    osdText = eg.ParseString(osdText)
    File "C:\Program Files (x86)\EventGhost\eg\Utils.py", line 204, in ParseString
    res = eval(word, {}, eg.globals.__dict__)
    File "<string>", line 1, in <module>
    AttributeError: 'Bunch' object has no attribute 'SleepTimerValue'
    If event arrives twice, go to: ProcessingSleepTimer
What did I do wrong?
User avatar
wakko
Posts: 33
Joined: Sat Aug 20, 2011 9:27 pm
Location: Russia, Siberia

Re: SleepTimer like on TV

Post by wakko »

Hi Zhan,

Have you added to configuration autostart section a python script with following values?
(Sorry for delay with reply, i'm not often visit to forum.)

Code: Select all

eg.globals.SleepTimerValue = 0
eg.globals.SleepTimerActive = 0
eg.globals.SleepTimerActiveGoodNight = 0
Zhan
Posts: 5
Joined: Sat Jan 11, 2014 12:49 pm

Re: SleepTimer like on TV

Post by Zhan »

Hi,

Thanks wakko for your reply. I added these lines and my autostart section looks like this:

Code: Select all

 <Autostart Name="Autostart" Expanded="True">
        <Plugin Identifier="HID" Guid="{05A690D9-27C2-4AC5-B0DD-2F562619E922}" File="HID">
            gAIoWAAAAABxAImIiVVSXFw/XGhpZCN2aWRfMDQ4MyZwaWRfMDAzNSM3JjM1MmI1ZjczJjAmMDAwMCN7NGQxZTU1YjItZjE2Zi0xMWNmLTg4Y2ItMDAxMTExMDAwMDMwfXEBTYMEWA0AAABFTE1BSyBSemVzem93cQJLNVgSAAAAUEMgTUFLIElSIFJlY2VpdmVycQNNFgGJS2N0cQQu
        </Plugin>
        <Plugin Identifier="DVBViewer" Guid="{747B54F6-59F6-4602-A777-984EA76D2D8C}" File="DVBViewer">
            gAIoiYmIiVguAAAAQzpcUHJvZ3JhbSBGaWxlcyAoeDg2KVxEVkJWaWV3ZXJcZHZidmlld2VyLmV4ZXEAWAAAAABxAYiJiImJSzxYDgAAAFN0YXJ0UmVjb3JkaW5ncQJYDgAAAFN0YXJ0UmVjb3JkaW5ncQNLA4mJSwVYDgAAADEyNy4wLjAuMTo4MDg5cQRYEAAAAERWQlZpZXdlclNlcnZpY2VxBYl0cQYu
        </Plugin>
        <Plugin Enabled="False" Identifier="Keyboard" Guid="{59CBD10F-C1D8-4ADB-999B-9B76BA360F1F}" File="Keyboard">
            gAKIhXEALg==
        </Plugin>
        <Plugin Identifier="Timer" Guid="{6149CA99-1FCD-4450-9160-7543BC20CFD3}" File="Timer">
            gAIpLg==
        </Plugin>
        <Plugin Identifier="OSM" Guid="{FCF3C7A7-FBC1-444D-B768-9477521946DC}" File="OSM">
            gAIpLg==
        </Plugin>
eg.globals.SleepTimerValue = 0
eg.globals.SleepTimerActive = 0
eg.globals.SleepTimerActiveGoodNight = 0
    </Autostart>
but I just realized that these three lines disappear every time when I click save in EventGhost window. Anyway even if they are in autostart the sleep time function doesn't work.
User avatar
wakko
Posts: 33
Joined: Sat Aug 20, 2011 9:27 pm
Location: Russia, Siberia

Re: SleepTimer like on TV

Post by wakko »

Hi Zhan,

No no no. You have to add to autostart section a python script. And inside that script you have to add those 3 lines.
After that, you should save your config and restart EventGhost.

This is just a definition for variables for SleepTimer script. If they are missing, then SleepTimer will not work.

You can copy and paste that code to your autostart section from my working config:

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="1534">
    <Action Name="Python ScriptForSleepTimer">
        EventGhost.PythonScript(u'eg.globals.SleepTimerValue = 0\neg.globals.SleepTimerActive = 0\neg.globals.SleepTimerActiveGoodNight = 0')
    </Action>
</EventGhost>
Zhan
Posts: 5
Joined: Sat Jan 11, 2014 12:49 pm

Re: SleepTimer like on TV

Post by Zhan »

Thanks a lot wakko, now it's working almost perfect. Almost because the osd messages are displayed on my second screen even if DVBViewer is on first (primary) screen. And one more thing, how I can replace "Sleep Timer 0" message to "Sleep Timer off"?
Zhan
Posts: 5
Joined: Sat Jan 11, 2014 12:49 pm

Re: SleepTimer like on TV

Post by Zhan »

Ok, I found the OSD monitor settings but now I have another problem. I must press the key on my remote very quickly, about 3-4 per second, otherwise the script does not respond. I mean the minuts are displayed but do not change. Or maybe it's normal?
User avatar
wakko
Posts: 33
Joined: Sat Aug 20, 2011 9:27 pm
Location: Russia, Siberia

Re: SleepTimer like on TV

Post by wakko »

It is not impossible to display "Sleep Timer off" instead of "Sleep Timer 0". But it requires some reprogramming of the script.

About your second question.
Single press of remote's key should just display current value of SleepTimer. Additional key pressing with pause between each press no more then 2 seconds should increment current SleepTimer value.

Script does not required such quick repetitive pressing of remote's key. So something going wrong.
Check the value in "begin" macro, in "If event arrives twice, go to: ProcessingSleepTimer" action. It should be 2 seconds.
Last edited by wakko on Mon Jan 27, 2014 6:05 am, edited 1 time in total.
Post Reply