Domain / RegEx - enable disable command or pihole -b command with group option

Hi,
I can run command to add RegEx in my Pi-Hole (Raspberry Pi ZERO W), however I'm using groups to distinguish my devices.
It seems that it's not possible to add specific domain to the black list and setup group assigment on it.
So I was trying find a way to update existing entry in the domain list with specific group assigment.

Is there any way to do it with command or API?

It is possible, but not with a single command.

See this topic, as there was a similar question. You need to adjust the sql commands to your needs, but it should give you a feeling how to accomplish what you want

1 Like

This is amazing, Thank You!

I was not aware it's so easy. One is more than enough,
I will just assign domains to another group ( group_id=1 ) and update status (enable or disable) for all of them.

enabled => 0 = disabled, 1 = enabled)

sudo sqlite3 /etc/pihole/gravity.db "Update domainlist SET enabled = 0 WHERE id in (Select domainlist_id from domainlist_by_group where group_id=1);"

https://docs.pi-hole.net/database/gravity/#domain-tables-domainlist

But it still would be nice to do it with API and HomeAssistant Integration..

There will be an API with Pi-hole v6.0 one day...

1 Like

Just for sharing.. finally I'v intergrated pihole with my Home Assistant.

Now I'm able to disable and enable all fun domeins in specific group, with one click, or Home Assistant automation. This takes away one more distraction from my kid during remote clases. Kind of parental control :wink:

Due to my Adlist, some domains has to be on white list, therfore final version of script in addition is enabling whtelist, when blacklist is turned off (and the other way around).

#Black List ON 
sudo sqlite3 /etc/pihole/gravity.db "UPDATE domainlist SET enabled = 1 WHERE type IN (1,3) AND id IN (SELECT domainlist_id FROM domainlist_by_group WHERE group_id=1);" && sudo sqlite3 /etc/pihole/gravity.db "UPDATE domainlist SET enabled = 0 WHERE type IN (2,4) AND id IN (SELECT domainlist_id FROM domainlist_by_group WHERE group_id=1);"

#Black List OFF
sudo sqlite3 /etc/pihole/gravity.db "UPDATE domainlist SET enabled = 0 WHERE type IN (1,3) AND id IN (SELECT domainlist_id FROM domainlist_by_group WHERE group_id=1);" && sudo sqlite3 /etc/pihole/gravity.db "UPDATE domainlist SET enabled = 1 WHERE type IN (2,4) AND id IN (SELECT domainlist_id FROM domainlist_by_group WHERE group_id=1);"

#For HA swich state:
sudo sqlite3 /etc/pihole/gravity.db "SELECT enabled FROM domainlist WHERE type IN (1,3) AND id in (Select domainlist_id from domainlist_by_group where group_id=1) LIMIT 1;"

I didn't tried to achieve similar on Group level, as I would probably need separate groups for Black and White list.

Hi, As I noticed that directly updateing the database does not give immediate effect to block/unblock domains, so I had to add a restart in addition.

I've tried to use
pihole restartdns

but the option below works much faster.
&& pihole disable && pihole enable

Is there any better way to do it? When I change the domain status manually, the results are instantly updated.

Thank You in advance

From pihole -h

restartdns          Full restart Pi-hole subsystems
                        Add 'reload' to update the lists and flush the cache without restarting the DNS server
                        Add 'reload-lists' to only update the lists WITHOUT flushing the cache or restarting the DNS server

So, to make Pi-hole aware of the changes pihole restartdns reload-lists is sufficient (and much faster than a full restart). This is also what happens if you change the status via web interface.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.