Do you have a new Version?
The Switch don’t work anymore…
Do you have a new Version?
The Switch don’t work anymore…
hey… I integrated the Pi-Hole yesterday… the switch works well in my case. I do not use a map in the channel in my case (please check that you call the URL with “disable” and not with “disabled”):
- id: status
channelTypeUID: http:switch
label: Status
description: null
configuration:
onValue: enable
offValue: disable
stateExtension: /admin/api.php?summaryRaw&auth=xxxx
commandExtension: /admin/api.php?%2$s&auth=xxxxx
stateTransformation: JSONPATH:$.status∩REGEX:s/led/le/g
Disable and enable the Pi-Hole.
Regards,
Tim
Don’t work for me… Anyone else with text based things?
When I work with your stateExtension, commandExtension my other things don’t work anymore (because of the BaseURL).
Thing http:url:pihole "Pihole" [
baseURL = "http://192.168.1.17/admin/api.php?summary&auth=xxxx",
refresh = "120",
timeout ="5000",
ignoreSSLErrors = "true"
]
{
Channels:
Type number : domains_being_blocked [
mode = "READONLY",
stateTransformation = "JSONPATH:$.domains_being_blocked"
]
Type number : dns_queries_today [
mode = "READONLY",
stateTransformation = "JSONPATH:$.dns_queries_today"
]
Type number : ads_blocked_today [
mode = "READONLY",
stateTransformation = "JSONPATH:$.ads_blocked_today"
]
Type number : ads_percentage_today [
mode = "READONLY",
stateTransformation = "JSONPATH:$.ads_percentage_today"
]
Type number : unique_domains [
mode = "READONLY",
stateTransformation = "JSONPATH:$.unique_domains"
]
Type number : queries_forwarded [
mode = "READONLY",
stateTransformation = "JSONPATH:$.queries_forwarded"
]
Type number : queries_cached [
mode = "READONLY",
stateTransformation = "JSONPATH:$.queries_cached"
]
Type number : clients_ever_seen [
mode = "READONLY",
stateTransformation = "JSONPATH:$.clients_ever_seen"
]
Type number : unique_clients [
mode = "READONLY",
stateTransformation = "JSONPATH:$.unique_clients"
]
Type number : dns_queries_all_types [
mode = "READONLY",
stateTransformation = "JSONPATH:$.dns_queries_all_types"
]
Type number : reply_NODATA [
mode = "READONLY",
stateTransformation = "JSONPATH:$.reply_NODATA"
]
Type number : reply_NXDOMAIN [
mode = "READONLY",
stateTransformation = "JSONPATH:$.reply_NXDOMAIN"
]
Type number : reply_CNAME [
mode = "READONLY",
stateTransformation = "JSONPATH:$.reply_CNAME"
]
Type number : reply_IP [
mode = "READONLY",
stateTransformation = "JSONPATH:$.reply_IP"
]
Type number : privacy_level [
mode = "READONLY",
stateTransformation = "JSONPATH:$.privacy_level"
]
Type switch : status [
mode = "READONLY",
stateTransformation = "JSONPATH:$.status",
onValue = "enabled",
offValue = "disabled"
]
Type switch : enable_disable "PiHole Command (Enable/Disable)" [
mode = "WRITEONLY",
stateExtension = "/admin/api.php?summaryRaw&auth=xxxx",
commandExtension = "/admin/api.php?%2$s&auth=xxxx",
stateTransformation = "JSONPATH:$.status∩REGEX:s/led/le/g",
onValue = "enable",
offValue = "disable"
]
//GRAVITY LAST UPDATED
Type string : file_exists [
mode = "READONLY",
stateTransformation = "JSONPATH:$.gravity_last_updated.file_exists"
]
//ABSOLUTE TIME OF LAST UPDATE
Type number : absolute [
mode = "READONLY",
stateTransformation = "JSONPATH:$.gravity_last_updated.absolute"
]
//RELATIVE TIME OF LAST UPDATE
Type number : days [
mode = "READONLY",
stateTransformation = "JSONPATH:$.gravity_last_updated.relative.days"
]
Type number : hours [
mode = "READONLY",
stateTransformation = "JSONPATH:$.gravity_last_updated.relative.hours"
]
Type number : minutes [
mode = "READONLY",
stateTransformation = "JSONPATH:$.gravity_last_updated.relative.minutes"
]
}
Great!
But… When I click the PiHole Status
card, the command is sent, and my pi-hole is disabled, however, the status of the card only changes after a couple of seconds. That is of course confusing for other users with less patience…
Why is there a delay, and is it possible to speed up the status update of the card? Maybe have it toggled immediately, along with the command that’s sent?
(My yaml knowledge and understanding is still quite small - for a so-called easy language, I find it difficult )
Now it worked for me, but the switch dont update its status. Do you have any idea?
Also i get this warning:
2024-07-10 14:25:36.433 [WARN ] [nelTransformation$TransformationStep] - Failed to use TransformationStep{serviceName='REGEX', function='s/led/le/g'}, service not found
//THING
Thing http:url:pihole "Pihole" [
authMode = "BASIC",
ignoreSSLErrors = "false",
baseURL = "http://192.168.1.17/admin/",
delay = "0",
stateMethod = "GET",
refresh = "300",
commandMethod = "GET",
timeout ="3000",
bufferSize = "2048"
]
{
Channels:
Type number : domains_being_blocked "Domains in Blockierlisten" [
mode = "READONLY",
stateExtension = "api.php?summaryRaw&auth=xxx",
stateTransformation = "JSONPATH:$.domains_being_blocked"
]
Type number : dns_queries_today "DNS Anfragen (heute)" [
mode = "READONLY",
stateExtension = "api.php?summaryRaw&auth=xxx",
stateTransformation = "JSONPATH:$.dns_queries_today"
]
Type number : ads_blocked_today "Werbung Blockiert (heute)" [
mode = "READONLY",
stateExtension = "api.php?summaryRaw&auth=xxxx",
stateTransformation = "JSONPATH:$.ads_blocked_today"
]
Type number : ads_percentage_today "Werbung Anteil (heute)" [
mode = "READONLY",
unit = "%",
stateExtension = "api.php?summaryRaw&auth=xxxx",
stateTransformation = "JSONPATH:$.ads_percentage_today"
]
Type switch : status "Webseiten Filter" [
onValue = "enable",
offValue ="disable",
stateExtension = "api.php?summaryRaw&auth=xxx",
commandExtension = "api.php?%2$s&auth=xxxx",
stateTransformation = "JSONPATH:$.status∩REGEX:s/led/le/g"
]
}
Do you install REGEX Transformation?
Now I have installed Regex. The warning is now gone.
However, the Switch still doesn’t update. Switching works.
Please double check the configuration: Pi-Hole Integration in openHAB - 360°Friends
You could also check the log. You should see the HTTP requests and could check, if the URL is the right one. You can also call the URL manually and check if the PiHole take the command (perhaps the API key is wrong).
Regards,
Tim
Checked the whole config. Now it works. Thank you!
Im trying to add the channel items as here described but I got wierd thing some of the item… I mean the full string and not the values that the jsonpath…
{
“domains_being_blocked”: “23,985,659”,
“dns_queries_today”: “16,961”,
“ads_blocked_today”: “13,048”,
“ads_percentage_today”: “76.9”,
“unique_domains”: “1,645”,
“queries_forwarded”: “2,933”,
“queries_cached”: “920”,
“clients_ever_seen”: “17”,
“unique_clients”: “15”,
“dns_queries_all_types”: “16,961”,
“reply_UNKNOWN”: “69”,
“reply_NODATA”: “688”,
“reply_NXDOMAIN”: “243”,
“reply_CNAME”: “1,971”,
“reply_IP”: “13,589”,
“reply_DOMAIN”: “385”,
“reply_RRNAME”: “2”,
“reply_SERVFAIL”: “0”,
“reply_REFUSED”: “0”,
“reply_NOTIMP”: “0”,
“reply_OTHER”: “0”,
“reply_DNSSEC”: “0”,
“reply_NONE”: “0”,
“reply_BLOB”: “14”,
“dns_queries_all_replies”: “16,961”,
“privacy_level”: “0”,
“status”: “enabled”,
“gravity_last_updated”: {
“file_exists”: true,
“absolute”: 1734873575,
“relative”: {
“days”: 0,
“hours”: 19,
“minutes”: 30
}
}
}
Note: The new version of openHAB has a separated binding to integrate Pi-Hole into openHAB.
Should we create a new thread “Pi-Hole Binding” because the binding configuation is different?
The settings are all in the documentation, so there’s no need for a new post unless you’re having trouble.
I haven’t upgraded to 4.3 yet, but in theory it’s the same as every other add-on: install the binding, add/configure a thing for Pi-Hole, and connect channels to items.
If you are looking to upgrade to PiHole 6, it seems to break the PiHole binding. Looks like they have integrated a new REST api, so still possible to access.
I recently accidentally upgraded one of my piholes to v6 which of course broke my OH integration (not based on the official binding but http binding based).
Because I still wanted to be able to disable ad blocking temporarily every now and again I just created a new config for my v6 Pi-Hole. For anyone else in the same situation I will share this with you here as a temporary workaround (or permanently if you like):
My current setup is based on two items:
pihole1_toggle (Switch)
pihole1_lastmessage (DateTime)
If you also want to read statistics from your Pi-Hole you can also follow this guide and just add more http calls and items to the update rule (see below). pihole1_toggle has an expiration timer metadata set that will send a command to re-enable the item after 15 minutes.
First create a new item:
pihole1_sid (String) ← This will hold the session id of your Pi-Hole connection.
One word about security: it’s not exactly a brilliant idea to keep login data saved as items. So please make your own risk assessment in your situation. Don’t expose this to anyone who should not be able to mess around with your Pi-Hole. You can also set Permit destructive actions via API to false on your Pi-Hole if you like. That said this should be reasonably safe in your average home setup. If you really don’t like the idea then remove the command calls to this item. This will however cause a notable delay when you‘re toggling blocking (at least on a weak Pi-Zero like where my Pi-Hole is running).
Create an expiration metadata on this item to set this item to UNDEF after 30 minutes (Pi-Hole will invalidate the token after 30 minutes unless you use it for an api call in the meantime which will reset the validity to 30 minutes).
configuration: {}
triggers:
- id: "1"
configuration:
cronExpression: 0/30 * * * * ? *
type: timer.GenericCronTrigger
conditions: []
actions:
- inputs: {}
id: "2"
configuration:
type: application/javascript
script: >-
var sid = items.pihole1_sid.state;
if (sid === "NULL" || sid == "UNDEF") {
var response = actions.HTTP.sendHttpPostRequest("http://10.9.0.252/api/auth", "application/json", "{\"password\": \"PASSWORD\"}", 5000);
sid = JSON.parse(response).session.sid;
items.pihole1_sid.sendCommand(sid);
}
try {
var headers = [];
headers["sid"] = sid;
var response = actions.HTTP.sendHttpGetRequest("http://10.9.0.252/api/dns/blocking", headers, 5000);
var enabled = JSON.parse(response).blocking === "enabled" ? "ON" : "OFF";
items.pihole1_toggle.postUpdate(enabled);
items.pihole1_lastmessage.postUpdate(time.toZDT());
items.pihole1_sid.sendCommand(sid);
}
catch(err) {
items.pihole1_sid.sendCommand("UNDEF");
}
type: script.ScriptAction
This should update your toggle item with the current blocking state of your Pi-Hole and also update the timestamp of the last message every 30 seconds. Note that the last command to the pihole1_sid item is required to reset the expiration timer on the item when you were still authenticated.
Then create a second rule that will be executed when your pihole1_toggle item receives a command:
configuration: {}
triggers:
- id: "1"
configuration:
itemName: pihole1_toggle
type: core.ItemCommandTrigger
conditions: []
actions:
- inputs: {}
id: "2"
configuration:
type: application/javascript
script: >-
var enable = event.itemCommand.toString() === "ON";
var sid = items.pihole1_sid.state;
if (sid === "NULL" || sid == "UNDEF") {
var response = actions.HTTP.sendHttpPostRequest("http://PIHOLEIP/api/auth", "application/json", "{\"password\": \"PASSWORD\"}", 5000);
sid = JSON.parse(response).session.sid;
items.pihole1_sid.sendCommand(sid);
}
var headers = [];
headers["sid"] = sid;
actions.HTTP.sendHttpPostRequest("http://PIHOLEIP/api/dns/blocking",
"application/json", "{\"blocking\": " + enable + "}", headers, 5000);
items.pihole1_sid.sendCommand(sid);
type: script.ScriptAction
And that’s it. This will allow you to control your Pi-Holes blocking state. If you don’t want to use an expiration timer on the pihole1_toggle item you may instead pass the blocking timeout directly to the api call by changing the payload to /api/dns/blocking like so:
"{\"blocking\": false, \"timeout\": " + timeout + "}"
where timeout is a var that holds the timeout in seconds for the Pi-Hole to re-enable blocking.
I’m testing a script for new PiHole version 6
You can find more information in the link
In my case, it is to have a dashboard where I can obtain information about the status of the various components used in my environment without having to open numerous different consoles.
Depending on the status, I go directly to the appropriate management console to perform the necessary actions.
Maybe this can be a useful source: Home Assistant integration doesn't currently support Pi-hole v6 - #8 by bastgau - Beta 6.0 - Pi-hole Userspace?