Nazaudy, a spark in your curious mind

Configure PowerChute Personal Edition to send e-mails

In this article I explain how to configure PowerChute Personal Edition to send e-mails so that you get alerted when there is a power outage

You might have an UPS (Uninterruptible Power Supply) at home if you are reading this article. I personally have an APC Power-Saving-Back BR550GI that I bought in Amazon, excellent value, it's tiny, quiet and perfect to protect a home computer:

A detailed page from the manufacturer here: https://www.apc.com/shop/

Once you have installed on your machine, and with the USB cable connected to it, you can download and install the APC PowerChute Personal Edition software to manage the computer in your system, and tell it how to responds to blackouts and power cuts. Go and download the free-of-charge software from here, version 3.1.0 is only available for Windows Operating Systemshttps://www.apc.com/shop/uk/

For some mysterious reason, at the time of writing this article,  APC has not included the extension on its download, therefore when you download the file, please add the .exe extension to it so that you can run it

 APC PowerChute

Once you completed the installation, you should find yourself having the version 3.1.0 installed, and correctly detecting your UPS (if you have connected the USB cable). See on my example how I only have 13 minutes left of battery, not much but enough to safely shutdown my PC in case of a blackout, preventing loss of data

 PowerChute Personal Edition

The problem is that PowerChute Personal Edition does not contain any means of sending you an e-mail in case of a power failure, so how do we do this? Well, let's dive into it

  1. Get a G-mail account ready
  2. Configuration of e-mails when there is a power cut
  3. Configuration of e-mails when the power is back
  4. The testing

 

1. Get a G-mail account ready

If you don't have one already, create an account in G-mail and configure it with low security settings, so that other programs can use it to send e-mails

Update March 2022: Please follow this other guide to enable App Passwords on your Google account, it is a much safer way to the one I propose below, which instructions I left for references purposes but have crossed out; Thanks so much Koleman for the tip!

https://technastic.com/allow-less-secure-apps-to-sign-in-google-account/

 

Click on this link to enable "less secure apps" in this on your account

https://myaccount.google.com/

Gmail - less secure app access

And this one too, to disable the Captcha access:

https://www.google.com/accounts/

Gmail - Allow access to your Google Account

 

 

2. Configuration of e-mails when there is a power cut

Fortunately for us, if you explore the Application log in your Windows computer, you will notice that PowerChute generates two messages in the event of power failures:

  • Event ID 174: Battery backup transferred to battery power due to a blackout.
  • Event ID 61455: Battery backup transferred to AC utility power.

Event ID 132

In this article of Configure PowerChute Personal Edition to send e-mails, what we are going to do is to use these 2 handy events to configure a script that will send us an e-mail when these events are logged, notifying us a power cut and a sub sequence power restore

Open notepad and paste on a new file the following powershell script (that needs to be save later on with the *.ps1 extension). Modify the "$to", "$Username" and "$Password" to match those of your own:

$Title = "A power FAILURE has occurred in your UPS " + (Get-Date)
$to = "<This email address is being protected from spambots. You need JavaScript enabled to view it.>"
$SMTPServer = "smtp.gmail.com"
$SMTPPort = "587"
$Username = "This email address is being protected from spambots. You need JavaScript enabled to view it."
$Password = "YourOwnCall"
$smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort);
$smtp.EnableSSL = $true
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
$message = New-Object System.Net.Mail.MailMessage
$message.subject = $Title
$message.to.add($to)
$message.from = $username
$smtp.send($message)

Save the file as PowerOffMail.ps1 and keep in a location of your choice, then copy and paste that file into the C:\Program Files (x86)\APC directory

Configure PowerChute Personal Edition to send e-mails

Before moving any further to configure PowerChute Personal Edition to send e-mails, we need to ensure that our computer will be able to run that script without problems, for that we'll set the Local Machine policy for PowerShell to "RemoteSigned". Open a privilege powershell window on your computer and then execute this command:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine

Enable PowerShell

 

Once you have the LocalMachine set to "RemoteSigned", open the Computer Management in your machine > Task Scheduler > Task Scheduler Library, and create a new Basic Task called "Power Off Send Mail"

 Create Scheduled Tasks for Testing the configuration email messages for Configure PowerChute Personal Edition to send e-mails

Choose the trigger "When a specific event is logged"

When a specific event is logged

For the next window, choose the Application Folder > select the "APC UPS Service" and type "174" in the Event ID box, meaning that every time event 174 is trigger this task will be activated

APC UPS Service

For the next screen, type "powershell" under the field Program/Script, then on the Add Arguments (Optional) field, paste this the following string:

-file "C:\Program Files (x86)\APC\PowerOffMail.ps1"

Your configuration should look something like this:

Start a program PowerShell

That should be all, your Task should be set with the status of "Ready", just waiting to come into action once Event ID 174 is logged

send e-mails

 

3. Configuration of e-mails when the power is back

You might want to create another script and associated another task to that script, so that when Event ID 61455 (power restored) occurs, you are notified too by e-mail

This is the script I created for a file called "PowerOnMail.ps1", basically just change the $Title field to something meaningful related to a power restore:

$Title = "Power has been RESTORED to your UPS " + (Get-Date)
$to = "<This email address is being protected from spambots. You need JavaScript enabled to view it.>"
$SMTPServer = "smtp.gmail.com"
$SMTPPort = "587"
$Username = "This email address is being protected from spambots. You need JavaScript enabled to view it."
$Password = "YourOwnCall"
$smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort);
$smtp.EnableSSL = $true
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
$message = New-Object System.Net.Mail.MailMessage
$message.subject = $Title
$message.to.add($to)
$message.from = $username
$smtp.send($message)

This is how the 2 x scripts should look in your "APC" folder:

The scripts to configure PowerChute Personal Edition

And see here configured the two tasks side by side, each one of them should be pointing to their corresponding powershell script

 Tasks are Ready

 

4. The testing

Obviously, I cannot finish this article without telling you to test this configuration, so be brave (but just in case save all your work and close all of your windows, including the one to the garden! haha), yes be brave and pull the power cord from your UPS, wait two or three minutes and then connect it back again. Hopefully your UPS battery will have enough capacity to provide power for these 2/3 minutes of the testing, and you'll have received on your inbox the events of power off and the sub-sequence power restore.

See below my screenshot. I manually turn off my UPS for about 3 minutes, and yah, I did receive the off and restore e-mails as configured. You'll see on your computer a brief display of a powershell window when the scripts activates both ways. If you wish this can be disable this with the "-hide" switch in the arguments of the task, but I prefer to have it on, so you can verify that the script is executed. Jolly good that it all worked! 

 

Testing the configuration email messages for Configure PowerChute Personal Edition to send e-mails

 

The elephant in the room: your router needs to be connected to the UPS too, so that the computer has Internet access when a power cuts occurs, otherwise as you can imagine there is no chance those emails will magically be send out

Thank you for reading! And I hope this guide helps you

London, 26 June 2019