Get trash collection date from www.deafvalapp.nl
Posted: Monday 31 July 2017 21:13
I saw the topic created by Zicht (https://www.domoticz.com/forum/viewtopi ... 61&t=17963) to query a Dutch website for garbage collection. Because in my location I need to use http://www.deafvalapp.nl and I didn't want to intrude that topic I am creating this one. I created a LUA script which gets the next collection date from http://www.deafvalapp.nl for the different types of garbage.
When using the above code a message will be send at 5 minutes past 8 every morning if there is a garbage collection scheduled.
Of course you could attach this to a text sensor or use it in a different way.
You can call the function with the following commands:
FindTrashDate("GFT","1234AB","1")
FindTrashDate("PAPIER","1234AB","1")
FindTrashDate("PLASTIC","1234AB","1")
FindTrashDate("REST","1234AB","1")
Replace 1234AB with your own zipcode and 1 with your own housenumber.
Code: Select all
function FindDate(String,Day,Month,Year,Count)
for i=Count,1,-1 do
if string.len(Day) == 1 then Day = "0" .. Day end
if string.len(Month) == 1 then Month = "0" .. Month end
Trash_NextDate = Day .. "%-" .. Month .. "%-" .. Year
if string.find(String, Trash_NextDate)
then
Date = Day .. "-" .. Month .. "-" .. Year
break
else
if tonumber(Day) == 31
then
Day = 1
Month = tonumber(Month) + 1
else
Day = tonumber(Day) + 1
end
end
end
return Date
end
function FindTrashDate(Type,Zipcode,Number)
url = ('curl "http://dataservice.deafvalapp.nl/dataservice/DataServiceServlet?service=OPHAALSCHEMA&land=NL&postcode=' .. Zipcode ..'&straatId=0&huisnr=' .. Number .. '"')
local f = io.popen(url)
while true do
line = f:read("*line")
if not line then break end
if string.find(line, Type)
then
Trash_Result=FindDate(line,os.date("%d"),os.date("%m"),os.date("%Y"),60)
end
end
return Trash_Result
end
Trash_Date = os.date("%d-%m-%Y")
Trash_GFT = FindTrashDate("GFT","1234AB","1")
Trash_Papier = FindTrashDate("PAPIER","1234AB","1")
Trash_Plastic = FindTrashDate("PLASTIC","1234AB","1")
Trash_Rest = FindTrashDate("REST","1234AB","1")
if (tonumber(os.date("%H")) == 8) and (tonumber(os.date("%M")) == 5)
then
if (Trash_Date == Trash_GFT)
then
commandArray[#commandArray +1]={['SendNotification']='Afval#Groente, Fruit en Tuinafval wordt vandaag opgehaald.#0'}
elseif (Trash_Date == Trash_Papier)
then
commandArray[#commandArray +1]={['SendNotification']='Afval#Papier wordt vandaag opgehaald.#0'}
elseif (Trash_Date == Trash_Plastic)
then
commandArray[#commandArray +1]={['SendNotification']='Afval#Plastic wordt vandaag opgehaald.#0'}
elseif (Trash_Date == Trash_Rest)
then
commandArray[#commandArray +1]={['SendNotification']='Afval#Restafval wordt vandaag opgehaald.#0'}
end
end
Of course you could attach this to a text sensor or use it in a different way.
You can call the function with the following commands:
FindTrashDate("GFT","1234AB","1")
FindTrashDate("PAPIER","1234AB","1")
FindTrashDate("PLASTIC","1234AB","1")
FindTrashDate("REST","1234AB","1")
Replace 1234AB with your own zipcode and 1 with your own housenumber.