Pi-hole Virtual Switch for Hubitat (Updated for v6 API & HPM)

Pi-hole Virtual Switch for Hubitat

This is an enhanced version of the Pi-hole Virtual Switch for Hubitat, originally created by Nick Veenstra, with contributions from cuboy29, harriscd, and Jed Brown. This driver allows you to control your Pi-hole instance from Hubitat, enabling on/off toggling, status checks, and automation integration.

:rocket: Features

  • :white_check_mark: Enable or disable Pi-hole via a virtual switch in Hubitat.
  • :arrows_counterclockwise: Check the current status of Pi-hole.
  • :zap: Updated to comply with Pi-hole v6 API changes.
  • :package: Now installable via [Hubitat Package Manager (HPM)] (GitHub - HubitatCommunity/hubitatpackagemanager).
  • :hammer_and_wrench: Improved code structure, better logging, and added authentication handling.

:arrows_counterclockwise: Why This Version?

With the release of Pi-hole v6, the API structure changed, requiring updates to the original driver. This version ensures compatibility with the latest Pi-hole release while improving maintainability, security, and performance.

:package: Installation

Hubitat Package Manager (Recommended)

  1. Open Hubitat Package Manager in your Hubitat interface.
  2. Choose InstallSearch by Keywords.
  3. Search for Pi-hole Virtual Switch.
  4. Click Install and follow the on-screen instructions.

Manual Installation

  1. Open Hubitat Web InterfaceDrivers Code.
  2. Click + New Driver and paste the contents of pi-hole-virtual-switch.groovy.
  3. Save the driver.
  4. Go to DevicesAdd Virtual Device and select Pi-hole Virtual Switch as the driver.

:gear: Configuration

  1. After installing, open the device page in Hubitat.
  2. Enter your Pi-hole API key and server URL in the device preferences.
  3. Save the settings.
  4. Use Hubitat automation or dashboards to toggle Pi-hole on/off.

:arrows_counterclockwise: Updates

To update the driver via HPM:

  1. Open Hubitat Package Manager.
  2. Select UpdateCheck for Updates.
  3. If an update is available, follow the instructions to install.

:trophy: Credits

This project is based on the original Pi-hole Virtual Switch by Nick Veenstra, cuboy29, harriscd, and Jed Brown.

Major updates for Pi-hole v6 compatibility and HPM support were made by WalksOnAir.

3 Likes

Trying this out.

Issue 1: Couldn't get this from HPM. I assume that it just needs time to show up on the search. That turns out to be a good thing, because I needed to modify the code to get it to work for my environment...

Issue 2: This doesn't seem to support alternative ports. My Pi-Holes run on a non-standard port, but port 80 is hard-coded into the driver.

I just submitted a PR on GitHub to create a user-selectable "devicePort" with a default value of 80.

1 Like

Thanks for the feedback, @Alan_F . I merged your code and also updated credits to include your contribution :slight_smile:

I also am having difficulty getting HPM to install the driver...I do see a Unable to Refresh null when I try to match up driver code so will have to trouble shoot with HPM. The local install method with HPM went smoothly so I'm not sure where the hiccup is...will investigate and fix asap.

Thanks again for the quick feedback! Keep em coming :coffee: !
WoA

1 Like

I wasn’t able to get it working. Running pihole 6 and since the update I can’t get to pihole on port 80, only 8080, so maybe that’s why. I’m running pihole on a desktop Ubuntu install.

Did you get the latest code that was just pushed up to the Github repo? Alan_F added a preference field where you can specify the port as 8080.

@walksonair - Thanks for updating and posting this. I didn't know the old version existed, but this will be really useful for me going forward. I run dual PiHoles, so I put a switch on my Node Red dashboard (that I use as a LAN home page) that toggles both switches at once. This is something my wife can find and use much more easily when she needs it compared to logging into the PiHoles and disabling them through their UI.

I'm curious how many people are running two PiHoles vs a single one. I may try to modify this to accept two IPs and two ports if I can do that without messing up the interface for people who only use one. Maybe with comma-separated IPs and ports, it could handle N instances and just loop through the list, but not need any new input when entering a single IP and port. EDIT: After looking through the code, I think it's going to be much easier to just use Rule Machine to create another virtual switch that toggles all PiHole switches on and off.

Your welcome. I only have the one Pi-hole and I have it linked to my HomeKit so my family uses their iOS devices to temp disable whenever they need it.

I would create two virtual devices with different IPs and different names and that way you can get them into a Rule Machine algo to keep them synced...just like you said :slight_smile:

Not yet. I’m unfortunately at work right now, but I really appreciate you offering this driver. My wife is not a tech person and I haven’t coded anything since grade school. I have a spare Hue dimmer that is set to turn on her PC with button 1, and plan to make button 4 turn off pihole. I had it working in Homebridge until the update killed it.

Yeah the latest API change drove me to update this asap...couldve merged it with the original code but wanted some slight changes so made it as a new repo with HPM support. Still debugging the HPM stuff so manual install is the only way for now...

1 Like

Could there be another web server running on your Ubuntu machine that’s using port 80?

I think I found where my issue was with getting this into HPM. Created a new PR so hopefully it will get sorted soon.

1 Like

The only thing on it is pihole, homebridge, home assistant, echo speaks, and an ntp server. I only get by on Linux by googling, but it happened as soon as I updated. My shortcut stopped working and I had to add an extra 80.

I just upgraded my Pi-hole from v5 to v6 and I noticed this in the announcement on the pi-hole project website:

During the upgrade operation, you will be presented with a dialog box asking if you wish to disable lighttpd . Doing so is probably appropriate for most users – unless you are using it to host web pages other than Pi-hole’s, in which case you may choose to keep it enabled. With lighttpd disabled, pihole-FTL will attempt to bind to ports 80 for HTTP and 443 for HTTPS. If there is any conflict on these ports, then it will revert to port 8080 for HTTP.

Could the lighttpd daemon (no longer needed) still be running on port 80 of your Pi?

1 Like

I remember having to disable and remove lighttpd after updating to pihole v6...

I ran the following commands:

  1. Check what's running on port 80:
    sudo ss -nltp | grep 80
  1. Stop, disable and remove lighttpd:
    sudo systemctl stop lighttpd
    sudo systemctl disable lighttpd
    sudo apt remove lighttpd -y

Pi-hole was the only thing using lighttpd so it was no issue for me to remove it.

2 Likes

@here HPM driver installation is available now. Thanks to CSteele for helping with HPM issue.

3 Likes

Port 8080 fixed it and the driver is working. Thanks for this and the pointers. I’ll see what I can find out when I have more energy.

3 Likes

works great, thanks

I installed this because I use pihole. Awesome, thank you!

I am just trying to understand why I would want to turn all of pihole off. My wife was blocked from googleads links last week and complained to me. Before I could implement this switch, she found out that disconnecting from WiFi “fixed” it for her. Then I thought to myself, why turn off all of pihole, even temporarily, for all devices. For her to shop, i would be allowing all that other blocked traffic from 60+ devices.

Is it possible to have a switch disable a rule? Or a group? She wants to shop -> turn on a switch -> only her phone (only device in its own group) is allowed googleads -> switch turns off automatically after 30 minutes.

1 Like

You can specify per client blocking

https://docs.pi-hole.net/group_management/example/

Thank you. I am aware of the group management. I am wondering if the the Pi-hole virtual switch can control (on/off) a group/client, or specific rule?