Monitors power outages by observing the availability of nearby WiFi networks.
I live in an area with frequent power outages. When the power goes out, I manually switch to a whole-house generator. I needed a way to be notified when grid power is restored so I can turn off the generator.
This script monitors the WiFi networks in my neighborhood. When networks that typically go down during an outage come back online, it sends a push notification to my phone. This tells me that power has been restored, and I can switch back to the grid.
This script is designed to run on a small, Linux-based single-board computer (like a Raspberry Pi) and has minimal dependencies. I run on a cheap used Orange Pi Zero that I found on eBay.
nmcli(NetworkManager command-line tool)curl(for sending ntfy notifications)- Python 3
-
Clone this repository.
git clone https://github.com/thisisjosh/WifiPowerMon
-
Configure the monitor: Edit the configuration file to specify which WiFi networks to monitor and your
ntfytopic.nano ~/WifiPowerMon/config.jsonSee the Configuration section below for details on the available options.
Edit the
wifimon.serviceto use the correct full paths for where theWifiPowerMondirectory is. -
Run the installer: The installer will set up a systemd service to run the monitor automatically.
sudo ./install.sh
The script will be started automatically by the systemd service. You can check its status or view its logs using the following commands.
Check service status:
sudo systemctl status wifimon.serviceConnect to the screen session and view the service console:
screen -r wifimonRestart the service:
sudo systemctl restart wifimon.serviceThis project uses ntfy.sh to send free push notifications to your phone.
Setup:
- Install the ntfy app on your Android or iOS device.
- Create a topic. A topic is like a channel name. It can be any string, but it's best to choose something unique and hard to guess (e.g.,
elmstreet_power_alerts_a5b2c). - Subscribe to your topic in the app.
- Update your
config.jsonwith the same topic name in theNTFY_TOPICfield.
Now, any message sent to that topic by the wifi_monitor.py script will appear as a push notification on your phone.
The config.json file contains the following options:
| Key | Description | Default |
|---|---|---|
TARGET_SSIDS |
A list of WiFi SSIDs (network names) to monitor. These should be networks that you expect to go offline during a power outage. | [] |
NTFY_TOPIC |
The topic name for your ntfy.sh push notifications. |
"" |
SCAN_INTERVAL |
The number of seconds to wait between scanning for WiFi networks. | 15 |
OFFLINE_THRESHOLD |
The number of seconds a network must be unseen before it is considered "offline". This prevents false alarms from intermittent signals. | 300 |
SIMULATION_TARGET_SSIDS |
Target SSIDs to use when running in simulation mode (--simulate). |
[] |
SIMULATION_NTFY_TOPIC |
ntfy.sh topic to use in simulation mode. |
"" |
SIMULATION_SCAN_INTERVAL |
Scan interval to use in simulation mode. | 1 |
SIMULATION_OFFLINE_THRESHOLD |
Offline threshold to use in simulation mode. | 2 |
THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.