Battery & UPS Monitor plugin.

Posted on
Tue Feb 05, 2013 12:12 pm
macpro offline
User avatar
Posts: 682
Joined: Dec 29, 2005
Location: Third byte on the right

Re: Battery & UPS Monitor plugin.

Here's output from one of my Macs:

$ apcaccess
APC : 001,036,0984
DATE : 2013-02-05 19:04:33 +0100
HOSTNAME : MServe.local
VERSION : 3.14.10 (13 September 2011) darwin
UPSNAME : MServeUPS
CABLE : USB Cable
DRIVER : USB UPS Driver
UPSMODE : Stand Alone
STARTTIME: 2013-02-04 12:20:28 +0100
MODEL : Back-UPS ES 700G
STATUS : ONLINE
LINEV : 224.0 Volts
LOADPCT : 24.0 Percent Load Capacity
BCHARGE : 100.0 Percent
TIMELEFT : 22.2 Minutes
MBATTCHG : 20 Percent
MINTIMEL : 10 Minutes
MAXTIME : 0 Seconds
SENSE : Medium
LOTRANS : 180.0 Volts
HITRANS : 266.0 Volts
ALARMDEL : 30 seconds
BATTV : 13.5 Volts
LASTXFER : Automatic or explicit self test
NUMXFERS : 1
XONBATT : 2013-02-05 06:45:58 +0100
TONBATT : 0 seconds
CUMONBATT: 11 seconds
XOFFBATT : 2013-02-05 06:46:09 +0100
LASTSTEST: 2013-02-05 06:45:58 +0100
STATFLAG : 0x07000008 Status Flag
SERIALNO : 5B1143T07380
BATTDATE : 2011-10-22
NOMINV : 230 Volts
NOMBATTV : 12.0 Volts
FIRMWARE : 871.O2 .I USB FW:O2
END APC : 2013-02-05 19:05:15 +0100

"I tawt I taw a puddy tat!" Tweety

Posted on
Tue Feb 05, 2013 12:19 pm
macpro offline
User avatar
Posts: 682
Joined: Dec 29, 2005
Location: Third byte on the right

Re: Battery & UPS Monitor plugin.

The downside of using /sbin/apcaccess is that you can only check the locally connected UPS.
But APCUPSD can also work together with Apache, providing a http interface.
This way it's possible to collect data from other systems with UPSses.
The output above is also available via a URL like this:

http://mserve.local/cgi-bin/upsfstats.cgi?host=mserve

"I tawt I taw a puddy tat!" Tweety

Posted on
Tue Feb 05, 2013 4:59 pm
bschollnick2 offline
Posts: 1294
Joined: Oct 17, 2004
Location: Rochester, Ny

Re: Battery & UPS Monitor plugin.

macpro wrote:
The downside of using /sbin/apcaccess is that you can only check the locally connected UPS.
But APCUPSD can also work together with Apache, providing a http interface.
This way it's possible to collect data from other systems with UPSses.
The output above is also available via a URL like this:

http://mserve.local/cgi-bin/upsfstats.cgi?host=mserve


Can you post the output? mserve.local is local to your network, and won't be accessible to us. (If you have it publically available, the IP address would work, or a FQN hostname).

------
My Plugins for Indigo (v4, v5, and v6) - http://bit.ly/U8XxPG

Security Script for v4 - http://bit.ly/QTgclf
for v5 - http://bit.ly/T6WBKu

Support Forum(s) - http://www.perceptiveautomation.com/userforum/viewforum.php?f=33

Posted on
Wed Feb 06, 2013 12:44 am
macpro offline
User avatar
Posts: 682
Joined: Dec 29, 2005
Location: Third byte on the right

Re: Battery & UPS Monitor plugin.

No, the output is not available on the interwebs.

