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

Offline Don Phillips

  • Hero Member
  • *****
  • Posts: 812
  • Karma: +18/-7
    • Worthington Engineering, Inc.
Re: APC UPS Backup - Now just needs a plugin
« Reply #60 on: December 25, 2016, 04:51:23 pm »
I made good progress. If both of my UPS's are on battery, a multiswitch is turned on and I get a notification. Only problem I am having is the OnBattery=0 variable in each UPS device does not change to 1 when I unplug them, but stays at 0. I have double checked the APCUPSD app and it shows the status going from ONLINE to ONBATT so something is happening. 

If I manually change the UPS devices to OnBattery=1, all my triggers work perfectly.

I am seeing battery levels, connected wattage, and lots of other variables, from APCUPSD but the OnBattery is the only one I do not see changing. Almost like I am missing something again  ???
Vera 3, UI7 1.7.947, CT101 t-stat, Everspring motion detector, GE/Jasco switch, Leviton outlet, AeonLabs door sensor, Insteon garage control, Blue Iris, Sricam SP011, iPhone locator, APCUPSD, VeraMate, VeraAlerts, PLEG, House Modes, Countdown Timer, DVR, Virtual & Multi Switch, Weather, Sys. Mon.

Offline Don Phillips

  • Hero Member
  • *****
  • Posts: 812
  • Karma: +18/-7
    • Worthington Engineering, Inc.
Re: APC UPS Backup - Now just needs a plugin
« Reply #61 on: December 26, 2016, 10:22:01 am »
I always found it interesting how you must give Vera time to get used to new things and this plug-in was no different.

After a couple of days of it running with the new plug-in, this morning I was testing it again and after about 1 to 2 minutes, the OnBattery variable finally changed to 1, triggering an icon change on VeraMate. It got me thinking to also look at the line voltage, since either one indicates a power loss.

So I unplugged the second UPS, again waited a couple of minutes, and the second switch flipped on so the trigger Power Outage tripped, sending me a notification. Working as expected except for the longer than expected delays. I had even set the Vera polling to 1 second (from 5 yesterday) and the APCUPSD polling variable to 5 seconds.

I waited a few minutes, then plugged in the UPS with the larger load. A couple of minutes later plugged in the second UPS, and again after a couple of minutes, received a notification that power was restored.

So everything seems to be working, now I just need to figure out the delay.
Vera 3, UI7 1.7.947, CT101 t-stat, Everspring motion detector, GE/Jasco switch, Leviton outlet, AeonLabs door sensor, Insteon garage control, Blue Iris, Sricam SP011, iPhone locator, APCUPSD, VeraMate, VeraAlerts, PLEG, House Modes, Countdown Timer, DVR, Virtual & Multi Switch, Weather, Sys. Mon.

Offline tedp

  • Full Member
  • ***
  • Posts: 249
  • Karma: +4/-2
Re: APC UPS Backup - Now just needs a plugin
« Reply #62 on: December 27, 2016, 12:59:22 am »
It seems like you're no longer using IIS -- right? With respect to the delays you were seeing, there are a bunch of timing loops to consider. 1st is the sampling period of apcupsd: I believe the "POLLTIME" setting in the apcupsd.conf file defaults to 60 seconds. I set mine to 10 seconds. Then there is the polltime of the Vera plugin, I set that to 10 seconds as well. I want to get reasonable notifications in case of a power outage, but at the same time I don't want to overtax the sampling. It's also one of the reasons I wanted to take the webserver out of the loop because it introduces yet another timing loop.

I'm glad you got it all going.

Offline Don Phillips

  • Hero Member
  • *****
  • Posts: 812
  • Karma: +18/-7
    • Worthington Engineering, Inc.
Re: APC UPS Backup - Now just needs a plugin
« Reply #63 on: December 27, 2016, 07:25:57 pm »
Exactly, no need to run IIS to just get the data APCUPSD already serves.

When I said I changed the APCUPSD polling to 5 seconds, it was the ONBATTERYDELAY variable. The POLLTIME variable was remarked out and set to 60, so I set it to 1.  Retested and much peppier now. Not sure why I did not see it before.

