Pi-Hole Integration

Very late to this party, but here’s my working pihole integration in OH3 using configuration files:

Things

//THING
Thing http:url:pihole1 "Pihole1" [
	baseURL = "http://YOUR_IP_HERE/admin/api.php",
	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 [
			mode = "WRITEONLY",
			commandExtension = "?%2$s&auth=YOUR_API_KEY_HERE",
			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"
		]
}

Items

Number nPihole1_domains_being_blocked { channel="http:url:pihole1:domains_being_blocked" }
Number nPihole1_dns_queries_today { channel="http:url:pihole1:dns_queries_today" }
Number nPihole1_ads_blocked_today { channel="http:url:pihole1:ads_blocked_today" }
Number nPihole1_ads_percentage_today { channel="http:url:pihole1:ads_percentage_today" }
Number nPihole1_unique_domains { channel="http:url:pihole1:unique_domains" }
Number nPihole1_queries_forwarded { channel="http:url:pihole1:queries_forwarded" }
Number nPihole1_queries_cached { channel="http:url:pihole1:queries_cached" }
Number nPihole1_clients_ever_seen { channel="http:url:pihole1:clients_ever_seen" }
Number nPihole1_unique_clients { channel="http:url:pihole1:unique_clients" }
Number nPihole1_dns_queries_all_types { channel="http:url:pihole1:dns_queries_all_types" }
Number nPihole1_reply_NODATA { channel="http:url:pihole1:reply_NODATA" }
Number nPihole1_reply_NXDOMAIN { channel="http:url:pihole1:reply_NXDOMAIN" }
Number nPihole1_reply_CNAME { channel="http:url:pihole1:reply_CNAME" }
Number nPihole1_reply_IP { channel="http:url:pihole1:reply_IP" }
Number nPihole1_privacy_level { channel="http:url:pihole1:privacy_level" }
Switch sPihole1_status { channel="http:url:pihole1:status" }
Switch sPihole1_enable_disable { channel="http:url:pihole1:enable_disable", channel="http:url:pihole1:status" }
String strPihole1_file_exists { channel="http:url:pihole1:file_exists" }
Number nPihole1_absolute { channel="http:url:pihole1:absolute" }
Number nPihole1_days { channel="http:url:pihole1:days" }
Number nPihole1_hours { channel="http:url:pihole1:hours" }
Number nPihole1_minutes { channel="http:url:pihole1:minutes" }

This configuration provides a Switch Item sPihole1_enable_disable which you can use to enable and disable pihole from within openHAB. This switch Item is also linked to the status Channel, so it will update if pihole is enabled/disabled by another source too.

6 Likes