But here's the <body> from the HTML page that is generated:
Code: Select all
<body>
<blockquote><pre>APC      : 001,036,0984
DATE     : 2013-02-06 07:40:43 +0100 
HOSTNAME : MServe.local
VERSION  : 3.14.10 (13 September 2011) darwin
UPSNAME  : MServeUPS
CABLE    : USB Cable
DRIVER   : USB UPS Driver
UPSMODE  : Stand Alone
STARTTIME: 2013-02-04 12:20:28 +0100 
MODEL    : Back-UPS ES 700G
STATUS   : ONLINE
LINEV    : 226.0 Volts
LOADPCT  :  24.0 Percent Load Capacity
BCHARGE  : 100.0 Percent
TIMELEFT :  22.2 Minutes
MBATTCHG : 20 Percent
MINTIMEL : 10 Minutes
MAXTIME  : 0 Seconds
SENSE    : Medium
LOTRANS  : 180.0 Volts
HITRANS  : 266.0 Volts
ALARMDEL : 30 seconds
BATTV    : 13.5 Volts
LASTXFER : Automatic or explicit self test
NUMXFERS : 1
XONBATT  : 2013-02-05 06:45:58 +0100 
TONBATT  : 0 seconds
CUMONBATT: 11 seconds
XOFFBATT : 2013-02-05 06:46:09 +0100 
LASTSTEST: 2013-02-05 06:45:58 +0100 
STATFLAG : 0x07000008 Status Flag
SERIALNO : 5B1143T07380 
BATTDATE : 2011-10-22
NOMINV   : 230 Volts
NOMBATTV :  12.0 Volts
FIRMWARE : 871.O2 .I USB FW:O2
END APC  : 2013-02-06 07:41:19 +0100 
</pre></blockquote>
</body>

"I tawt I taw a puddy tat!" Tweety

Posted on
Wed Feb 06, 2013 8:44 am
Fishysan offline
Posts: 72
Joined: Feb 01, 2012

Re: Battery & UPS Monitor plugin.

This is awesome Ben! Thanks for this.. I'll have to give it a whirl. (and upgrade to 6! :D )

Posted on
Wed Feb 06, 2013 12:24 pm
bschollnick2 offline
Posts: 1294
Joined: Oct 17, 2004
Location: Rochester, Ny

Re: Battery & UPS Monitor plugin.

Fishysan wrote:
This is awesome Ben! Thanks for this.. I'll have to give it a whirl. (and upgrade to 6! :D )


This plugin should work in Indigo v5. I haven't tested it there, but it should.

------
My Plugins for Indigo (v4, v5, and v6) - http://bit.ly/U8XxPG

Security Script for v4 - http://bit.ly/QTgclf
for v5 - http://bit.ly/T6WBKu

Support Forum(s) - http://www.perceptiveautomation.com/userforum/viewforum.php?f=33

Posted on
Wed Feb 06, 2013 12:56 pm
Fishysan offline
Posts: 72
Joined: Feb 01, 2012

Re: Battery & UPS Monitor plugin.

Groovy - I might try this for added connectivity. I got an APC AP9617 management card (ethernet) for my UPS but never got it working. The integration with Indigo however is very cool and opens up a lot of flexible options. I'll let you know when I get a chance to try it w v5.

Posted on
Sun Feb 10, 2013 7:18 pm
berkinet offline
User avatar
Posts: 2892
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Battery & UPS Monitor plugin.

macpro wrote:
The downside of using /sbin/apcaccess is that you can only check the locally connected UPS.
Code: Select all
APCACCESS(8)              BSD System Manager's Manual             APCACCESS(8)

NAME
     apcaccess -- retrieve status information from apcupsd(8)

SYNOPSIS
     apcaccess [status [ [<hostname>][:<port>] ] ]
So: apcaccess status 192.168.4.4 -- Works fine :-)
Or even with bonjour: apcaccess status somehost.local

apcaccess is just a client app that queries the APC Netserver, by default on port 3551. The actual "driver" is apcupsd which runs as a daemon, started in /Library/StartupItems/apcupsd The web interface is provided by multimon.cgi which reads fro the APC Netserver and spits out the same data as apcaccess, but in html.
Last edited by berkinet on Sun Feb 10, 2013 7:37 pm, edited 1 time in total.

Posted on
Sun Feb 10, 2013 7:29 pm
berkinet offline
User avatar
Posts: 2892
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Battery & UPS Monitor plugin.

BTW, here is a little AppleScript I've used her for a few years. It is run on a schedule and just grabs the APC data from the UPS attached to my server (it could easily use a local instance as well.). I should probably rewrite this in Python just for the exercise.

As to making a plugin out of it... I hope Ben just adds the support to his existing UPS plugin. If he doesn't, I'll think about it. But, frankly, for a one-way device (I.e. read-only) I am not sure what advantage a plugin/device implementation has over a script/variable approach.
Code: Select all
-- Convert the incoming "Name: Value" newline separated records into
-- a single line that can be converted into an AppleScript list
-- 1) look for ": " and change those delimiters to "@"
-- 2) Remove any spaces preceeding the "@" and leave one trailing space
-- 3) Add "@ " before each newline
-- 4) Delete the newlines
-- 5) Trim off the last two characters of the line "@ "
set rawData to do shell script "/usr/local/bin/apcaccess status 192.168.4.4|sed -e\"s/: /@ /\"|sed -e\"s/  *@  */@ /g\"|sed -e \"s/$/@ /\" |tr -d \"\\012\"|sed -e \"s/..$//g\""
-- Save the current text delimiters
set oldDefs to AppleScript's text item delimiters

