Monitor Computer Power

Discussion and support for individual OSA plugins
Message
Author
Automate
Posts: 1691
Joined: Sat Dec 11, 2010 1:44 pm
Location: US

Monitor Computer Power

#1 Post by Automate » Wed Jan 12, 2011 3:43 pm

OK, my first plugin. Nothing fancy, it just monitors your computer power/battery. Requires a laptop with a battery or a UPS that reports its status back to Windows.

What can it be used for? Sending a text message or e-mail to you when you loose power to your computer/house. Or, if you have equipment other than your computer supplied by your UPS you could write a script to shutdown the non-essential equipment as the UPS battery level gets low. Also, when OSA gets a web interface you will be able to monitor UPS power and remaining runtime remotely.

I have only tried it on a laptop with Win XP. It was compiled for the unreleased 0.2 version from SVN so if Brian, Vaughn or anybody else running 0.2 could test it for me it would be appreciated.

Automate

Edit: Latest version is on the plugins page
Last edited by Automate on Sat Oct 29, 2011 4:26 am, edited 2 times in total.

User avatar
bwoodworth
Site Admin
Posts: 1563
Joined: Tue May 04, 2010 6:49 am
Location: California

Re: Monitor Computer Power

#2 Post by bwoodworth » Wed Jan 12, 2011 3:54 pm

This sounds great! I will test it right away. I will give you permission to upload it to the plugin manager so when we release 0.2.0 you can upload it there.
Brian

User avatar
bwoodworth
Site Admin
Posts: 1563
Joined: Tue May 04, 2010 6:49 am
Location: California

Re: Monitor Computer Power

#3 Post by bwoodworth » Wed Jan 12, 2011 4:15 pm

First up, it installed flawlessly and loaded up perfectly when I started the service so great job with packaging it up.

As far as I can tell it is working, but I'm not sure what I should be looking for. (I haven't been able to test fully since I am RDP'ing to my dev machine so I can't unplug it). I am assuming that the PowerRestored and PowerLost events get triggered when the respective power event happens. I will test this more when I get home in a couple hours.

Couple suggestions, neither of which are necessary:

- I might add a 'Computer Name' property to your object type. What this does is allow there to be multiple instances of the plugin on different machines. Plugin objects that don't have this property are considered unique and will only run on one machine. With this type pf plugin you may want to be able to monitor the power status of every machine running OSA.

- Add a property to store the current power status. Then the user can display this in the GUI is they want to be able to readily see the power status of their machine.

Like I said, those suggestions are minor and probably, just my taste. Overall great job and thanks for being our first developer!
Brian

Automate
Posts: 1691
Joined: Sat Dec 11, 2010 1:44 pm
Location: US

Re: Monitor Computer Power

#4 Post by Automate » Wed Jan 12, 2011 4:25 pm

Maybe I don't understand how the installer works. I should have included an install.sql which includes the following.

CALL osae_sp_object_type_add ('COMPUTER POWER','Computer Power Monitor Plugin','','PLUGIN',1,0,0,1);
CALL osae_sp_object_type_state_add ('ON','Running','COMPUTER POWER');
CALL osae_sp_object_type_state_add ('OFF','Stopped','COMPUTER POWER');
CALL osae_sp_object_type_event_add ('ON','Started','COMPUTER POWER');
CALL osae_sp_object_type_event_add ('OFF','Stopped','COMPUTER POWER');
CALL osae_sp_object_type_event_add ('PowerLost','PowerLost','COMPUTER POWER');
CALL osae_sp_object_type_event_add ('PowerRestored','PowerRestored','COMPUTER POWER');
CALL osae_sp_object_type_method_add ('ON','Start','COMPUTER POWER','','','','');
CALL osae_sp_object_type_method_add ('OFF','Stop','COMPUTER POWER','','','','');
CALL osae_sp_object_type_method_add ('UPDATE','Update','COMPUTER POWER','','','','');
CALL osae_sp_object_type_property_add ('Update Interval','String','COMPUTER POWER',0);
CALL osae_sp_object_type_property_add ('Computer Name','String','COMPUTER POWER',0);
CALL osae_sp_object_type_property_add ('PowerLineStatus','String','COMPUTER POWER',0);
CALL osae_sp_object_type_property_add ('BatteryChargeStatus','String','COMPUTER POWER',0);
CALL osae_sp_object_type_property_add ('BatteryFullLifeTime','String','COMPUTER POWER',0);
CALL osae_sp_object_type_property_add ('BatteryLifePercent','String','COMPUTER POWER',0);
CALL osae_sp_object_type_property_add ('BatteryLifeRemaining','String','COMPUTER POWER',0);

As you can see it has the properties you are talking about. Also, when I run it, the computer name is appended to the plugin name.

User avatar
bwoodworth
Site Admin
Posts: 1563
Joined: Tue May 04, 2010 6:49 am
Location: California

Re: Monitor Computer Power

#5 Post by bwoodworth » Wed Jan 12, 2011 4:34 pm

Ah yes, I see that you have all those properties already.

Looks like Vaughn forgot to update the export function for object types with his most recent update. There is a new parameter in the object_type_property_add routine for default values. This new parameter should be third. Here is your script with it updated:

Code: Select all

