OH3: Integrate PI-Hole via HTTP-Binding using the UI

OH3: Integrate PI-Hole via HTTP-Binding (updated to reflect @justinwilczek improvement)

Prerequisites:

HTTP-Binding installed (Settings → Add-ons → Bindings)
JSONPath-Transformation installed (Settings → Add-ons → Transformations)

Implementation:

1. Create a new HTTP-Thing manually (Settings → Things)

2. Create a new HTTP URL Thing

Set the Label of your Thing to something meaningful

Set your Base URL (replace with the IP-Adress of your PI-Hole Instance)
image

Click on show advanced to be able to set Content Type to ‚application/json‘

and the click on ‚Create Thing‘
image

Now the new Thing should be in the Thing-List

If you click on it, you get the Thing-Details

And on the second TAB the assigned Channels (which is empty until now)

Now you can add your channels one by one

for example: Domains being blocked

And to make the result visible you finally have to link an Item to this Channel

And as a result you have now a PI-Hole Thing with Channel and linked Item

You can use my Thing-Code as a reference for your own Thing

Things Code
UID: http:url:000e4c241a
label: pihole
thingTypeUID: http:url
configuration:
  authMode: BASIC
  ignoreSSLErrors: false
  baseURL: http://<YOUR-PIHOLE-IP/admin/api.php
  refresh: 30
  commandMethod: GET
  contentType: application/json
  timeout: 3000
channels:
  - id: domains_being_blocked
    channelTypeUID: http:number
    label: Domains being blocked
    description: null
    configuration:
      stateTransformation: JSONPATH:$.domains_being_blocked
  - id: dns_queries_today
    channelTypeUID: http:number
    label: DNS Queries today
    description: null
    configuration:
      stateTransformation: JSONPATH:$.dns_queries_today
  - id: ads_blocked_today
    channelTypeUID: http:number
    label: Ads blocked today
    description: null
    configuration:
      stateTransformation: JSONPATH:$.ads_blocked_today
  - id: ads_percentage_today
    channelTypeUID: http:number
    label: Ads percentage today
    description: null
    configuration:
      stateTransformation: JSONPATH:$.ads_percentage_today
  - id: unique_domains
    channelTypeUID: http:number
    label: Unique Domains
    description: null
    configuration:
      stateTransformation: JSONPATH:$.unique_domains
  - id: queries_forwarded
    channelTypeUID: http:number
    label: Queries forwarded
    description: null
    configuration:
      stateTransformation: JSONPATH:$.queries_forwarded
  - id: queries_cached
    channelTypeUID: http:number
    label: Queries cached
    description: null
    configuration:
      stateTransformation: JSONPATH:$.queries_cached
  - id: clients_ever_seen
    channelTypeUID: http:number
    label: Clients ever seen
    description: null
    configuration:
      stateTransformation: JSONPATH:$.clients_ever_seen
  - id: unique_clients
    channelTypeUID: http:number
    label: Unique Clients
    description: null
    configuration:
      stateTransformation: JSONPATH:$.unique_clients
  - id: Status
    channelTypeUID: http:string
    label: Status
    description: ""
    configuration:
      stateTransformation: JSONPATH:$.status
1 Like

Just curious if there is a specific reason not to use the State Transformation property on the HTTP thing channels to do the JSONPATH transformation instead of doing the transformation with the profile? And use number channels.

  - id: ads_blocked_today
    channelTypeUID: http:number
    label: Ads blocked today
    description: ""
    configuration:
      stateTransformation: JSONPATH:$.ads_blocked_today

you are correct. This is a ceaner way to solve this. And everything would be in the Code-Tab afterwards.
I think I will adopt this and update the Tutorial.

Updated OP with JSONPATH-Transformation at the Thing-Level

@Christian_Brosius have you also linked the enable/disable button? How have you done it?

You can send enable/disable commands through the API also.

Both of them require the API token that you can get from the API/Web interface page in the pi-hole settings. Or from the /et/pihole/setupVars.conf (the WEBPASSWORD entry in that file).

To disable: http://<piholeip>/admin/api.php?disable=<seconds>&auth=<WEBPASSWORD>
To enable: http://<piholeip>/admin/api.php?enable&auth=<WEBPASSWORD>

I think the only way to implement this is by adding two channels; one each for disable and enable.

On my instance; I have added a Number channel for disable.

In the advanced options on the channel…
image
To disable, you send a command to the linked item and it’ll stick the number into the URL and the pi-hole will get disabled for that long. A value of 0 will disable it indefinitely.

I have not hooked up anything for specific enable commands; have not figured out the best way to handle it. It could be a Switch channel, with the Command URL Extension set to ?enable&auth=<WEBPASSWORD>. This would send the enable command for both ON and OFF states; so I haven’t bothered yet.

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