Hi,
if you just want to disable all of Pi-Hole you would be better off using the official integration that will give you a service to disable Pi-Hole for a duration of your choice.
The topic here is to enable/disable specific groups in pi-hole that are not exposed via an official API (yet).
Yeah, I tried that, including adding the apikey generated from within the pi-hole instance, but the lovelace card it generates doesnāt really toggle too well. It turns on, but the toggle off doesnāt really work.
@datamonkey
Short note to thank you for sharing this. Itās exactly what I was looking for. Iāve set up as described and it just works.
As for the command line switch Iāve taken a simpler, however somewhat less secure approach. However I can live with it.
I run HA in docker and Iāve given HA access to the host docker engine, adding below to volumes:
emphasized textThank you so much for this. Itās done the job well.
I have Home Assistant now enabling/disabling Pi-Hole groups. Both are in separate docker containers.
The only issue I had is that the Lovelace switch cards didnāt appear to stay at the on position, but cycled to off, then on every 1 min. 1 min on, one min off and repeat. The actual group status in Pi-Hole was unaffected, it was just an annoyance in my dashboard.
Adding āscan_interval: 300ā to my configuration.yaml in an attempt to resolve this has only lengthened the cycle to 5 minutes. I canāt understand why the status is flipping at every scan.
Help please!
#!/bin/bash
# takes the group name and enable disable and status as input and
# updates the pihole gravity database accordingly
# then restarts the pihole dns and lists
# Data Monkey January 2021
case "$2" in
"enable")
sqlite3 /etc/pihole/gravity.db "update 'group' set 'enabled'=1 where name='$1'";
# refresh PiHole
/usr/local/bin/pihole restartdns reload-lists >/dev/null
;;
"disable")
sqlite3 /etc/pihole/gravity.db "update 'group' set 'enabled'=0 where name='$1'";
# refresh PiHole
/usr/local/bin/pihole restartdns reload-lists >/dev/null
;;
"status")
stat=`sqlite3 /etc/pihole/gravity.db " select enabled from 'group' where name = '$1';"`
echo $stat
exit 0
;;
*)
echo $"Usage: $0 {GroupName enable|disable|status}"
exit 1
esac
UPDATE:
Iāve now sort of resolved the issue using the revisions offered above by the-bort-the. Thanks.
It address the strange unwanted toggle to off in HA, but I have lost the proper status checking unfortunately. So if I toggle a group on the Pi-Hole front end HA will not update.
But Iāll try to live with that for now.
FURTHER UPDATE:
I find that updating Home Assistant breaks the connection to Pi-hole.
Running the following command within the Home Assistant container (via Portainer) fixes it for me.
ssh -i /config/.ssh/pihole USERNAME@SERVER IP ADDRESS
Thank you for this! It has been the inspiration to build a small script that exposes PiHole groups via MQTT to HA with autoconf!
I can finally automate the site-blocking āparental control styleā from Home Assistant! https://github.com/Andrec83/pihole-ha-mqtt-service/tree/main
This is a great idea.
But I am running pihole in docker, will need to see if I can make your script persistent in the docker container, that would be great!
the install script for docker integration was next in line, I added yesterday a couple of features that were missing (and did some code clean-up, although still very ugly) and was planning to work on a set-up script in the next few days. I will hold on for now since the API route is of course preferred.
This is exactly what I was looking for. I use domains and groups to define what sites are accessible and then set my childās device to the appropriate group to set the access.
Unfortunately, my HA server is accessible from the Internet via Nabu Casa cloud, so enabling ssh to root isnāt an option.
I looked at the MQTT approach but that doesnāt seem feasible for my situation.