Shutdown on Power Blackout

When you lose AC power, your backup system takes over. This project shuts down your vulnerable equipment before the UPS dies.

Aug 21, 2021

2577 views

0 respects

Components and supplies

1

USB to 2.1 mm cable

1

Belkin Wemo Smart Plug

1

NRF24 Radio

3

DIKAVS Breadboard-Friendly 2.1mm PCB Mounting Female DC Power Barrel Jack (Pack of 10)

1

Arduino Nano R3

1

Signal Relay, 5 VDC

1

UL Certified USB Wall Charger Power Supply 5v 1A (1000mA) Universal Portable Travel Power Adapter Plug

Tools and machines

1

3D Printer (generic)

Project description

Code

Power Monitor HA Automations

yaml

These Home Assistant automations send messages through gmail to alert the home owner of a loss of power and the regaining of power. In both cases, a binary switch set up by the Arduino code triggers a notification. These automations do not take any actions. Further actions are initiated by other HA automations or by the Arduino as detail in the comments at the top of the Arduino code. Several lines are commented out in this yaml file. These lines effectuate the shutdown of the PC and RPi. When commented out, neither the PC or RPi will shut down. The code is used this way during testing. Note: when testing the Wemo plug and the Power port are not connected to the PC and RPi. See the testing section of the 'Story.'

Power Monitor Arduino Code v4.1

c_cpp

The current timing of this code is set up for testing. Starting at line 81 are a list of defined times that should be adjusted to match individual system requirements.

Power Monitor Test Yaml

yaml

By removing some lines from the Home Assistant "Power Monitor" automation, tests of the system can be conducted without switching power off to the PC or Raspberry. This allows you to safely test to make sure that everything is working as it should. In my testing, I also modified the times in the Arduino code to shorten the test period. So: #define RPI_BOOT_TIME .2 // time in minutes until Raspberry has booted #define RPI_SHUTDOWN_TIME .2 // time in minutes to allow Raspberry to shutdown before switching off power #define PC_BOOT_TIME .2 // time in minutes to allow the PC to boot. Actual boot time includes RPI_BOOT_TIME #define PC_SHUTDOWN_TIME .2 // time in minutes to allow PCs to shutdown before switching off

Power Monitor Arduino Code v4.1

c_cpp

The current timing of this code is set up for testing. Starting at line 81 are a list of defined times that should be adjusted to match individual system requirements.

Set_State.py

c_cpp

This a great bit of code written by Rod Payne which is used in this project to change the state of binary sensors in Home Assistant.

Lovelace Interface

yaml

This yaml file creates a page for the Power Monitor in Home Assistant.

Set_State.py

c_cpp

This a great bit of code written by Rod Payne which is used in this project to change the state of binary sensors in Home Assistant.

Lovelace Interface

yaml

This yaml file creates a page for the Power Monitor in Home Assistant.

Power Monitor Test Yaml

yaml

By removing some lines from the Home Assistant "Power Monitor" automation, tests of the system can be conducted without switching power off to the PC or Raspberry. This allows you to safely test to make sure that everything is working as it should. In my testing, I also modified the times in the Arduino code to shorten the test period. So: #define RPI_BOOT_TIME .2 // time in minutes until Raspberry has booted #define RPI_SHUTDOWN_TIME .2 // time in minutes to allow Raspberry to shutdown before switching off power #define PC_BOOT_TIME .2 // time in minutes to allow the PC to boot. Actual boot time includes RPI_BOOT_TIME #define PC_SHUTDOWN_TIME .2 // time in minutes to allow PCs to shutdown before switching off

Power Monitor HA Automations

yaml

These Home Assistant automations send messages through gmail to alert the home owner of a loss of power and the regaining of power. In both cases, a binary switch set up by the Arduino code triggers a notification. These automations do not take any actions. Further actions are initiated by other HA automations or by the Arduino as detail in the comments at the top of the Arduino code. Several lines are commented out in this yaml file. These lines effectuate the shutdown of the PC and RPi. When commented out, neither the PC or RPi will shut down. The code is used this way during testing. Note: when testing the Wemo plug and the Power port are not connected to the PC and RPi. See the testing section of the 'Story.'

Downloadable files

Power Monitor Circuit Board

This board uses an external usb power supply to monitor the voltage on an outlet that is not backed up. If the power is lost, the Arduino will initiate a shut down process to first shut down any designated PCs on the network, if desired, it will shut down any items connected to IOT switches, and finally, will shut down the RPi. Even though I used the extra wide leads on the PCB, the current carrying capability of the board was not sufficient to power the Raspberry. Therefore, I soldered 18 awg wires to the bottom of the board connecting the positive terminals of the USB connectors directly to the relay. Then I connected the grounds of the USB connectors together.

Power Monitor Circuit Board

Power Monitor Circuit Board

This board uses an external usb power supply to monitor the voltage on an outlet that is not backed up. If the power is lost, the Arduino will initiate a shut down process to first shut down any designated PCs on the network, if desired, it will shut down any items connected to IOT switches, and finally, will shut down the RPi. Even though I used the extra wide leads on the PCB, the current carrying capability of the board was not sufficient to power the Raspberry. Therefore, I soldered 18 awg wires to the bottom of the board connecting the positive terminals of the USB connectors directly to the relay. Then I connected the grounds of the USB connectors together.

Power Monitor Circuit Board

Documentation

Power Monitor Enclosure

Power Monitor Enclosure

Power Monitor Enclosure

Power Monitor Enclosure

Power Monitor Cover

Power Monitor Cover

Comments

Only logged in users can leave comments

zavracky

0 Followers

0 Projects

0