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"] );
break;
case "disable":
http.get("http://" + plugin.Settings["HostName"] + "/admin/api.php?disable&auth="+ plugin.Settings["Token"] );
break;
default:
break;
}
onPoll();
}
function onConnect() {
console.log("connected");
}
function onDisconnect() {
console.log("disconnected");
}
function onPoll() {
console.log("polling pihole");
var response = http.get("http://" + plugin.Settings["HostName"] + "/admin/api.php?status&auth="+ plugin.Settings["Token"] );
var json = response.data;
var mainDevice = plugin.Devices["pihole"];
mainDevice.status = json.status;
}
function onSynchronizeDevices() {
}