Here it is, my own little pi-hole ad blocker which I managed to build from scratch using my own hands.
Some helpful references:
# Pi-hole Network-wide Ad Blocking https://pi-hole.net/ ## Pi-hole Made EASY - A Complete Tutorial https://www.youtube.com/watch?v=e_EfmKdP2ng ## The Firebog - The Big Blocklist Collection: https://firebog.net/ ## Commonly whitelisted domains: https://discourse.pi-hole.net/t/commonly-whitelisted-domains/212 ## Barton Bytes DNS over TLS: https://bartonbytes.com/posts/configure-pi-hole-for-dns-over-tls/ ## How to Install Raspberry Pi 5 & X1200 UPS & X1200-C1 Metal Case: https://www.youtube.com/watch?v=sKlRIPLSck0&t=52s ## Unbound - Pi-hole as All-Around DNS Solution Secure dns for all outgoing requests. https://docs.pi-hole.net/guides/dns/unbound/ ## Geekworm X2100 Geekworm X1200 2-Cell 18650 5.1V 5A UPS HAT for Raspberry Pi 5 Series https://geekworm.com/products/x1200?srsltid=AfmBOor9h0PNlO8EVIuuWLLGBZGXh7ELEwD9iLnNudADdCC7Myor7kk2 ## Wiki https://wiki.geekworm.com/X1200 ## https://www.nkon.nl/en/ Samsung INR18650-35E 3400mAh - 8A (production year 2025) ## Power management script for monitoring supply and authomatic shutdown at threshhold: https://suptronics.com/Raspberrypi/Power_mgmt/x120x-v1.0_software.html ## More blacklists: https://pastebin.com/h1sSSSjH ## Checking your Raspberry Pi's view of its power supply https://share.google/DrBWsob6fZowYGTDb ## Pi.alert https://github.com/pucherot/Pi.Alert
Crontab low voltage shutdown (according to ChatGPT):
You don't actually use *crontab itself* to detect the low voltage -- you use a small script that checks the voltage status, and then you schedule that script in crontab.
On a Raspberry Pi, the usual way to detect undervoltage is via:
```bash
vcgencmd get_throttled
```
This returns a hex bitmask. If bit 0 or 16 is set, the Pi is/was undervolted.
Below is a complete solution:
---
## 1. Enable `vcgencmd` and test it
Make sure `vcgencmd` works:
```bash
vcgencmd get_throttled
```
You should see something like:
```text
throttled=0x0
```
If it's nonzero, some throttle/undervolt flags are set.
---
## 2. Create the low-voltage check script
Create a script, e.g.:
```bash
sudo nano /usr/local/sbin/check_low_voltage.sh
```
Paste this into it:
```bash
#!/bin/bash
# Simple low-voltage check for Raspberry Pi
# Uses vcgencmd get_throttled and performs a controlled shutdown
# if undervoltage is detected.
LOGFILE="/var/log/low_voltage_monitor.log"
# Ensure vcgencmd exists
if ! command -v vcgencmd >/dev/null 2>&1; then
echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR: vcgencmd not found" >> "$LOGFILE"
exit 1
fi
THROTTLED_RAW=$(vcgencmd get_throttled 2>/dev/null)
# Expected format: "throttled=0x50000" or similar
VALUE_HEX=$(echo "$THROTTLED_RAW" | awk -F= '{print $2}')
# Strip leading "0x" if present
VALUE_HEX=${VALUE_HEX#0x}
# Convert hex to decimal
VALUE_DEC=$((16#$VALUE_HEX))
# Bit 0 (0x00001): under-voltage currently detected
# Bit 16 (0x10000): under-voltage has occurred since last reboot
UNDER_VOLTAGE_NOW=$((VALUE_DEC & 0x1))
UNDER_VOLTAGE_PAST=$((VALUE_DEC & 0x10000))
if [ "$UNDER_VOLTAGE_NOW" -ne 0 ]; then
echo "$(date '+%Y-%m-%d %H:%M:%S') - CRITICAL: undervoltage detected now (throttled=$THROTTLED_RAW). Initiating shutdown." >> "$LOGFILE"
/usr/sbin/shutdown -h now "Undervoltage detected - shutting down to protect system."
elif [ "$UNDER_VOLTAGE_PAST" -ne 0 ]; then
# Optional: treat "has occurred" as a warning only
echo "$(date '+%Y-%m-%d %H:%M:%S') - WARNING: undervoltage has occurred in the past (throttled=$THROTTLED_RAW)." >> "$LOGFILE"
else
# All good
echo "$(date '+%Y-%m-%d %H:%M:%S') - OK: no undervoltage (throttled=$THROTTLED_RAW)." >> "$LOGFILE"
fi
```
Save and exit.
Make it executable:
```bash
sudo chmod +x /usr/local/sbin/check_low_voltage.sh
```
### About "threshold"
The Pi doesn't let you specify a numeric voltage threshold directly; it just flags "undervoltage" based on its own internal threshold (~4.63 V on 5 V rail). The script above treats *any* active undervoltage flag as critical and shuts down.
If you want a "softer" threshold, you can, for example, only shut down after multiple consecutive detections -- I can add that logic if you'd like.
---
## 3. Add to root's crontab
Edit root's crontab:
```bash
sudo crontab -e
```
Add a line like this to check every minute:
```cron
* * * * * /usr/local/sbin/check_low_voltage.sh
```
Or every 5 minutes:
```cron
*/5 * * * * /usr/local/sbin/check_low_voltage.sh
```
Cron will run it as root, which is required to call `shutdown`.
---
## 4. Quick test (without actually shutting down)
Before enabling the real shutdown, you can comment out the `shutdown` line and replace it with an `echo`, run the script manually, then restore the shutdown command once you're confident:
```bash
sudo /usr/local/sbin/check_low_voltage.sh
tail -n 20 /var/log/low_voltage_monitor.log
```
---
If you tell me how aggressive you want the shutdown behavior (immediate vs. after X consecutive low-voltage detections), I can tweak the script to include counters and a configurable "threshold" for number of hits.