Alternative to Power Failure trigger

Posted on
Tue Jul 31, 2012 1:34 pm
bolivar offline
Posts: 8
Joined: Feb 08, 2010

Alternative to Power Failure trigger

My setup include a MacMini on a UPS with the 2448A7 interface.
As such, I cannot take advantage of the built in power outage trigger, but really wants to be notify when there is a power outage.

I was thinking about creating a date/time event that would run an Applescript every 15 or 20 mins that would do the following:

Send a status request to a fixed wireline insteon device. (Now, I am assuming the response would not be ON/OFF if the device is offline ... 0 maybe ? Can someone confirm this ?)

Use that piece of information (ON/OFF/0) either as a variable in Indigo, or to trigger an email within the Applescript.

Now, reading several threads in this forum, and it seems the only way to retrieve this information (ON/OFF/0) is to parse the log file ..... Can someone explain how to do that ?

Thanks !

Posted on
Tue Jul 31, 2012 4:35 pm
nsheldon offline
Posts: 2469
Joined: Aug 09, 2010
Location: CA

Re: Alternative to Power Failure trigger

The concept seems doable. However, the results of a status request aren't easily obtainable, as you pointed out.

Rather than using a status request as a test, consider using an INSTEON "ping" command. You can do this using the "Send Raw INSTEON Command" action found in the INSTEON Commands plugin. Create an Indigo variable named something like "PowerTest" with no initial value. Then create an Indigo Schedule that repeats ever how often you want to test (15 to 20 minutes seems reasonable). For the action type, choose "Plugin", selecting the "INSTEON Commands" plugin and "Send Raw INSTEON Command" action. Click "Edit Action Settings" to configure the action. Select the device you'd like to ping. It should be one that's always been very reliable. It should also be a newer INSTEON module (made around 2007 or later) to be more sure that it'd respond to INSTEON version i2 messages. Put a check next to "Write results to variable". Set the Results location to "In ACK". Select the PowerTest variable as the Variable in which to store the result. Set the Command 1 Byte to 0x0F (those are zeros). Set Command 2 Byte to 0x00 (those are zeros too). Click Save. Click OK on the Schedule window.

As long as the device responds to the ping request, the PowerTest variable should contain 0 (zero). If there's a communication error (no ping response), the value in the variable will change to ERROR. You can then create a trigger based on that variable to send email, etc. if the variable changes to ERROR.

One word of caution. Any time INSTEON messages aren't acknowledged, the INSTEON controller (your 2448 in this case) will repeat the message numerous times which can cause communications delays, esp. if you have lots of devices.

Posted on
Wed Aug 01, 2012 6:26 am
bolivar offline
Posts: 8
Joined: Feb 08, 2010

Re: Alternative to Power Failure trigger

Thank you !

I believe this should do the trick.

One question... The "Plugin" action type does not appear as an option.
I am assuming this is a new functionality of Indigo 5, correct ?
(I am running 4.2)

Or do I need to manually install the plug in ?

Thanks !

Posted on
Wed Aug 01, 2012 9:55 am
nsheldon offline
Posts: 2469
Joined: Aug 09, 2010
Location: CA

Re: Alternative to Power Failure trigger

Ahh... Yea. You won't be able to do any of what I described with any version of Indigo prior to version 5.1. Absent any information to the contrary, I assumed you were using the latest version of Indigo Pro. You may be able to develop something using the "send insteon raw" AppleScript verb to send the same type of ping and an AppleScript Indigo Attachment that subscribed to all INSTEON messages to monitor traffic, however, that approach would probably have the same limitations as an INSTEON status request in that there really wouldn't be any easy way to tell what the result of sending the command was. Sorry I couldn't help more.

Posted on
Wed Aug 01, 2012 10:13 am
bolivar offline
Posts: 8
Joined: Feb 08, 2010

Re: Alternative to Power Failure trigger

No worry .... You were actually very helpful.

This may be the incentive I needed to upgrade :lol:

Thank you !

Posted on
Wed Feb 13, 2013 7:39 am
Nono offline
Posts: 5
Joined: Dec 02, 2012

Re: Alternative to Power Failure trigger

Hello,

I've made a script to check if the MacMini is on UPS or not.
My UPS is an APC and natively supported on OSX.
It is detected as a "battery" (like MacBooks) so the script check if the power is on AC or on battery.
If the script detect the Mac is on battery, it sends a telnet command to my NAS to shutdown it.
It sends me also an iMessage to tell me there's a power failure at my home.

I also put a variable "powerFailure" to true, for an other script, wich check if the Mac is on AC after and if the powerFailure is
true. To send a wake-on-lan command to the NAS and send me an iMessage to tell me that the power is back at my home.

Here is a piece of code:

Code: Select all
set PowerSource to (do shell script "pmset -g ps")
if PowerSource does not contain "AC Power" then
<< here what you want to do if the power source is the battery pack >>
end if


Note that I put it in a schedule, to make that check every minutes.

Posted on
Wed Feb 13, 2013 11:59 am
bschollnick2 offline
Posts: 1355
Joined: Oct 17, 2004
Location: Rochester, Ny

Re: Alternative to Power Failure trigger

Nono wrote:
Hello,

I've made a script to check if the MacMini is on UPS or not.
My UPS is an APC and natively supported on OSX.
It is detected as a "battery" (like MacBooks) so the script check if the power is on AC or on battery.
If the script detect the Mac is on battery, it sends a telnet command to my NAS to shutdown it.
It sends me also an iMessage to tell me there's a power failure at my home.

I also put a variable "powerFailure" to true, for an other script, wich check if the Mac is on AC after and if the powerFailure is
true. To send a wake-on-lan command to the NAS and send me an iMessage to tell me that the power is back at my home.

Here is a piece of code:

Code: Select all
set PowerSource to (do shell script "pmset -g ps")
if PowerSource does not contain "AC Power" then
<< here what you want to do if the power source is the battery pack >>
end if


Note that I put it in a schedule, to make that check every minutes.


You might want to take a look at the Battery & UPS monitor plugin. It is doing what you are doing in your script, but also tracks it as a device so that you can monitor the Power Status, Battery Charge, and you can configure how often it checks the battery status.

viewtopic.php?f=33&t=9559

------
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

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 5 guests