Basic Pi-hole plugin

I made this crude plugin to turn my PiHole on and off.
I’m sure it can be improved. My next step is to add timed disables.
Since the poll time is long, I’m calling onPoll immediately after changing status, to update the display faster.

plugin.Name = "Pihole";
plugin.OnChangeRequest = onChangeRequest;
plugin.OnConnect = onConnect;
plugin.OnDisconnect = onDisconnect;
plugin.OnPoll = onPoll;
plugin.OnSynchronizeDevices = onSynchronizeDevices;
plugin.PollingInterval = 60000;
plugin.DefaultSettings = {};

var http = new HTTPClient();

function onChangeRequest(device, attribute, value) {
        switch (value) {
            case "enable":
                http.get("http://" + plugin.Settings["HostName"] + "/admin/api.php?enable&auth="+ plugin.Settings["Token"] );
            case "disable":
                http.get("http://" + plugin.Settings["HostName"] + "/admin/api.php?disable&auth="+ plugin.Settings["Token"] );

function onConnect() {

function onDisconnect() {

function onPoll() {
    console.log("polling pihole");
    var response = http.get("http://" + plugin.Settings["HostName"] + "/admin/api.php?status&auth="+ plugin.Settings["Token"] );
    var json =;  
    var mainDevice = plugin.Devices["pihole"];
    mainDevice.status = json.status;

function onSynchronizeDevices() {
1 Like

Did you notice a significant difference after using pi-hole? I have a spare RPi and I was thinking of some uses for it, this was on my list.

Yes. Highly recommended. Web pages are a lot cleaner.