Page 1 of 1

How to get Pi-Hole value into Domoticz

Posted: Saturday 16 April 2016 11:54
by drenergy
Hi,

Yesterday I installed Pi-hole (pi-hole.net) on my raspberry pi. This software is to block advertisements and it's working great!

When I enter the following URL I get the current values for the number of Ads being blocked today and some other values.

http://<raspberrypi IP/admin/api.php

{"domains_being_blocked":"51,409","dns_queries_today":"3,311","ads_blocked_today":"193","ads_percentage_today":"5.8"}

Now I would like to put this values into Domoticz but I have no idea how?

Anyone know an easy way to accomplish this?

Thanks in advance!

Re: How to get Pi-Hole value into Domoticz

Posted: Saturday 16 April 2016 12:09
by Westcott
That looks like JSON encoding.
Perhaps this topic will give some clues -
http://www.domoticz.com/forum/viewtopic.php?t=11450

Re: How to get Pi-Hole value into Domoticz

Posted: Saturday 16 April 2016 12:16
by drenergy
Westcott wrote:That looks like JSON encoding.
Perhaps this topic will give some clues -
http://www.domoticz.com/forum/viewtopic.php?t=11450
Thank you for your quick reply Westcott! I will look at that topic and try to make it work. I will post the result in this topic for other people who might want to try this.

Re: How to get Pi-Hole value into Domoticz

Posted: Saturday 16 April 2016 12:35
by Westcott
This is how to read and decode to a table.
Just pass it your URL.
You'll need to get JSON.lus, see the Wiki.

Code: Select all

function GetJSONdata(url)
	if not JSON then
		JSON = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()
	end

	local jsondata = assert(io.popen(url))
	local data = jsondata:read('*all')
	jsondata:close()
	return JSON:decode(data)
end

Re: How to get Pi-Hole value into Domoticz

Posted: Wednesday 03 May 2017 10:40
by clubeddie
drenergy wrote:
Westcott wrote:That looks like JSON encoding.
Perhaps this topic will give some clues -
viewtopic.php?t=11450
Thank you for your quick reply Westcott! I will look at that topic and try to make it work. I will post the result in this topic for other people who might want to try this.
Did you get it working?