( function (input) { var parsedInput = JSON.parse(input); if (parsedInput.status === 'enabled') { return 'ON'; } return 'OFF'; } )(input);
rule
rule "Enable PiHole"
when
Item item_pihole_enabled received command ON
then
var String HTTPString = "http://pi.hole/admin/api.php?enable&auth=API_TOKEN" HTTPString.sendHttpGetRequest(20000); end rule "Disable PiHole" when Item item_pihole_enabled received command OFF then var String HTTPString = "http://pi.hole/admin/api.php?disable&auth=API_TOKEN" HTTPString.sendHttpGetRequest(20000);
end
my OH3 thing
Thing http:url:pihole "pihole api" [ baseURL="http://pihole.fritz.box/admin/api.php", refresh=3600] {
Channels:
Type number : PiHole_DomainsBeingBlocked "Domains being blocked [%d]" [ stateTransformation="JSONPATH:$.domains_being_blocked" ]
}
I’ve been moving to a UI based config and done things slightly different in that I have a Proxy item to switch the status of PiHole - easy to define as it wouldn’t be assigned a channel:
Switch PiHole_Toggle "PiHole" ["Switchable"]
I then use a rule that updates the toggle in case the PiHole admin interface is used to disable it (note: there will be a delay in the update depending on your refresh interval). The rule is triggered by a the status item changing.
I want to disable or enable my pihole instance this is done by the URL
pihole.fritz.box/admin/api.php?enable&auth=token
But with my switch it is not possible to enable or disable the pihole instance and with this “stateTransformation: JSONPATH:$.status” I want that my switch is “on” when pihole.fritz.box/admin/api.php json status is shown “enable” and “OFF” when the api.php shows disable.