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
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>
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.