Exit away mode (1 Viewer)

Vasilich

Portal Pro
August 30, 2009
3,392
1,173
Germany, Mayence
Home Country
Russian Federation Russian Federation
I am using mp 1.2 on W7, and i like the feature it supports - away mode. Though i still can't figure out how to exit away mode from remote? e.g. i pressed power button on my remote while recording goes on, and HTPC went to away mode. 2 minutes later i decided to watch movie. And imagine what i do when see black screen on my TV? right, press power button again. But nothing happens. So only way for me to exit away mode is to connect keyboard or mouse and press a key/move mouse. I hope there should be a way to exit away mode with my remote. I use X10 remote with special drivers without HID support (as suggested on X10 configuration page in MP Config).

can anyone give me any advice where to show at? is exit away mode supported by MP?
 

Marcus Venturi

MP Donator
  • Premium Supporter
  • March 23, 2012
    614
    745
    58
    Home Country
    Germany Germany
    Thank you for the fast response.

    In my custom made media center I have an integrated 2x100W digital amplifier with speakers directly connected, which would mean, that if a programm is recorded without away mode, the sound would play - even in the middle of the night. I think my wife would kill me if that happens...
    So for the first I have to live with that limitation.
     

    Marcus Venturi

    MP Donator
  • Premium Supporter
  • March 23, 2012
    614
    745
    58
    Home Country
    Germany Germany
    Hi Vasilich,

    The problem is caused by the way, the Away-Mode is handled within Mediaportal. At the moment I see no internal workarround for this problem, because it would require to alter the power management interaction between the mediaportal server and the client (if both are running on the same machine).

    From the Microsoft documentation I saw, that the Away-Mode remains active until a HID-device (Keyboard or Mouse) sends an event. In this case the system wakes up. As the remote is not handled as HID-device we both have the problem that the system remains in Away-Mode.

    The only other way to temporary quit the Away-Mode is, that any other thread in the system set it's execution state in a special way.
    See Microsoft documentation for details: http://msdn.microsoft.com/en-us/library/windows/desktop/aa373208(v=vs.85).aspx

    So in our case this thread would have to set the execution state to ES_CONTINUOUS, ES_DISPLAY_REQUIRED and ES_SYSTEM_REQUIRED.

    As I control my MediaPortal with Eventghost and Lirc I tried to add 2 commands to switch the execution state of Eventghost between the above state and back to the normal state.

    I added 2 new Commands to Eventghost in form of a Python script:

    This command forces the PC to leave the Away-Mode:
    eg.WinApi.Dynamic.SetThreadExecutionState(0x800000003);

    This command allows the PC to go back to Away-Mode:
    eg.WinApi.Dynamic.SetThreadExecutionState(0x800000000);

    I did a quick test this evening, started a recording and turned MediaPortal off, which forces it to go in Away-Mode. Afterwards I was able to wake it up with a button on the remote that was mapped to the first above command. Screen was on and sound was available. :)

    This solution is not very clean at the moment, but it's a workarround.

    Best solution would be a plugin within MediaPortal that would do this job.
     
    Last edited:

    Marcus Venturi

    MP Donator
  • Premium Supporter
  • March 23, 2012
    614
    745
    58
    Home Country
    Germany Germany
    Hi again,

    yesterday I took some time and implemented a solution for that problem. I solved it by a combination of a small program and EventGhost.

    First unzip the attached file and put it somewhere on your harddisk:

    For my example it's in:

    C:\Program Files (x86)\AwayModeHelper\AwayModeHelper.exe

    Then you must add the follwing Action to the Autostart group of EventGhost which starts that program with EventGhost.

    XML:
    <Action>
    System.Execute(u'C:\\Program Files (x86)\\AwayModeHelper\\AwayModeHelper.exe', u'', 0, False, 2, u'', False)
    </Action>

    Then you must add a Macro that on the power key of your remote. In my case I listen to "Lirc.Power" event. In this event you start the same program again. I will explain this later.

    XML:
    <Macro Name="RemoteOnOff" Expanded="True">
    <Event Name="Lirc.Power" />
    <Action>
      System.Execute(u'C:\\Program Files (x86)\\AwayModeHelper\\AwayModeHelper.exe', u'', 0, False, 2, u'', False)
    </Action>
    </Macro>

    Then you need to Macros that react on 2 special Events:

    XML:
    <Macro Name="Resume" Expanded="True">
    <Event Name="Main.AwayMode.Resume" />
    <Action>
      System.MuteOff(0)
    </Action>
    <Action>
      MediaPortal.Start()
    </Action>
    </Macro>
     
    <Macro Name="Standby" Expanded="True">
    <Event Name="Main.AwayMode.Suspend" />
    <Action>
      System.Standby(False)
    </Action>
    </Macro>

    How does it work?

    If AwayModeHelper.exe is started the first time, it checks if EventGhost ist running, if not it shows a Message and quits.
    Therefore must be started from the Autostart in EventGost. If started from EventGhost it stays in Memory until EventGhost is closed.

    It registers itself for power event notifications. If a second instance is started it checks if there is already an instance running and asks this instance for the current power state.

    If the system is in away mode the instance creates a low level keyboard event, which forces the system to wake up from Away Mode and sends a "Main.AwayMode.Resume" event to EventGhost. EventGhost has a handler for this event (see above) which turns the mute of the sound off.

    If the system is not in away mode the second instance sends a "Main.AwayMode.Suspend" event to EventGhost.
    In the event handler for this event EventGhost brings the system into Standby or back into Away Mode (if still active).

    All this could have also be done within EventGhost, but as I'm not so familiar with Python, it was easier to do it in small C++ program, because this has less memory footprint than a C# solution.
     

    Attachments

    • AwayModeHelper.zip
      11.6 KB
    Last edited by a moderator:

    Marcus Venturi

    MP Donator
  • Premium Supporter
  • March 23, 2012
    614
    745
    58
    Home Country
    Germany Germany
    Did work,
    but had one small Problem. If I left the TV that was woken up from away mode, without turning it off it didn't go back to sleep after the recording was finished. In that case I had to do it with the remote, because the modified thread execution state prevented it from doing so. Only turning it off with the remote set the thread execution state back.
    For sure that was only a small problem, but I wanted a solution that works 100%.
     

    wawa79

    Portal Pro
    December 9, 2008
    111
    28
    Niort
    Home Country
    France France
    Hello, I was really concerned by this issue for years! Your explanations here let me understand the Win 7 logic about away-mode!
    To exit the 'away-mode', Win 7 needs activity from a HID-compliant device.
    I just noticed Windows exits away-mode when connecting my Htpc from Ultra-VNC (so without HID hardware) so there should be a way to emulate it.

    I started looking for a way to trigger such a low-level keyboard keypress: I found that Python piece of code to include as an Eventghost Python script action:
    http://noabsolutetruths.com/2010/05/19/keyboard-event-generation-in-eventghost
    Just add at the end outputtext("f") to simulate a clik on key "F" of the keyboard. Make this action triggered by the remote command that starts MP and that's it!

    No more blank screen or missing audio on resume, no more CPU left in power-saving mode and reduce performance. Yeahh!

    Thank you and I hope this helps also!
     

    Users who are viewing this thread

    Top Bottom