We have moved at community.getvera.com

Author Topic: APC UPS Backup - Now just needs a plugin  (Read 40728 times)

Offline jimpapa

  • Sr. Member
  • ****
  • Posts: 454
  • Karma: +28/-1
Re: APC UPS Backup - Now just needs a plugin
« Reply #45 on: January 01, 2014, 02:52:54 pm »
Anyone working on a UPS plugin?

I see a real need to monitor if your power is out and if so.. Can send push notifications and network commands via SSH to servers etc. while on UPS power.

I have been looking for a decent way to monitor if AC power is down at my office and to be notified. 
All vital equipment is on UPS including network closet. 

We wired in a manual transfer switch.   I could not install a natural gas gen with auto transfer switch because our feed to the office suite is only 1/2" pipe.   So I need to get alerted that we lost power.. If I am not in the office and also. Need to shutdown a rack of servers on an APC 3000 UPS

Having vera do this would be great.. 

Offline AgileHumor

  • Hero Member
  • *****
  • Posts: 984
  • Karma: +51/-27
  • KISS
Re: APC UPS Backup - Now just needs a plugin
« Reply #46 on: March 26, 2014, 01:33:08 pm »
How to people monitor outages?  I have a Cyperpower UPS, but would like some notification when power goes out.
WMC Leviton:18xVPE06,8xVRS15,3xVRP03-W,2xVRR15,4xVRCS4,2xVRCS2,VP00R,8xVRS15 Aeon:5xDSC06106,4xDSC24,4xDSC25,12xDSB29,2xDSC11,4xDSB54,DSB05,3xDSA22,DSA38,2xDSA03202B,DSB09104,HEM Other:3xYale,12xHSM100v3,7xSP103,45604,WDHA-12,SSA2USR,EVLCD1T,6xWWA02A,7xIPC-HFW2100,URTSI,Hue,Russound,OpenSprinker

Offline jimpapa

  • Sr. Member
  • ****
  • Posts: 454
  • Karma: +28/-1
Re: APC UPS Backup - Now just needs a plugin
« Reply #47 on: March 26, 2014, 01:45:33 pm »
I started a thread a while back about this..

so this is what I came up with and it is working great.

http://forum.micasaverde.com/index.php/topic,22330.msg149194.html#msg149194


Offline kabili207

  • Newbie
  • *
  • Posts: 3
  • Karma: +1/-0
