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.

How to respond on power failure?

If you have a question or need help, this is the place to be.
Post Reply
waveking
Posts: 1
Joined: Sat Jun 05, 2010 4:11 am

How to respond on power failure?

Post by waveking »

Hi,
I am using USB UIRT to control my VLC player using EventGhost on my laptop.

I need that when my laptop goes into battery mode from Ac mode, then eventghost should pause VLC player, if it is running.
How can i achieve this?
stottle
Plugin Developer
Posts: 636
Joined: Sun Apr 26, 2009 10:59 pm

Re: How to respond on power failure?

Post by stottle »

I don't run from a laptop. I know EG posts several power messages, like idle/unidle. Does it generate any messages for switching the power mode? If so, just attach action to that event. Otherwise, it would be necessary to change the power plugin code to add that event....

Brett
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: How to respond on power failure?

Post by krambriw »

Currently you only get "POWERSTATUSCHANGE" events when switching between battery/line back and forth

To find out if running on batteries (or mains) a plugin or eg itself would need to dig "deeper" calling GetSystemPowerStatus and checking the SYSTEM_POWER_STATUS structure

Code: Select all

typedef struct _SYSTEM_POWER_STATUS {
  BYTE  ACLineStatus;
  BYTE  BatteryFlag;
  BYTE  BatteryLifePercent;
  BYTE  Reserved1;
  DWORD BatteryLifeTime;
  DWORD BatteryFullLifeTime;
} SYSTEM_POWER_STATUS, *LPSYSTEM_POWER_STATUS;
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: How to respond on power failure?

Post by krambriw »

I just elaborated a bit and found that this simple script will generate an event when changing from AC to Battery and vice versa. Below is also a picture showing my configuration. You just have to create a macro with a python script and copy the code below. Then you add the system event "System.PowerStatusChange" as I did

You can then use the "Main.Energy.Source.Battery" event to control another macro to pause VLC

Best regards, Walter

Code: Select all

import ctypes
import ctypes.wintypes

class SYSTEM_POWER_STATUS(ctypes.Structure):
   _fields_ = [("ACLineStatus", ctypes.c_byte), ("BatteryFlag", ctypes.c_byte), ("BatteryLifePercent", ctypes.c_byte), ("Reserved1", ctypes.c_byte), ("BatteryLifeTime", ctypes.wintypes.DWORD), ("BatteryFullLiveTime", ctypes.wintypes.DWORD)]

sps = SYSTEM_POWER_STATUS()
ctypes.windll.kernel32.GetSystemPowerStatus(ctypes.byref(sps))

status_constants = ["", "High", "Low", "Critical", "Charging", "No system battery", "Unknown"]
ac_constants = ["Battery", "AC Power", "Unknown"]
hours, rest = divmod(sps.BatteryLifeTime , 3600)
minutes, seconds = divmod(rest, 60)

#print "Battery charge status:", status_constants[sps.BatteryFlag]
#print "Energy source:", ac_constants[sps.ACLineStatus]
#print "Battery life percentage: %s%%" % sps.BatteryLifePercent
#print "Estimated remaining time: %s:%s:%s" % (hours, minutes, seconds)

eg.TriggerEvent("Energy.Source."+ac_constants[sps.ACLineStatus])
Image1.jpg
Post Reply