Python Plugin: PiHole Control

Python and python framework

Moderator: leecollings

Post Reply
voyo
Posts: 40
Joined: Monday 17 February 2020 19:16
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Poland
Contact:

Python Plugin: PiHole Control

Post by voyo »

hi
I've created new version of Pi-hole plugin for PiHole v6 API, based on Xorfor's original idea. ( viewtopic.php?t=20834 )

**Features:**
- Monitor Pi-hole statistics in real-time
- Control block lists as switches in Domoticz
- Auto-sync with Pi-hole (detects added/removed lists)
- Works with Pi-hole groups for ie. parental controls

**My use case:** Schedule kids' block lists - enable YouTube blocking during homework time, disable in the evening.

**Repo:** https://github.com/voyo/Domoticz_PiHole-Control

Works with Pi-hole v6.x. Tested on v6.1.2 + Domoticz 2024.7.
sloeber70
Posts: 45
Joined: Wednesday 08 July 2020 10:59
Target OS: Linux
Domoticz version: latest
Location: Bruges
Contact:

Re: Python Plugin: PiHole Control

Post by sloeber70 »

Hi,

Nice work!!
Kind regards,
Sloeber70

Linux Debian 13 standard edition
Domoticz latest beta on ProxmoxVE Virtual Machine
WouterO
Posts: 66
Joined: Sunday 14 May 2023 19:23
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: PiHole Control

Post by WouterO »

Impressive, especially the blocklist control via timed switches adds functionality to Pihole via Domoticz, originally not available in Pihole itself. I like that!
mark.sellwood
Posts: 107
Joined: Tuesday 04 March 2014 10:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Surrey, UK
Contact:

Re: Python Plugin: PiHole Control

Post by mark.sellwood »

Great work, I have added the plugin & configured, now in Domoticz I get switches for each of Lists & I can Enable / Disable

Is it possible to control the Groups listed on PiHole under Group Management?

Thanks
3 x Pi, 1 Master, 2 Slaves, 1x Aeotec Z-Stick S2, 4xSP103 PIR, 5xPowerNode 1, 1xSmart Energy Switch Gen5, 4xFGSS101 Smoke Sensor, 2xFGD212, 9xFGS212 , 7xFGS221/2, 1xAD142 , 1xTKB TZ68E , 2xAeotec Multi Sensor, 3 x NodOn CRC-3-1-00.
voyo
Posts: 40
Joined: Monday 17 February 2020 19:16
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Poland
Contact:

Re: Python Plugin: PiHole Control

Post by voyo »

mark.sellwood wrote: Wednesday 19 November 2025 21:32 Great work, I have added the plugin & configured, now in Domoticz I get switches for each of Lists & I can Enable / Disable

Is it possible to control the Groups listed on PiHole under Group Management?

Thanks
maybe ? what functionality you'd like to achieve with groups , please elaborate ?
mark.sellwood
Posts: 107
Joined: Tuesday 04 March 2014 10:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Surrey, UK
Contact:

Re: Python Plugin: PiHole Control

Post by mark.sellwood »

Hi, I'm just looking to control the Groups in the same way as Lists Enable / Disable
3 x Pi, 1 Master, 2 Slaves, 1x Aeotec Z-Stick S2, 4xSP103 PIR, 5xPowerNode 1, 1xSmart Energy Switch Gen5, 4xFGSS101 Smoke Sensor, 2xFGD212, 9xFGS212 , 7xFGS221/2, 1xAD142 , 1xTKB TZ68E , 2xAeotec Multi Sensor, 3 x NodOn CRC-3-1-00.
voyo
Posts: 40
Joined: Monday 17 February 2020 19:16
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Poland
Contact:

Re: Python Plugin: PiHole Control

Post by voyo »

Ok, I added group functionality (same as with Lists). TBH Im not sure whether I see this useful for my usecase, not sure if I will be using it.
Beside of this - I found and fixed problem with clearing metadata (comments) when Lists status was changed, and fixed it.
Please test.
mark.sellwood
Posts: 107
Joined: Tuesday 04 March 2014 10:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Surrey, UK
Contact:

Re: Python Plugin: PiHole Control

Post by mark.sellwood »

Many thanks for making the change.
I have tested today, the groups show up correctly & the status reflects PiHole & changes when I change a Group in PiHole.

The control from Domoticz does not work, if I issue a switch command I see the below in the log but the status does not change in PiHole.
2025-11-22 20:04:29.181 PiHole: Successfully set group 82 ('Phone') to enabled
2025-11-22 20:04:29.184 PiHole: Group ID 82 ('Group: Phone') set to enabled
Thanks
3 x Pi, 1 Master, 2 Slaves, 1x Aeotec Z-Stick S2, 4xSP103 PIR, 5xPowerNode 1, 1xSmart Energy Switch Gen5, 4xFGSS101 Smoke Sensor, 2xFGD212, 9xFGS212 , 7xFGS221/2, 1xAD142 , 1xTKB TZ68E , 2xAeotec Multi Sensor, 3 x NodOn CRC-3-1-00.
voyo
Posts: 40
Joined: Monday 17 February 2020 19:16
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Poland
Contact:

Re: Python Plugin: PiHole Control

Post by voyo »

Wasted 2 hours debugging why group control wasn't working - turns out Pi-hole's API uses group NAME in the URL not ID (like /api/groups/TV instead of /api/groups/3), even though it returns success either way. Classic API inconsistency.