Again, thanks for the awesome tweak on an awesome plug-in. Oh, and +1 to you and kabili207.
« Last Edit: December 27, 2016, 07:29:14 pm by Don Phillips »
Vera 3, UI7 1.7.947, CT101 t-stat, Everspring motion detector, GE/Jasco switch, Leviton outlet, AeonLabs door sensor, Insteon garage control, Blue Iris, Sricam SP011, iPhone locator, APCUPSD, VeraMate, VeraAlerts, PLEG, House Modes, Countdown Timer, DVR, Virtual & Multi Switch, Weather, Sys. Mon.

Offline reneboer

  • Hero Member
  • *****
  • Posts: 1091
  • Karma: +57/-30
Re: APC UPS Backup - Now just needs a plugin
« Reply #64 on: December 29, 2016, 10:39:25 am »
Hi,

As I have a Rasberry Pi running a web server and openLuup I took a bit of a different route. I installed NUT on the Pi and created the attached plugin to parse the upsc command response. This plug in looks like a standard Door/Windows sensor. Benefit of that is that Vera and apps can better deal with it. The only thing is that the Alerts will trigger a door open notification.

When using it on a Vera you still need a Pi or other server with NUT installed as that cannot run on the Vera it self.

This is tested with an APC UPS attached to a Synology NAS and NUT on a Rasberry Pi.
- Follow these instructions to install NUT https://www.domoticz.com/forum/viewtopic.php?t=2266 (installing just the nut-client package may suffice, not tested)
- test the installation using the command : upsc ups@(your NAS IP)

When on Vera you need a remote server to run the upsc command.
Put this php script in the default sever directory. Configure the IP address of your NAS.
For a Pi with Apache and default settings this is /var/www/html   
Code: [Select]
<?php
$nas_ip 
'192.168.x.x';
$output shell_exec('upsc ups@'.$nas_ip);
echo 
"<pre>$output</pre>";
?>

When you have installed on openLuup you do not need the php script, but then you need to set the Remote variable to 0.

The plugin is pending approval on the Vera app market, but is available on the ALTUI App Store if you have ALTUI. You can also force an install on your Vera with this URL http://<your vera IP>:3480/data_request?id=action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=CreatePlugin&PluginNum=8866&Version=32851

Install the plugin by uploading the D_UPSSensor1.xml and I_UPSSensor1.xml files to your Vera. Then manually create a device using these two files.

The device is a default door/windows sensor so it will behave as such. Extra variables will be set with all parameters from the upsc command and others like Watts, just have a look.

The only configuration required is to set the IP address for the web server running the script in the ip attribute.
When running local on openLuup you must enter the IP address of your NAS and set the Remote variable to 0.
   
Some more background information
   GitHub repository    https://github.com/reneboer/vera-UPSSensor
   variables possible    http://networkupstools.org/docs/user-manual.chunked/apcs01.html
   status details APC    http://www.mathstat.dal.ca/~selinger/ups/backups.html

Cheers Rene
« Last Edit: December 30, 2016, 10:55:28 am by reneboer »
2xVeraLite, VeraEdge, openLuup, ALTUI, 20 switches, 10 dimmers, 20 sensors, 10 scene controllers, 1 Harmony Hub, many plug-ins. Not enough time.

Offline Don Phillips

  • Hero Member
  • *****
  • Posts: 812
  • Karma: +18/-7
    • Worthington Engineering, Inc.
Re: APC UPS Backup - Now just needs a plugin
« Reply #65 on: December 29, 2016, 07:57:47 pm »
Thanks for the alternative option.

I have an RPi3 in a box that I could whip out to monitor the UPS that my Vera is connected to. It may be a winter 2018 project (not enough time).
Vera 3, UI7 1.7.947, CT101 t-stat, Everspring motion detector, GE/Jasco switch, Leviton outlet, AeonLabs door sensor, Insteon garage control, Blue Iris, Sricam SP011, iPhone locator, APCUPSD, VeraMate, VeraAlerts, PLEG, House Modes, Countdown Timer, DVR, Virtual & Multi Switch, Weather, Sys. Mon.

Offline wilme2

  • Hero Member
  • *****
  • Posts: 1011
  • Karma: +18/-13