CALL osae_sp_object_type_add ('COMPUTER POWER','Computer Power Monitor Plugin','','PLUGIN',1,0,0,1);
CALL osae_sp_object_type_state_add ('ON','Running','COMPUTER POWER');
CALL osae_sp_object_type_state_add ('OFF','Stopped','COMPUTER POWER');
CALL osae_sp_object_type_event_add ('ON','Started','COMPUTER POWER');
CALL osae_sp_object_type_event_add ('OFF','Stopped','COMPUTER POWER');
CALL osae_sp_object_type_event_add ('PowerLost','PowerLost','COMPUTER POWER');
CALL osae_sp_object_type_event_add ('PowerRestored','PowerRestored','COMPUTER POWER');
CALL osae_sp_object_type_method_add ('ON','Start','COMPUTER POWER','','','','');
CALL osae_sp_object_type_method_add ('OFF','Stop','COMPUTER POWER','','','','');
CALL osae_sp_object_type_method_add ('UPDATE','Update','COMPUTER POWER','','','','');
CALL osae_sp_object_type_property_add ('Update Interval','String','','COMPUTER POWER',0);
CALL osae_sp_object_type_property_add ('Computer Name','String','','COMPUTER POWER',0);
CALL osae_sp_object_type_property_add ('PowerLineStatus','String','','COMPUTER POWER',0);
CALL osae_sp_object_type_property_add ('BatteryChargeStatus','String','','COMPUTER POWER',0);
CALL osae_sp_object_type_property_add ('BatteryFullLifeTime','String','','COMPUTER POWER',0);
CALL osae_sp_object_type_property_add ('BatteryLifePercent','String','','COMPUTER POWER',0);
CALL osae_sp_object_type_property_add ('BatteryLifeRemaining','String','','COMPUTER POWER',0);
Brian

User avatar
bwoodworth
Site Admin
Posts: 1563
Joined: Tue May 04, 2010 6:49 am
Location: California

Re: Monitor Computer Power

#6 Post by bwoodworth » Wed Jan 12, 2011 4:40 pm

I add those properties and everything is working great! BTW, is the update interval in seconds or minutes?
Brian

Automate
Posts: 1691
Joined: Sat Dec 11, 2010 1:44 pm
Location: US

Re: Monitor Computer Power

#7 Post by Automate » Wed Jan 12, 2011 4:49 pm

I will add some detail to the wiki later. Currently the update interval is not used. It is all event driven. On my XP box an event runs when you first loose power and then about every 5 seconds until power is restored and the battery is back to 100%. Then the events stop.

When you get a chance to try it, look in the plugin log file and tell me how often yours is running when on batteries.

Vaughn
Site Admin
Posts: 1432
Joined: Thu May 13, 2010 2:17 pm

Re: Monitor Computer Power

#8 Post by Vaughn » Wed Jan 12, 2011 6:37 pm

To my knowledge the exports are up to date, I know the GUI went up a couple times with misc commits, but just yesterday. Anyways, I will recompile a little later to make sure. Bad timing, changing procs and API always causes a little pain.

Anyways, Automate, gratz, you are in the #1 position for our favorite contributor of 2011 so far! heheh Good job, hope it was not too hard to work with, and man, anything that causes you pain while working on this stuff, just let us know.

Something to consider also in this plugin's design is only putting events and properties on the plugin's type that are directly related to the running of the plugin, not the output. For example, the computer already has a computer object with states and events, when you program detects a change in that computer's powersupply, it should update the computer. This way all data about the computer is in one place and we do not have to go hunt down plugins.

Yes, Computer is a reserved system type. We can handle that in 2 ways, 1) you could include the sql to modify the existing Computer object_type, or 2) I modify the Computer object_type for you in the core database.

The core Object_Types in the DB have had very little thought put into most of them, so we would like to evolve the baseline properties, methods, etc for those objects. When the additions are pretty generic, it does not hurt to add them, I do not want to clutter them with super specialized stuff though. For example, PLACE has very few properties, but I just added Temperature as a property. Most people will not know the temp for most places, but it is common enough of an association with a place to include it always.

So, some computers have Battery information, some don't. Should we include those properties on all computers? I have a UPS on this computer, it is not reporting its levels, but it is justifiable to have those properties sit empty on this machine.

Now, Base Types. We can have a Desktop and a Laptop Object_Type, both with the base type of Computer. This way for filtering or some logic, they are the same, but hold different properties, events, etc...

blah blah... =)

Grats again Automate, and thanks.

Vaughn

User avatar
bwoodworth
Site Admin
Posts: 1563
Joined: Tue May 04, 2010 6:49 am
Location: California

Re: Monitor Computer Power

#9 Post by bwoodworth » Wed Jan 12, 2011 7:08 pm

I have unplugged my laptop and I get the initial event of PowerLost. It has been 15 minutes without any additional events and the BatteryLifePercent property is still at 100. When I hover over my battery icon in the task bar it reads 94%. I am running Windows 7 32bit.
Brian

Automate
Posts: 1691
Joined: Sat Dec 11, 2010 1:44 pm
Location: US

Re: Monitor Computer Power

#10 Post by Automate » Wed Jan 12, 2011 7:15 pm

bwoodworth wrote:I have unplugged my laptop and I get the initial event of PowerLost. It has been 15 minutes without any additional events and the BatteryLifePercent property is still at 100. When I hover over my battery icon in the task bar it reads 94%. I am running Windows 7 32bit.
Sounds like Win 7 does not trigger the system events as the battery discharges and recharges. I will add a polling timer.

Post Reply