Page 1 of 1

Live Wildfire Info

Posted: Tuesday 06 February 2018 22:57
by elmortero
For those of us who live in areas where forestal fires are a risk I wrote this script to warn of current wildfires.
In the posted version there is no geographical filter but you can filter by Country, Province and city (or with some tweaking a radius around coordinates)

Code: Select all

--[[
some of the used methods require dzVents 2.4.0 or higher
data from http://effis.jrc.ec.europa.eu
--]]

return {
	on = {
		timer = { 'at every 30 minutes'},
		httpResponses = { 'effis' } -- matches callback string below
	},
	
	execute = function(domoticz, triggerItem)
local sensor = domoticz.devices('Wildfire') --text or alert sensor
local currInfo = tostring(sensor.text)
		if (triggerItem.isTimer) then
			domoticz.openURL({
				url = 'http://effis.jrc.ec.europa.eu/rest/2/burntareas/current/?limit=25&ordering=-firedate&format=json',
				method = 'GET',
				callback = 'effis'
			})
			--print('effis triggered by timer')
		elseif (triggerItem.isHTTPResponse) then

	local response = triggerItem
		if not response.isJSON then print('data is not jSon') end
		if (response.ok and response.isJSON) then

				local ctry = tostring(response.json.results[1].countryful)
				local vill = tostring(response.json.results[1].commune)
				local prov = tostring(response.json.results[1].province)
				local fech = tostring(response.json.results[1].firedate)
				local superf = tostring(response.json.results[1].area_ha)
				local dia = string.sub(fech, 9,10); local mes = string.sub(fech, 6,7); local anno = string.sub(fech, 1,4)
				local humano = tostring(dia..'-'..mes..'-'..anno)
				local mensaje = tostring(vill.. ', '..prov.. ', '..ctry.. '\n on '..humano..' area '..superf.. 'ha')
				if mensaje ~= currInfo then
					--uncomment line below and the commented end if you want to filter the results to match your location
				    --if string.find((string.lower(FIELD_TO_FILTER_HERE)), "[SEARCHSTRING_IN_LOWERCASE]") then
					sensor.updateAlertSensor(0, mensaje)
					print('msg : '..mensaje)
					-- when using the filter also uncomment the line below to close loop
					--end
				end

		else
				print('**effis failed to fetch info')
		end
		
	 end
	end
}

Re: Live Wildfire Info

Posted: Thursday 08 February 2018 7:33
by dannybloe
Ain't that neat :)