Re: APC UPS Backup - Now just needs a plugin
« Reply #66 on: January 04, 2017, 05:12:38 pm »
Hi,

As I have a Rasberry Pi running a web server and openLuup I took a bit of a different route. I installed NUT on the Pi and created the attached plugin to parse the upsc command response. This plug in looks like a standard Door/Windows sensor. Benefit of that is that Vera and apps can better deal with it. The only thing is that the Alerts will trigger a door open notification.

When using it on a Vera you still need a Pi or other server with NUT installed as that cannot run on the Vera it self.


Could not this have run all on the Synology NAS?
Long Live UI5!

Offline reneboer

  • Hero Member
  • *****
  • Posts: 1091
  • Karma: +57/-30
Re: APC UPS Backup - Now just needs a plugin
« Reply #67 on: January 05, 2017, 05:11:42 am »
Hi,

I guess if you find out how NUT talks to the Synology NAS to get the status, then yes I'd think so. No idea how hard that is though. This was a few hours job. Maybe next my try  ;).

Cheers Rene
2xVeraLite, VeraEdge, openLuup, ALTUI, 20 switches, 10 dimmers, 20 sensors, 10 scene controllers, 1 Harmony Hub, many plug-ins. Not enough time.

Offline reneboer

  • Hero Member
  • *****
  • Posts: 1091
  • Karma: +57/-30
Re: APC UPS Backup - Now just needs a plugin
« Reply #68 on: January 06, 2017, 06:17:29 am »
Hi,

So... one evening later and a managed to figure out how NUT talks to a UPS server (like a Synology NAS) over IP and attached is a version of the plugin that does not require a Pi running NUT and a special script  :D.

If you upload this version and point it to your Synology NAS IP address it should work directly.

It does not support communication via SSL, so if you turned that on on your UPS server it won't work. Also if you have a different server than a Synology NAS you may need to change the UPSName variable and add the correct port to the ip attribute. The default port number is 3493.

BTW, tested on UI7 and openLuup. I do not do UI5 anymore.

This version is pending approval on the Vera App Market, but can can install via this URL http://<your vera IP>:3480/data_request?id=action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=CreatePlugin&PluginNum=8866&Version=32866.


Enjoy.

Cheers Rene
« Last Edit: January 06, 2017, 07:55:46 am by reneboer »
2xVeraLite, VeraEdge, openLuup, ALTUI, 20 switches, 10 dimmers, 20 sensors, 10 scene controllers, 1 Harmony Hub, many plug-ins. Not enough time.

Offline wilme2

  • Hero Member
  • *****
  • Posts: 1011
  • Karma: +18/-13
Re: APC UPS Backup - Now just needs a plugin
« Reply #69 on: January 06, 2017, 10:49:31 am »
So... one evening later and a managed to figure out how NUT talks to a UPS server (like a Synology NAS) over IP and attached is a version of the plugin that does not require a Pi running NUT and a special script  :D.

It does not support communication via SSL, so if you turned that on on your UPS server it won't work.

Awesome - thanks!  I do use a Synology NAS, but with SSL, but let me look at it and test.  I am UI5, so can test that too. 
Long Live UI5!

Offline Judman13

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
Re: APC UPS Backup - Now just needs a plugin
« Reply #70 on: March 09, 2017, 02:54:51 pm »
Hi,

So... one evening later and a managed to figure out how NUT talks to a UPS server (like a Synology NAS) over IP and attached is a version of the plugin that does not require a Pi running NUT and a special script  :D.

If you upload this version and point it to your Synology NAS IP address it should work directly.

It does not support communication via SSL, so if you turned that on on your UPS server it won't work. Also if you have a different server than a Synology NAS you may need to change the UPSName variable and add the correct port to the ip attribute. The default port number is 3493.

BTW, tested on UI7 and openLuup. I do not do UI5 anymore.

This version is pending approval on the Vera App Market, but can can install via this URL http://<your vera IP>:3480/data_request?id=action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=CreatePlugin&PluginNum=8866&Version=32866.


Enjoy.

Cheers Rene

Will try this tonight! Many thanks!