Sign inSign up

ptsimpso/isp_monitor

By ptsimpso

Updated 2 months ago

Image
0

989

ptsimpso/isp_monitor repository overview

Internet Outage Monitor with Kasa Smart Plug Control

This project monitors your internet connection for outages and automatically power-cycles your ISP modem via a Kasa smart plug if an outage is detected. It uses python-kasa for local control of the Kasa plug, ensuring the solution works even if the internet is down.


Features

  • Customizable Connectivity Checks:
    • Pings multiple hosts (e.g., Google, Cloudflare) to verify internet availability.
    • Fails over to other hosts if the primary host is unreachable.
  • Local Control:
    • Commands the Kasa smart plug via your local network, independent of cloud services.
  • Configurable Options:
    • Define the plug's IP address, check interval, failure threshold, and retry interval via environment variables.
  • Dockerized Setup:
    • Easy to deploy using Docker and Docker Compose.
  • Reasonable Defaults:
    • Operates out-of-the-box with minimal configuration.

Requirements

  • A Kasa Smart Plug (e.g., Kasa Smart Plug Mini) with local control enabled.
  • A server or device running Docker and Docker Compose.
  • Local network connectivity between the server and the Kasa plug.

Environment Variables

The following environment variables can be configured in the docker-compose.yml file:

VariableDefaultDescription
PLUG_NAMEMySmartPlugLocal name of the Kasa smart plug.
CHECK_INTERVAL60Time (in seconds) between internet connectivity checks.
FAILURE_THRESHOLD3Number of consecutive connectivity check failures required to trigger a power cycle.
RETRY_INTERVAL300Time (in seconds) to wait before rechecking after a power cycle.
CHECK_HOSTS8.8.8.8,1.1.1.1Comma-separated list of hosts to ping for internet connectivity verification.

How It Works

  1. Connectivity Check:

    • The script pings a list of hosts (e.g., 8.8.8.8, 1.1.1.1) to verify internet connectivity.
    • If all hosts fail to respond, the system increments a failure counter.
  2. Failure Detection:

    • Once the failure counter reaches the FAILURE_THRESHOLD, the system power-cycles the modem by toggling the Kasa plug off and on.
  3. Retry Mechanism:

    • After power cycling, the system waits for the RETRY_INTERVAL before resuming connectivity checks.

Logs and Monitoring

To view logs, run:

docker logs -f internet-monitor

Troubleshooting

  • Local Access to Kasa Plug: Ensure your Kasa smart plug is connected to the same network as the server running this application. Assign a static IP to the plug via your router.

  • Docker Host Network: The container uses network_mode: host to communicate with devices on your local network. This is required for local control of the Kasa plug.

  • Adjusting Host Checks: Add or remove IPs from the CHECK_HOSTS list to optimize connectivity checks for your region or ISP.


Example Use Cases

  • Home Automation: Automatically restart your ISP modem during internet outages.
  • Remote Monitoring: Keep your internet connection reliable for remote access or critical services.

Contributing

Feel free to submit issues or pull requests to improve this project.


License

This project is licensed under the MIT License. See the LICENSE file for more details.


Tag summary

Content type

Image

Digest

sha256:de27a68e9

Size

33.7 MB

Last updated

2 months ago

docker pull ptsimpso/isp_monitor