Page 1 of 1

Get trash collection date from www.deafvalapp.nl

Posted: Monday 31 July 2017 21:13
by vrmp
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.

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  
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.

Re: Get trash collection date from www.deafvalapp.nl

Posted: Thursday 25 April 2019 11:49
by rensbr
vrmp wrote: 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.
Thank you for the script. It did not work on the first try, because I saw that you forgot:

Code: Select all

commandArray = {}
--and
return commandArray
Then I did work. I also made some modifications. I've added the 'Kerstboom', so you will also get a notifications for that. And I added a second notification the day before:

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_DateTomorrow = os.date("%d-%m-%Y",os.time()+24*60*60)
Trash_GFT = FindTrashDate("GFT","1234AB","1)
Trash_Papier = FindTrashDate("PAPIER","1234AB","1)
Trash_Plastic = FindTrashDate("PMD","1234AB","1)
Trash_Rest = FindTrashDate("REST","1234AB","1)
Trash_Kerst = FindTrashDate("KERSTBOOM","1234AB","1)

commandArray = {}

if (tonumber(os.date("%H")) == 7) and (tonumber(os.date("%M")) == 00)
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'}
        print("Papier wordt vandaag opgehaald.")
    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'}
    elseif (Trash_Date == Trash_Kerst)
    then
        commandArray[#commandArray +1]={['SendNotification']='Afval#Kerstboom wordt vandaag opgehaald.#0'}
    end    
end  

if (tonumber(os.date("%H")) == 21) and (tonumber(os.date("%M")) == 00) 
then
    if (Trash_DateTomorrow == Trash_GFT)
    then
        commandArray[#commandArray +1]={['SendNotification']='Afval#Groente, Fruit en Tuinafval wordt morgen opgehaald.#0'}
    elseif (Trash_DateTomorrow == Trash_Papier)
    then
        commandArray[#commandArray +1]={['SendNotification']='Afval#Papier wordt morgen opgehaald.#0'}
    elseif ((Trash_Date == Trash_Plastic) or (Trash_DateTomorrow == Trash_Plastic))
    then
        commandArray[#commandArray +1]={['SendNotification']='Afval#Plastic wordt morgen opgehaald.#0'}
    elseif ((Trash_Date == Trash_Rest) or (Trash_DateTomorrow == Trash_Rest))
    then
        commandArray[#commandArray +1]={['SendNotification']='Afval#Restafval wordt morgen opgehaald.#0'}
    elseif ((Trash_Date == Trash_Kerst) or (Trash_DateTomorrow == Trash_Kerst))
    then
        commandArray[#commandArray +1]={['SendNotification']='Afval#Kerstboom wordt morgen opgehaald.#0'}
    end    
end  

return commandArray

Re: Get trash collection date from www.deafvalapp.nl

Posted: Wednesday 14 August 2019 12:08
by rensbr
I have re-written the code to dzvents, because the number of requests to the afvalapp API where enourmous, now it only runs twice a day.

Also I made some changes. The next pickup dates are now displayed in a text sensor.

In order for this to work you have to change the following in AfvalNotificationDZ.lua:
- Add postcode at variable 'postcode';
- Add house number at variable 'hn';
- Add an Dummy Text sensor;
- Change the IDX at variable 'kalender' (from the dummy text sensor).

The scipts can be found at Github:
- AfvalNotificationDZ.lua
- global_data.lua

Re: Get trash collection date from www.deafvalapp.nl

Posted: Wednesday 14 August 2019 13:39
by jvdz
... and there is also an updated version available which runs as LUA script here: https://github.com/jvanderzande/mijnafvalwijzer
This is configurable when to update is done and which way you want to be notified. :D

Jos