Re: APC UPS Backup - Now just needs a plugin
« Reply #48 on: April 04, 2014, 06:41:13 pm »
I spent some time over the past few days parsing the output of apcupsd CGI stats page (http://www.apcupsd.com/manual/manual.html#upsfstatus-cgi) and came up with this. This is for UPS units not connected to the Vera. You need to setup a server running apcupsd to expose the cgi scripts.

After uploading the files attached the the vera, add a device with the following parameters:
Device type: urn:zyrenth-com:device:Ups:1
Device filename: D_ApcUps1.xml
Imp file: I_ApcUps1.xml

After creating the device, go to the device settings and set the url to the cgi script (ex. http://192.168.1.10/cgi-bin/upsfstats.cgi). Make sure you use the upsfstats.cgi script!

Let me know if there is anything you'd like me to add.

Offline hharte

  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
Re: APC UPS Backup - Now just needs a plugin
« Reply #49 on: May 04, 2014, 02:41:51 pm »
Wow, the plugin by kabili207 works great.  I have it running on my Vera3 with three APC Back-UPS Pro.

UPS1: 700VA APC Back-UPS Pro attached to 192.168.0.100 (also hosting the apcupsd webserver, running Windows 8.1)
UPS2: 700VA APC Back-UPS Pro attached to 192.168.0.110 (apcupsd running on Windows 7)
UPS3: 1500VA APC Back-UPS Pro attached to 192.168.0.111 (apcupsd running on Windows 8.1)

The Windows 8.1 "server" machine is running the Apache2 HTTP server via Cygwin and is hosting the gci scripts.  On the machine hosting the webserver, you add each of the other machines to the apcupsd hosts.conf file as follows:

MONITOR 127.0.0.1 "UPS1"
MONITOR 192.168.0.110 "UPS2"
MONITOR 192.168.0.111 "UPS3"

On the remote machines, you need to create an inbound rule in Windows Firewall to unblock TCP port 3551.

Then for each instance of the Vera UPS plugin, you add the appropriate URL from your web server, ie, for the example above:

http://192.168.0.100/cgi-bin/apcupsd/upsfstats.cgi
http://192.168.0.100/cgi-bin/apcupsd/upsfstats.cgi?host=192.168.0.110&temp=F
http://192.168.0.100/cgi-bin/apcupsd/upsfstats.cgi?host=192.168.0.111&temp=F

In order to be able to tell in Vera if there is a power failure, I used the App "Program Logic Event Generator" to monitor the "OnBattery" Device Property of each APC UPS.  If any of them goes to "OnBattery == 1" then it will turn a Virtual Switch (App) to off, indicating a power failure.  When all of the UPS OnBattery == 0, then the power is declared restored, and the Virtual Switch is turned on.

I'm using the Virtual Switch to trigger  scenes for "power failure" and "power restored."  In those scenes, I send push notifications via the "Push Notifications" App to my Android phone.

It is working really well so far.  A couple things I can think of to improve this plugin are as follows:

1. Provide a "motion sensor" capability or make it a virtual switch (like the "Day or Night" app) .
2. Add the ability to add an offset to the wattage meter.  For example, my UPS says the load attached to it is 61W, but when I measure it with a power meter, it is really using 79W.  I guess this is because the UPS itself is consuming some power.
3. Add it to the Vera Apps store for easier download/install.

Thanks again for the useful plugin!

-Howard
« Last Edit: May 04, 2014, 02:44:03 pm by hharte »

Offline tomgru

  • Hero Member
  • *****
  • Posts: 1403
  • Karma: +18/-6
Re: APC UPS Backup - Now just needs a plugin
« Reply #50 on: December 16, 2014, 08:03:09 pm »
How to people monitor outages?  I have a Cyperpower UPS, but would like some notification when power goes out.

@agilehumor, did you ever come up with a solution for this?

Offline tedp

  • Sr. Member
  • ****
  • Posts: 288
  • Karma: +6/-2
Re: APC UPS Backup - Now just needs a plugin
« Reply #51 on: June 14, 2016, 06:47:45 pm »
I probably should start a new topic, but I don't want to confuse people given I'm posting a modified implementation file.

I got  kabili207's plug in working -- the biggest hassle was getting IIS to work on my home network. I realized there's not really a reason to have a web-server in the path since all the web-server does is access port 3551 on the individual machines to poll for UPS data. So, I rewrote the implementation file to access individual computers associated with a UPS directly.

I simply replaced socket.http with socket.tcp (along with some other sundry changes).

The file is attached -- instead of specifying a URL on the control page (i.e. http://192.168.1.50/xxxx), just specify the IP address of the computer that is running apcupsd --  i.e.  192.168.1.22 (just the IP, no http or anything else in the field). Make sure there is a firewall exception to allow access to that port on the target computer.

There is probably a good amount of cleanup to do, but it works -- and in conjunction with altUI watches and veraAlerts, I can be notified of power failures.

Offline Scarab

  • Sr. Newbie
  • *
  • Posts: 40
  • Karma: +4/-1
Re: APC UPS Backup - Now just needs a plugin
« Reply #52 on: December 17, 2016, 03:25:56 pm »
Great but has anyone found a way to plug the USB directly into the Vera unit?  Most modern (home) UPSes not only alert during a power outage but also provide power consumption data in WATTs.  Even thought the energy monitoring on Vera is not all that great it would be nice to know what my equipment rack is using compared to the rest of the house. 

Most energy monitors compatible with vera are switched, but I want something more passive so no one can accidently turn off my network equipment.  It would simply be nice to be alerted of a power failure and have the device report power consumption. 

Offline tedp

  • Sr. Member
  • ****
  • Posts: 288
  • Karma: +6/-2
Re: APC UPS Backup - Now just needs a plugin
« Reply #53 on: December 20, 2016, 08:52:21 am »
Great but has anyone found a way to plug the USB directly into the Vera unit?  Most modern (home) UPSes not only alert during a power outage but also provide power consumption data in WATTs.  Even thought the energy monitoring on Vera is not all that great it would be nice to know what my equipment rack is using compared to the rest of the house. 

Most energy monitors compatible with vera are switched, but I want something more passive so no one can accidently turn off my network equipment.  It would simply be nice to be alerted of a power failure and have the device report power consumption.

See my post at http://forum.micasaverde.com/index.php/topic,38300.msg286318.html on this topic. To get APCUPS working with Vera would require a recompile of some USB drivers which would then have to be installed. That would only be step 1, with additional hurdles afterwards. It's beyond my capabilities. To achieve what you are trying to do, I might try and hook up a BeagleBone or a RaspberryPi to the same UPS as my Vera to APCUPS. FYI: APCUPS only works on APC brand devices. I'm not sure if there are equivalents for other brands (i.e. CyberPower). Also, the lower end APCUPS devices do not report real-time power consumption.
« Last Edit: December 20, 2016, 08:54:15 am by tedp »

Offline Don Phillips

  • Hero Member
  • *****
  • Posts: 1464
  • Karma: +41/-36
Re: APC UPS Backup - Now just needs a plugin
« Reply #54 on: December 20, 2016, 09:58:14 pm »
The file is attached -- instead of specifying a URL on the control page (i.e. http://192.168.1.50/xxxx), just specify the IP address of the computer that is running apcupsd --  i.e.  192.168.1.22 (just the IP, no http or anything else in the field). Make sure there is a firewall exception to allow access to that port on the target computer.

Excellent tweak on an excellent plug in.  Enabling IIS is not something I wanted to do. 

I have the device set up, pointing to the computer the UPS is plugged into, 192.168.1.100.  But Vera reports "Data URL is required". I check the device and the URL under setting is blank.  I enter 192.168.1.100 and it reports "error: invalid service". I ensured port 3551 is open to all connections on the .100 computer.  APCUPSD is running and I can see the data, but Vera is not being cooperative.

I re-uploaded the file in case that was the problem - still not working.

Am I overlooking something?
« Last Edit: December 20, 2016, 10:06:20 pm by Don Phillips »
Vera 3, 1.7.1040, CT101, Everspring Motion, GE/Jasco Switch/Dimmer, Leviton outlet, AeonLabs sensor, NuTone garage door, Blue Iris, Sricam SP011, iPhone locator, APCUPSD, VeraMate, VeraAlerts, PLEG, House Modes, Countdown Timer, DVR, Virtual/Multi Switch, LB60Z-1 bulb, Hue, Alexa, Zooz 4-1

Offline tedp

  • Sr. Member
  • ****
  • Posts: 288
  • Karma: +6/-2
Re: APC UPS Backup - Now just needs a plugin
« Reply #55 on: December 21, 2016, 01:41:07 am »
The file is attached -- instead of specifying a URL on the control page (i.e. http://192.168.1.50/xxxx), just specify the IP address of the computer that is running apcupsd --  i.e.  192.168.1.22 (just the IP, no http or anything else in the field). Make sure there is a firewall exception to allow access to that port on the target computer.

Excellent tweak on an excellent plug in.  Enabling IIS is not something I wanted to do. 

I have the device set up, pointing to the computer the UPS is plugged into, 192.168.1.100.  But Vera reports "Data URL is required". I check the device and the URL under setting is blank.  I enter 192.168.1.100 and it reports "error: invalid service". I ensured port 3551 is open to all connections on the .100 computer.  APCUPSD is running and I can see the data, but Vera is not being cooperative.

I re-uploaded the file in case that was the problem - still not working.

Am I overlooking something?

hmmm.. I was trying to pull out the relevant LUA code that is the "secret sauce" so you could run it under something like altUI's "Test LUA" page to see if you are actually talking with your APC. Much to my dismay, I'm getting some LUA error when running the code, but the plugin still seems to work fine.

If you want to give it a shot, paste this into the "test code" and change the string for the IP address on line #8. If it works, you should get a printout of the APCUPSD status dump.

Code: [Select]
local socket = require("socket")
local apc = socket.tcp()
apc:settimeout(5)
local st = os.time()
print (st)
local stats = {} 
apc:setoption("tcp-nodelay",true)
apc:connect("192.168.1.xx", 3551)
apc:send("\00\06")
for i = 1,100,1 do  -- there should not be more than 100 lines
local result = apc:receive(2) -- the length comes first
local lineLen = 256* string.byte(result,1) + string.byte(result,2) -- convert length into an integer
local v = apc:receive(lineLen - 1) -- read the rest of the line less the newline
apc:receive(1) -- dump the newline
local kk = v:match("^(.-)%s*:")  -- get the key
local vv = v:match("^.-:%s*(.-)%s*$") --get the value
stats[kk] = vv
if string.find(v,"END.*") ~= nil  then break end -- did we get to the end?
end
apc:close()

    print("fetchSensorData: exec=" .. (os.time() - st))

print(v)
return(true)

Offline Don Phillips

  • Hero Member
  • *****
  • Posts: 1464
  • Karma: +41/-36
Re: APC UPS Backup - Now just needs a plugin
« Reply #56 on: December 21, 2016, 05:03:32 pm »
I really appreciate the help.  The LUA code seems to run with no errors, but I do not see any "printout" on the screen nor can I figure out where to go to look at a file. Note: I do not use ALTUI.

In the meantime, trying to get IIS running but no luck getting CGI enabled. Tinkering with it I may have caused more damage to settings than anything else.   
Vera 3, 1.7.1040, CT101, Everspring Motion, GE/Jasco Switch/Dimmer, Leviton outlet, AeonLabs sensor, NuTone garage door, Blue Iris, Sricam SP011, iPhone locator, APCUPSD, VeraMate, VeraAlerts, PLEG, House Modes, Countdown Timer, DVR, Virtual/Multi Switch, LB60Z-1 bulb, Hue, Alexa, Zooz 4-1

Offline Don Phillips

  • Hero Member
  • *****
  • Posts: 1464
  • Karma: +41/-36
Re: APC UPS Backup - Now just needs a plugin
« Reply #57 on: December 22, 2016, 02:10:41 pm »
Quick follow up: I tested the APCUPSD installation and I am able to get data from a command prompt from another computer by running apcaccess status 192.168.1.100 so at least the app is reachable.  Just not sure why Vera cannot get the same data using the plugin.  ???
Vera 3, 1.7.1040, CT101, Everspring Motion, GE/Jasco Switch/Dimmer, Leviton outlet, AeonLabs sensor, NuTone garage door, Blue Iris, Sricam SP011, iPhone locator, APCUPSD, VeraMate, VeraAlerts, PLEG, House Modes, Countdown Timer, DVR, Virtual/Multi Switch, LB60Z-1 bulb, Hue, Alexa, Zooz 4-1

Offline Don Phillips

  • Hero Member
  • *****
  • Posts: 1464
  • Karma: +41/-36
Re: APC UPS Backup - Now just needs a plugin
« Reply #58 on: December 24, 2016, 01:28:30 pm »
I finally figured out what happened.  When I uploaded the new implementation file, Vera added the local path into the file name, C:\Users\Don\Desktop\I_ApcUps1.xml, so when I created the device, I was using the old file not the new one.  Changed it to the long file name and viola! Working like a charm. I have a second UPS powering my network gear and NAS I'll work on next.   
Vera 3, 1.7.1040, CT101, Everspring Motion, GE/Jasco Switch/Dimmer, Leviton outlet, AeonLabs sensor, NuTone garage door, Blue Iris, Sricam SP011, iPhone locator, APCUPSD, VeraMate, VeraAlerts, PLEG, House Modes, Countdown Timer, DVR, Virtual/Multi Switch, LB60Z-1 bulb, Hue, Alexa, Zooz 4-1

Offline bucko

  • Hero Member
  • *****
  • Posts: 659
  • Karma: +27/-9
Re: UPS done right
« Reply #59 on: December 24, 2016, 08:30:58 pm »
This is a Sako 3000VA online UPS that powers all my HA equipment for 10-12 hrs. Cams, Vera, M1 Gold, network, etc.
Vera 3, 40+ Fibaro relays & dimmers, IPUX cams, Elk M1 Gold, M1XEP, M1SP, XVOR, M1RB, Elk124, Monoprice HDMI matrix & 6 zone amp, Denon AVR, Panasonic A8000, BI DV,On Controls