Pi-Hole (ad blocking DNS server) Controller

Plugins that users have built. NOTE: plugins that were developed for Indigo versions older than 2022.1 will have to be updated to work with Indigo 2022.1 (Python 3 - see this blog post for details). If the plugin listed here is not in the Plugin Store (which will show updated plugins) then you will need to ask on the appropriate thread below if it has been updated and where you get get the update.
MarcoGT
Posts: 1148
Joined: Thu Sep 11, 2014 1:06 pm
Location: Germany

Re: Pi-Hole (ad blocking DNS server) Controller

Post by MarcoGT »

Same here, but I read the release not of PiHole and I saw they changed same thing APIs related; I have to have a better look at
sumocomputers
Posts: 268
Joined: Mon Jun 23, 2008 10:46 pm

Re: Pi-Hole (ad blocking DNS server) Controller

Post by sumocomputers »

madscientist
Posts: 122
Joined: Fri Jan 05, 2007 10:13 pm
Location: Ontario, Canada

Re: Pi-Hole (ad blocking DNS server) Controller

Post by madscientist »

I am also getting this error with the current Pi-Hole controller release:
Pi Hole DNS Controller Error Error in plugin execution runConcurrentThread:

File "plugin.py", line 164, in runConcurrentThread
File "plugin.py", line 141, in udpateStatus
type: local variable 'response' referenced before assignment

Pi Hole DNS Controller Error plugin runConcurrentThread function returned or failed (will attempt again in 10 seconds)
The plug-in still works though. I can turn the ad blocker on and off from Indigo. But my Indigo logs are getting inundated with these error messages.

Has a solution to this problem been identified yet?
sumocomputers
Posts: 268
Joined: Mon Jun 23, 2008 10:46 pm

Python Scripts to Disable or Enable PiHole 6 Blocking

Post by sumocomputers »

Since PiHole 6 updates, the Indigo PiHole plugin no longer works. For me there were 2 issues:

1. PiHole now requires getting an Authentication "sid" before making changes
2. When upgrading PiHole from 5 to 6, the port changed from 80 to 8080

I came up with 2 Python scripts (one to disable blocking and one to enable), which I then use with a Virtual ON/OFF device and Action Groups. I then publish the Virtual device with HomeKitLink Siri so I can just command PiHole on or off as needed with a voice command.

I know the scripts are a little hacky, but they work. Note that I have not turned on https, 2FA, or app password.

First there were 2 things I needed to do in the PiHole config:

1. Change the webserver.port value (see screenshot)
Settings > All Settings > Toggle Expert in upper right > Webserver and API > webserver.port > change from 8080 to 80

2. Change the timeout for webserver.api.max_sessions (see screenshot)
Settings > All Settings > Toggle Expert in upper right > Webserver and API > webserver.api.max_sessions > change from 16 a higher number (I used 1024)

I know there is also the ability to disable PiHole for a period of time rather than indefinitely as I did, and tons of other things you can control. Here is some API documentation:

https://docs.pi-hole.net/api/

http://pi.hole/api/docs/

Base Script Example for Disabling Blocking

Code: Select all

import requests

# URL for the Authorization POST request (using local IP in this example)
url = "https://192.168.2.15/api/auth"

# Data to be sent in the POST request ()
data = {"password": "YourActualPassword"}

# Send the POST request
response = requests.post(url, json=data, verify=False)

# Assuming the response is in JSON format and sid is a key in the response
response_data = response.json()  # Convert the response to JSON

# Retrieve the value for 'sid' from the response
sid = response_data['session']['sid']  # Get the value of 'sid' from the JSON response

# URL for the Blocking POST request (using local IP + sid in this example)
url = "https://192.168.2.15/api/dns/blocking?sid="+sid

# Data to be sent in the POST request (using False to turn off Blocking in this example)
data = {"blocking": False}

# Send the POST request
response = requests.post(url, json=data, verify=False)
Screenshot 2025-04-01 at 1.24.35 PM.png
Screenshot 2025-04-01 at 1.24.35 PM.png (75.28 KiB) Viewed 298 times
Screenshot 2025-04-01 at 1.24.22 PM.png
Screenshot 2025-04-01 at 1.24.22 PM.png (346.46 KiB) Viewed 298 times
Post Reply

Return to “User Plugins”