-- set the text delimiters to our desired "@ "
set AppleScript's text item delimiters to "@ "

-- Read the output from the shell script into a list
set upsData to (every text item of rawData)

-- Restore the text delimiters
set AppleScript's text item delimiters to oldDefs

-- Push the upsData list into our conversion script (see below)
set listToRecord's dataElement to upsData

-- and finally, convert the list to records
set upsData to (run script listToRecord)

tell application "IndigoServer"
   set the value of variable "BATTV" to BATTV of upsData
   set the value of variable "BCHARGE" to BCHARGE of upsData
   set the value of variable "DATE" to |date| of upsData
   set the value of variable "LINEV" to LINEV of upsData
   set the value of variable "LOADPCT" to LOADPCT of upsData
   set the value of variable "NUMXFERS" to NUMXFERS of upsData
   set the value of variable "STATUS" to STATUS of upsData
   set the value of variable "TIMELEFT" to TIMELEFT of upsData
end tell

-- This is the script that does the actual list to record conversion
script listToRecord
   property dataElement : missing value
   {«class usrf»:dataElement}
end script

Posted on
Mon Feb 11, 2013 12:10 am
macpro offline
User avatar
Posts: 682
Joined: Dec 29, 2005
Location: Third byte on the right

Re: Battery & UPS Monitor plugin.

berkinet wrote:
So: apcaccess status 192.168.4.4 -- Works fine :-)

Doh! I should have RTFH. :wink:

"I tawt I taw a puddy tat!" Tweety

Posted on
Mon Feb 11, 2013 7:03 pm
berkinet offline
User avatar
Posts: 2892
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Battery & UPS Monitor plugin.

I have posted a Python version of the AppleScript posted below to this thread started by @DU Lou.

This script is a complete implementation in Python and does not require the apcaccess program. If someone (Ben?) were to wish to include APC specific features in a plugin. The script pretty much provides the necessary functionality.

If there are questions about the script or use of apaccess and apcupsd please post them to the to the thread linked to above so we can leave this thread for discussion of the UPS plugin.
Last edited by berkinet on Mon Feb 11, 2013 10:40 pm, edited 1 time in total.

Posted on
Mon Feb 11, 2013 10:39 pm
berkinet offline
User avatar
Posts: 2892
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Battery & UPS Monitor plugin.

a little while back, automaton wrote:
...The plugin looks great. I don't know if the can be run in parallel with APCUPSD (I'm guessing not), so you may have to choose depending on your needs and the complexity of your UPS setup.

Based on this snippet from the apcupsd documentation, I believe apcupsd and the built-in OS-X System Preferences -> Energy Saver -> UPS pane are incompatible.

    ... During installation, Apcupsd will automatically install a simple dummy kext driver [ApcupsdDummy.kext] designed to prevent Apple's monitoring software from taking over the UPS. ...

And, in fact, if the kext is present, the UPS pane does not appear.

Posted on
Tue Feb 12, 2013 1:11 am
macpro offline
User avatar
Posts: 682
Joined: Dec 29, 2005
Location: Third byte on the right

Re: Battery & UPS Monitor plugin.

That's correct. On my Macs with APCUPSD I don't see the UPS pane anymore. But it was visible before installing APCUPSD.

"I tawt I taw a puddy tat!" Tweety

Posted on
Tue Jun 11, 2013 8:14 am
Dewster35 offline
Posts: 1005
Joined: Jul 06, 2010
Location: Petoskey, MI

Re: Battery & UPS Monitor plugin.

Perhaps slightly off topic, but does anyone have any hardware recommendations for a UPS that would work with this plugin?

Posted on
Mon Jul 15, 2013 2:52 am
McJohn offline
User avatar
Posts: 273
Joined: Dec 18, 2012
Location: The Netherlands

Re: Battery & UPS Monitor plugin.

Great Plugin! Thank you very much Benjamin.

Simple but powerful and very handy.

I use a APC UPS 650
(http://www.apc.com/products/resource/in ... ku=BE650G1)

Connected a Mac mini, 2 Airports, Cable Router, powered USB Hub and 4 little power supplies for other stuff,
when power fails, the APC almost 20 minutes continues the power delivery.

Greetings,

John

Who is online

Users browsing this forum: No registered users and 2 guests