Had to open browser devtools and watch what the actual UI sends because the docs don't mention this anywhere. Fixed in latest commit , thanks God for Claude and LLMs :D
PLease check
mark.sellwood
Posts: 107
Joined: Tuesday 04 March 2014 10:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Surrey, UK
Contact:

Re: Python Plugin: PiHole Control

Post by mark.sellwood »

Thanks or the update.
Using the ID would be the best way as I have found an issue using a Groups name

If the Group Name has a space in it switching fails One of my Groups is named "Black List"
2025-11-23 08:21:53.057 Error: PiHole: Error setting group state: URL can't contain control characters. '/api/groups/"Black List"' (found at least ' ')
2025-11-23 08:21:53.057 Error: PiHole: Failed to change state of group ID 74
3 x Pi, 1 Master, 2 Slaves, 1x Aeotec Z-Stick S2, 4xSP103 PIR, 5xPowerNode 1, 1xSmart Energy Switch Gen5, 4xFGSS101 Smoke Sensor, 2xFGD212, 9xFGS212 , 7xFGS221/2, 1xAD142 , 1xTKB TZ68E , 2xAeotec Multi Sensor, 3 x NodOn CRC-3-1-00.
voyo
Posts: 40
Joined: Monday 17 February 2020 19:16
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Poland
Contact:

Re: Python Plugin: PiHole Control

Post by voyo »

Im afraid this is Pihole fault. It is just not supporting groups with multiple words in name.
Check it yourself - try to add such group using PiHole interface directly.

This is my try (I especially upgraded to latest-greatest pihole version)
Bez tytułu.png
Bez tytułu.png (71.9 KiB) Viewed 163 times
voyo
Posts: 40
Joined: Monday 17 February 2020 19:16
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Poland
Contact:

Re: Python Plugin: PiHole Control

Post by voyo »

Ok, I played some more. It helped when I added group with ' " ' ("test group") .
New fixed code is available, please check :)
mark.sellwood
Posts: 107
Joined: Tuesday 04 March 2014 10:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Surrey, UK
Contact:

Re: Python Plugin: PiHole Control

Post by mark.sellwood »

Many thanks for the great work, works fine.
3 x Pi, 1 Master, 2 Slaves, 1x Aeotec Z-Stick S2, 4xSP103 PIR, 5xPowerNode 1, 1xSmart Energy Switch Gen5, 4xFGSS101 Smoke Sensor, 2xFGD212, 9xFGS212 , 7xFGS221/2, 1xAD142 , 1xTKB TZ68E , 2xAeotec Multi Sensor, 3 x NodOn CRC-3-1-00.
JayDotR
Posts: 11
Joined: Thursday 02 January 2025 21:15
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Lux
Contact:

Re: Python Plugin: PiHole Control

Post by JayDotR »

Big like for your work and time invested to make an old version of the plugin working again (also for me). I permitted myself to make a branch of your code is working when the PiHole is not using http, but https :)

https://github.com/janreimen/Domoticz-PiHole-Control
--
Domoticz Beta on Raspberry 3b (2x), and 4 (2x) on Rasbian Bullseye / Raspbian Bookworm / OSMC
Using: PiHole, SolarEdge Modbus, Sainlogic / Weather Underground, MQTT, Fritzbox, P1 Meter(s), dzvents Scripting
User avatar
waltervl
Posts: 6677
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Python Plugin: PiHole Control

Post by waltervl »

JayDotR wrote: Saturday 03 January 2026 21:39 Big like for your work and time invested to make an old version of the plugin working again (also for me). I permitted myself to make a branch of your code is working when the PiHole is not using http, but https :)

https://github.com/janreimen/Domoticz-PiHole-Control
It would be more helpful to the community that you made a PR on the original plugin as then there is just one plugin to look at.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
voyo
Posts: 40
Joined: Monday 17 February 2020 19:16
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Poland
Contact:

Re: Python Plugin: PiHole Control

Post by voyo »

JayDotR wrote: Saturday 03 January 2026 21:39 Big like for your work and time invested to make an old version of the plugin working again (also for me). I permitted myself to make a branch of your code is working when the PiHole is not using http, but https :)

https://github.com/janreimen/Domoticz-PiHole-Control
This is a bad approach. The plugin shouldn’t add an option to patch chain.pem just to support self-signed certs or your own CA - that’s a hack and will create maintenance problems down the line. If you really want to experiment, you could modify the plugin to ignore self-signed cert issues, but that’s a workaround at best. The proper way is to add the cert system-wide so all applications trust it, keeping things stable and maintainable.
But now its your branch , enjoy ;)
(but please only correct credits, its 'Voyo' not 'YoYo' )
JayDotR
Posts: 11
Joined: Thursday 02 January 2025 21:15
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Lux
Contact:

Re: Python Plugin: PiHole Control

Post by JayDotR »

I will fix your credits, thanks for making me aware of the Typo.

For the http/https point, ignoring the checks on ssl is from the "Secure by design" Scheme a no-go (I am working in IT, so I am perhaps "work-damaged" over the years). My certs and RootCA/SubCA were known systemwide, and as the Raspberry is part of an IT Network, it has to follow the standards of the infra ;)
--
Domoticz Beta on Raspberry 3b (2x), and 4 (2x) on Rasbian Bullseye / Raspbian Bookworm / OSMC
Using: PiHole, SolarEdge Modbus, Sainlogic / Weather Underground, MQTT, Fritzbox, P1 Meter(s), dzvents Scripting
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest