dzVents get garbage collection dates (various)  [SOLVED]

Moderator: leecollings

Bikey
Posts: 331
Joined: Sunday 22 February 2015 12:19
Target OS: Linux
Domoticz version: 2020.x
Location: Netherlands
Contact:

Re: dzVents get garbage collection dates (various)

Post by Bikey »

Thanks waaren!

I couldn't stand that I was not able to get this working nicely so did some more testing and found that the crippled Json is in a part of the result that is not relevant. So I used the regex as posted earlier to only select the proper "ophaaldagen" Json object from the result.

Now - building on your latest version - this is how I got it working:

Code: Select all

--[[ getGarbageDates.lua for [ dzVents >= 2.4 ]

this script is only useful in those  areas of the Netherlands where the household garbage collector is connected to afvalwijzer.nl

Enter your zipcode and housenumber in the appropriate place between the lines starting with --++++
Next is to set your virtual text and or virtual alert device.

the text device will contain the most nearby collectdates for the four types of household garbage
the alert device will contain the date and type for the garbagecollecion that will arrive first

]]--

return {
        on      =   {   timer              =  { "at 00:05","at 08:00" },    -- daily run twice
                        devices            =  { "Garbage" },               -- Only for test purposes can be ignored  
                        httpResponses      =  { "getGarbage_Response" }     -- Trigger the handle Json part
                },
        logging =   {   level              =   domoticz.LOG_DEBUG,          
                        marker             =   "collectGarbage"      },

        data    =   {   garbage            =    { initial = {}      },       -- Keep a copy of last json just in case  
                        lastStartline      =    { initial = 1       },  
                        lastEndline        =    { initial = 1000    },  
                    },             

    execute = function(dz, triggerObject)

        --++++--------------------- Mandatory: Set your values and device names below this Line --------------------------------------
        local myZipcode     = "3065KA"            -- Your zipcode like "3085RA"
        local myHousenumber =  193                 -- Your housenumber like 38
        local myTextDevice  = "GarbageText"       -- Name with quotes or idx without when created as virtual text device
        local myAlertDevice = "GarbageAlert"      -- Name with quotes or idx without when created as virtual alert device
        --++++---------------------------- Set your values and device names above this Line --------------------------------------------

        local myYear = os.date("%Y")
        garbageTypes  = {"restafval","gft","papier","plastic"}

        local function collectGarbageDates(secondsFromNow)
            local getGarbage_url  = "http://json.mijnafvalwijzer.nl/?method=postcodecheck&postcode="  .. 
                                    myZipcode .. "&street=&huisnummer=" .. 
                                    myHousenumber .. "&toevoeging" 
            dz.openURL  ({  url = getGarbage_url ,
                            method = "GET",
                            callback = "getGarbage_Response" }).afterSec(secondsFromNow)
        end

        -- Add entry to log and notify to all subsystems
        local function errorMessage(message)
            dz.log(message,dz.LOG_ERROR)
            dz.notify(message)
        end

        local function string2Epoch(dateString) -- seconds from epoch based on stringdate (used by string2Date)
            -- Assuming a date pattern like: yyyy-mm-dd
            local pattern = "(%d+)-(%d+)-(%d+)"
            local runyear, runmonth, runday= dateString:match(pattern)
            local convertedTimestamp = os.time({year = runyear, month = runmonth, day = runday})
            return convertedTimestamp
        end

        local function string2Date(str,fmt)             -- convert string from json into datevalue
            if fmt then return os.date(fmt,string2Epoch(str)) end
            return os.date(" %A %d %B, %Y",string2Epoch(str))
        end

        local function alertLevel(delta)
            if delta < 2 then return dz.ALERTLEVEL_RED end
            if delta < 3 then return dz.ALERTLEVEL_YELLOW end
            if delta < 4 then return dz.ALERTLEVEL_ORANGE end
            return dz.ALERTLEVEL_GREEN
        end

        local function setGarbageAlertDevice(alertDevice,alertText,alertDate)
            local delta = tonumber(string2Date(alertDate,"%d")) - tonumber(os.date("%d"))  -- delta in days between today and first garbage collection date
            dz.devices(alertDevice).updateAlertSensor(alertLevel(delta),alertText)
            dz.log("\nalertLevel: " .. alertLevel(delta) .. ", alertText: " .. alertText,dz.LOG_DEBUG)
            return (delta == 0)
        end

        local function longGarbageName(str)                                        -- Use descriptive strings
            str = tostring(str)
            str = str:gsub("plastic","  Plastic verpakkingen, blik en drinkpakken ")
            str = str:gsub("gft","  Groente-, fruit- en tuin afval            ")
            str = str:gsub("papier","  Papier en kartonnen verpakkingen          ")
            str = str:gsub("restafval" ,"  Restafval                                ")
            return str
        end

       local function handleResponse()
            json = "{"..triggerObject.data:match('(\"ophaaldagen\":{.*),\"ophaaldagenNext\":').."}"
--          dz.log('JSON RESULT: '..json,dz.LOG_ERROR)            
            triggerObject.json = dz.utils.fromJSON(json)
            -- json is now a Lua table
            if type(triggerObject.json) == 'table' then
                dz.data.garbage    = triggerObject.json.ophaaldagen.data      -- Store this part in dz.data 
                rt = triggerObject.json.ophaaldagen.data                      -- and in table
            else
               errorMessage("Problem with response (no data) using data from earlier run")
               rt  = dz.data.garbage                       -- json empty. Get last valid from dz.data
               if #rt < 1 then                              -- No valid data in dz.data either
                  errorMessage("No previous data. are zipcode and housenumber ok and in afvalkalender ?")
                  return false
               end
            end

--            dz.utils.dumpTable(rt)
            
            local garbageLines = ""
            local typeEarliestDate
            local overallEarliestDate   = "2999-12-31"       -- Hopefully we will have a different garbage collection system by then
            local garbageToday = false
            local today = os.date("%Y-%m-%d")
            local garbage = {}
            
            for i = 1,#garbageTypes do --walk the the type Table
                typeEarliestDate      = "2999-12-31"
                for j = 1, math.min(#rt, #dz.data.garbage) do                                 -- walk the response table
                   if  rt[j].date >= today and rt[j].date < typeEarliestDate and  rt[j].type == garbageTypes[i] then -- Keep date closest to today per type
                        typeEarliestDate =  rt[j].date
                        if  typeEarliestDate < overallEarliestDate then     -- date closest to today overall ?
                            overallEarliestDate = typeEarliestDate          -- keep date
                            overallEarliestType =  garbageTypes[i]          -- keep type
                            dz.data.lastStartline = j 
                        end
                        garbage[string2Epoch(typeEarliestDate,"%a %e %b" )] = string2Date(typeEarliestDate,"%a %e %b" ) .. longGarbageName(rt[j].type)
                        typeEarliestDate = rt[j].date  -- Keep date closest to today
                    end
                end
            end
            
            -- Order the lines based on dates
            local keyTable = {}
            local garbageLines = ''
            for key in pairs(garbage) do 
                table.insert(keyTable, key) 
            end
            
            table.sort(keyTable)
            
            for _, key in ipairs(keyTable) do 
                garbageLines = garbageLines .. garbage[key] ..  '\n' 
            end
            
            -- Update the devices
            if myAlertDevice then   -- Update AlertDevice with nearby date / type
                garbageToday = setGarbageAlertDevice(  myAlertDevice,
                                                        longGarbageName(overallEarliestType) .. "\n" ..
                                                        string2Date(overallEarliestDate),
                                                        overallEarliestDate)
            end

            if myTextDevice then       -- Update defined virtual text device with dates / types
                dz.devices(myTextDevice).updateText(garbageLines)
                dz.log("\n" .. garbageLines,dz.LOG_DEBUG)
            end

            if dz.time.matchesRule("at 08:00-17:00") and garbageToday then
                dz.notify(longGarbageName(overallEarliestType) .. " will be collected today")
            end
        end

        -- Main
        if triggerObject.isHTTPResponse then
            if triggerObject.ok then
                handleResponse()
            else
                errorMessage("Problem with response from hvcgroep (not ok)")
                --collectGarbageDates(600)                            -- response not OK, try again after 10 minutes
            end
        else
            collectGarbageDates(1)
        end
    end
}
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: dzVents get garbage collection dates (various)

Post by jvdz »

I don't think that this line will work at the end of the year:

Code: Select all

 json = "{"..triggerObject.data:match('(\"ophaaldagen\":{.*),\"ophaaldagenNext\":').."}"
.. because towards the end of December the "ophaaldagenNext" table will be filled with the collection dates for January and the "ophaaldagen" tabel will be "empty". I found that out the hard way too at the end of a year. ;)
So what I do is process the ophaaldagenNext table as well when the found future waste events are below 10.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVents get garbage collection dates (various)

Post by waaren »

jvdz wrote: Sunday 14 June 2020 14:14 I don't think that this line will work at the end of the year:
Thx ! Your warning is much appreciated.

I will set a reminder for myself towards the end of the year to look at the script again. To harden the script now without proper testdata is probably not going to deliver the best results.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
HansieNL
Posts: 957
Joined: Monday 28 September 2015 15:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dzVents get garbage collection dates (various)

Post by HansieNL »

@waaren Many thanks for fixing the script :D
Blah blah blah
Bikey
Posts: 331
Joined: Sunday 22 February 2015 12:19
Target OS: Linux
Domoticz version: 2020.x
Location: Netherlands
Contact:

Re: dzVents get garbage collection dates (various)

Post by Bikey »

jvdz wrote: Sunday 14 June 2020 14:14 I don't think that this line will work at the end of the year:

Code: Select all

 json = "{"..triggerObject.data:match('(\"ophaaldagen\":{.*),\"ophaaldagenNext\":').."}"
.. because towards the end of December the "ophaaldagenNext" table will be filled with the collection dates for January and the "ophaaldagen" tabel will be "empty". I found that out the hard way too at the end of a year. ;)
So what I do is process the ophaaldagenNext table as well when the found future waste events are below 10.

Jos
Thanks for the tip! Then I will already change the regex to include ophaaldagenNext as well, like this:

Code: Select all

            json = "{"..triggerObject.data:match('(\"ophaaldagen\":{.*),\"mededelingen\":').."}"
However the logic in the script then also need to be adapted to look in both the ophaaldagen en the ophaaldagenNext object.
As waaren mentioned, that is probably best to do if we have some real data.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVents get garbage collection dates (various)

Post by waaren »

Bikey wrote: Sunday 14 June 2020 21:26 I will already change the regex to include ophaaldagenNext as well, like this:

Code: Select all

            json = "{"..triggerObject.data:match('(\"ophaaldagen\":{.*),\"mededelingen\":').."}"
This will probably work for you but is not needed for addresses where the initial conversion already worked. There is also a risk that the order in the JSON change.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVents get garbage collection dates (various)

Post by waaren »

Code cleanup and prepared for period close to end of year (ophaaldagenNext)

Code: Select all

--[[ getGarbageDates.lua for [ dzVents >= 2.4 ]

this script is only useful in those  areas of the Netherlands where the household garbage collector is connected to afvalwijzer.nl

Enter your zipcode and housenumber in the appropriate place between the lines starting with --++++
Next is to set your virtual text and or virtual alert device.

the text device will contain the most nearby collectdates for the four types of household garbage
the alert device will contain the date and type for the garbagecollecion that will arrive first

            History:
            20180705: Start Coding
            20180725: First public release
            20180819: Changed target URL to mijnafvalwijzer
            20181108: use curl because of badly formatted json return
            20200614: sort lines before posting them to text device
            20200614: code cleanup
            20200614: Prepared for period close to end of year (ophaaldagenNext)
            20200615: Fixed notification bug
            20200615: Add choice for notification subsystem(s)

      tbc   20201210: interpret dates in next year ??

]]--

return
{
        on =
        {
            timer =
            {
                'at 00:05',
                'at 08:00'
            },

            devices =
            {
                'Garbage'                -- Only for test purposes can be ignored
            },

            httpResponses =
            {
                'getGarbage_Response' -- Trigger the handle Json part
            },
        },

        logging =
        {
            level = domoticz.LOG_ERROR, -- set to LOG_DEBUG when something does not work as expected
            marker = 'collectGarbage',
        },

        data =
        {
            garbage =
            {
                initial = {},              -- Keep a copy of last json just in case
            },
        },

    execute = function(dz, item)

        --++++--------------------- Mandatory: Set your values and device names below this Line --------------------------------------
        local myZipcode     = '3085RA'          -- Your zipcode like '3085RA'
        local myHousenumber = 38                -- Your housenumber like 38
        local myTextDevice  = 'GarbageText'     -- Name with quotes or idx without when created as virtual text device
        local myAlertDevice = 'GarbageAlert'    -- Name with quotes or idx without when created as virtual alert device

        local myNotificationTable =
        {
             -- table with one or more notification systems.
             -- uncomment the notification systems that you want to be used
             -- Can be one or more of

             -- dz.NSS_FIREBASE_CLOUD_MESSAGING,
             -- dz.NSS_PUSHOVER,
             -- dz.NSS_HTTP,
             -- dz.NSS_KODI,
             -- dz.NSS_LOGITECH_MEDIASERVER,
             -- dz.NSS_NMA,
             -- dz.NSS_PROWL,
             -- dz.NSS_PUSHALOT,
             -- dz.NSS_PUSHBULLET,
             -- dz.NSS_PUSHOVER,
             -- dz.NSS_PUSHSAFER,
             dz.NSS_TELEGRAM,
        }
        --++++---------------------------- No changes required below this line --------------------------------------------

        local debug = ( dz.utils.LOG_MODULE_EXEC_INFO == dz.LOG_DEBUG )
        local garbageTypes  = {'restafval','gft','papier','plastic','batterijen'}

        local function collectGarbageDates(secondsFromNow)
            local getGarbage_url  = 'http://json.mijnafvalwijzer.nl/?method=postcodecheck&postcode='  ..
                                    myZipcode .. '&street=&huisnummer=' ..
                                    myHousenumber .. '&toevoeging'
            dz.openURL  ({  url = getGarbage_url ,
                            method = 'GET',
                            callback = 'getGarbage_Response' }).afterSec(secondsFromNow)
        end

        -- Add entry to log and notify to set subsystems
        local function errorMessage(message)
            dz.log(message,dz.LOG_ERROR)
            dz.notify('Garbage',message, dz.PRIORITY_HIGH, dz.SOUND_DEFAULT, "" , myNotificationTable)
        end

        local function string2Epoch(dateString, pattern) -- seconds from epoch based on stringdate (used by string2Date)
            dz.log(dateString)
            local pattern = pattern or '(%d+)-(%d+)-(%d+)'
            local runyear, runmonth, runday= dateString:match(pattern)
            local convertedTimestamp = os.time({year = runyear, month = runmonth, day = runday})
            return convertedTimestamp
        end

        local function string2Date(str,fmt)             -- convert string from json into datevalue
            if fmt then return os.date(fmt,string2Epoch(str)) end
            return os.date(' %A %d %B, %Y',string2Epoch(str))
        end

        local function alertLevel(delta)
            if delta < 2 then return dz.ALERTLEVEL_RED end
            if delta < 3 then return dz.ALERTLEVEL_YELLOW end
            if delta < 4 then return dz.ALERTLEVEL_ORANGE end
            return dz.ALERTLEVEL_GREEN
        end

        local function setGarbageAlertDevice(alertDevice,alertText,alertDate)
            local delta = tonumber(string2Date(alertDate,'%d')) - tonumber(os.date('%d'))  -- delta in days between today and first garbage collection date
            dz.devices(alertDevice).updateAlertSensor(alertLevel(delta),alertText)
            dz.log('\nalertLevel: ' .. alertLevel(delta) .. ', alertText: ' .. alertText,dz.LOG_DEBUG)
            return (delta == 0)
        end

        local function longGarbageName(str) -- Use descriptive strings
            str = tostring(str)
            str = str:gsub('plastic','Plastic verpakkingen, blik en drinkpakken')
            str = str:gsub('gft','Groente-, fruit- en tuin afval')
            str = str:gsub('papier','Papier en kartonnen verpakkingen')
            str = str:gsub('restafval' ,'Restafval')
            str = str:gsub('batterijen' ,'Baterijen en klein chemisch afval')
            return str
        end

        local function getSortedKeys(t)
            local keyTable = {}
            for key, _ in pairs(t) do
                table.insert(keyTable, key)
            end
            table.sort(keyTable)
            return keyTable
       end

        function table.merge (t1, t2)
            for k,v in ipairs(t2) do
                table.insert(t1, v)
            end
            return t1
        end

       local function handleResponse()

             if not item.json then
                item.json = dz.utils.fromJSON(item.data:gsub('"ophaaldagen:','"ophaaldagen":'))  -- Some responses are even crippled in this part
            end

            if type(item.json) == 'table' then
                rt = table.merge(item.json.data.ophaaldagen.data, item.json.data.ophaaldagenNext.data)
                dz.data.garbage = rt
            else
               errorMessage('Problem with response (no data). Try using data from earlier run')
               rt  = dz.data.garbage                           -- json empty. Get last valid from dz.data
               if #rt < 1 then                              -- No valid data in dz.data either
                  errorMessage('No previous data. Are zipcode and housenumber ok and available in afvalkalender?')
                  return false
               end
            end

            if debug then dz.utils.dumpTable(rt) end

            local garbageToday = false
            local today = os.date('%Y-%m-%d')
            local garbage = {}

            for _, garbageType in ipairs(garbageTypes) do -- walk the the type Table
                local earliestDate = '2999-12-31'

                for _, garbageCollectRecord in ipairs(rt) do -- walk the response table
                    if  garbageCollectRecord.type == garbageType and garbageCollectRecord.date >= today and garbageCollectRecord.date < earliestDate  then -- Keep date closest to today per type
                        earliestDate = garbageCollectRecord.date
                        garbage[string2Epoch(earliestDate)] = { garbageCollectRecord.date , garbageCollectRecord.type }
                    end
                end
            end

            -- sort the keys of the garbage table
            local sortedKeys = getSortedKeys(garbage)

            -- Update alert device
            if myAlertDevice then
                local alertLines = longGarbageName(garbage[sortedKeys[1]][2]) .. '\n' .. string2Date(garbage[sortedKeys[1]][1])
                dz.log(alertLines,dz.LOG_DEBUG)
                garbageToday = setGarbageAlertDevice(  myAlertDevice, alertLines, garbage[sortedKeys[1]][1])
            end

            -- Update text device
            if myTextDevice then
                local garbageLines = ''
                for _, key in ipairs(sortedKeys) do
                    garbageLines = garbageLines .. string2Date(garbage[key][1], '%a %e %b' ) .. ':  '  .. longGarbageName(garbage[key][2]) .. '\n'
                end
                dz.devices(myTextDevice).updateText(garbageLines)
            end

            if dz.time.matchesRule('at 08:00-17:00') and garbageToday then
                dz.notify('Huisafval',longGarbageName(garbage[sortedKeys[1]][2]) .. " will be collected today", dz.PRIORITY_NORMAL,dz.SOUND_DEFAULT, "" , myNotificationTable)
            end
        end

        -- Main
        if item.isHTTPResponse then
            if item.ok then
                handleResponse()
            else
                errorMessage('Problem with response (not ok)')
                collectGarbageDates(600)                                           -- response not OK, try again after 10 minutes
            end
        else
            collectGarbageDates(1)
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Bikey
Posts: 331
Joined: Sunday 22 February 2015 12:19
Target OS: Linux
Domoticz version: 2020.x
Location: Netherlands
Contact:

Re: dzVents get garbage collection dates (various)

Post by Bikey »

waaren wrote: Sunday 14 June 2020 21:52
Bikey wrote: Sunday 14 June 2020 21:26 I will already change the regex to include ophaaldagenNext as well, like this:

Code: Select all

            json = "{"..triggerObject.data:match('(\"ophaaldagen\":{.*),\"mededelingen\":').."}"
This will probably work for you but is not needed for addresses where the initial conversion already worked. There is also a risk that the order in the JSON change.
Mmm, yeah you are right changing the order would brake things. So I will stick to your new script ;-)
That works excellent, thanks again!
Bikey
Posts: 331
Joined: Sunday 22 February 2015 12:19
Target OS: Linux
Domoticz version: 2020.x
Location: Netherlands
Contact:

Re: dzVents get garbage collection dates (various)

Post by Bikey »

Found a small bug, the notification returned an empty message today.

So line 194:

Code: Select all

dz.notify(longGarbageName(overallEarliestType) .. ' will be collected today')
needs to be changed to:

Code: Select all

dz.notify(longGarbageName(garbage[sortedKeys[1]][2]) .. ' will be collected today')
Or this, if you would like to select which notification channel to use (e.g. Telegram)

Code: Select all

dz.notify('Huisafval',longGarbageName(garbage[sortedKeys[1]][2]) .. " will be collected today", dz.PRIORITY_NORMAL,dz.SOUND_DEFAULT, "" , dz.NSS_TELEGRAM)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVents get garbage collection dates (various)  [SOLVED]

Post by waaren »

Bikey wrote: Monday 15 June 2020 9:29 Found a small bug, the notification returned an empty message today.
Thx. I changed it in my posted version. Also added the option to select notification subsystem(s)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
ronaldbro
Posts: 327
Joined: Thursday 15 November 2018 21:38
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: dzVents get garbage collection dates (various)

Post by ronaldbro »

Hi waaren,

Found a functional mistake in the script. At the alert sensor colors yellow and orange are switched.
In the script the order is green - orange - yellow - red, should be green - yellow - orange - red.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVents get garbage collection dates (various)

Post by waaren »

ronaldbro wrote: Saturday 20 June 2020 21:17 Found a functional mistake in the script. At the alert sensor colors yellow and orange are switched.
In the script the order is green - orange - yellow - red, should be green - yellow - orange - red.
Sorry, I was not aware that there is an official color warning system for the amount of days before a certain garbage type will be collected :D
If it is too confusing for you please feel free to change it to the colors you consider right.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
ronaldbro
Posts: 327
Joined: Thursday 15 November 2018 21:38
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: dzVents get garbage collection dates (various)

Post by ronaldbro »

Lol. Yep, it’s defined by the NPGCAW...
The National Department of Garbage Collector Alert Widgets. So it’s pretty official. But don’t worry, I already changed it in my version.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVents get garbage collection dates (various)

Post by waaren »

ronaldbro wrote: Saturday 20 June 2020 23:15 Lol. Yep, it’s defined by the NPGCAW...
😂😂👍
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
DickNi
Posts: 4
Joined: Thursday 09 July 2020 15:28
Target OS: -
Domoticz version:
Contact:

Re: dzVents get garbage collection dates (various)

Post by DickNi »

Hi there,

I followed you post with interest.

I'm trying to use the code also, but I get some errors:

2020-07-09 15:37:08.175 Error: Error opening url: http://json.mijnafvalwijzer.nl/?method= ... toevoeging
2020-07-09 15:37:08.319 Error: dzVents: Error: (3.0.2) collectGarbage: HTTP/1.1 response: 7 ==>> Couldn't connect to server
2020-07-09 15:37:08.319 Error: dzVents: Error: (3.0.2) collectGarbage: Problem with response from hvcgroep (not ok)

When i use http://json.mijnafvalwijzer.nl/?method= ... toevoeging in a browser i get a lot of data shown, which seems to be oke

Can you tell me what is going wrong and where i have to look for
Thanks
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVents get garbage collection dates (various)

Post by waaren »

DickNi wrote: Thursday 09 July 2020 15:39 2020-07-09 15:37:08.319 Error: dzVents: Error: (3.0.2) collectGarbage: Problem with response from hvcgroep (not ok)
Can you tell me what is going wrong and where i have to look for
From the error you posted, I understand you are not using the latest version . Can you try with the latest version (June 14th) I posted ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
DickNi
Posts: 4
Joined: Thursday 09 July 2020 15:28
Target OS: -
Domoticz version:
Contact:

Re: dzVents get garbage collection dates (various)

Post by DickNi »

Thanks Waaren,

I tried your latest version but now I get the following errors:
Error: dzVents: Error: (3.0.2) collectGarbage: Error parsing json to LUA table: /home/pi/domoticz/scripts/dzVents/../lua/JSON.lua: 1234: /home/pi/domoticz/scripts/dzVents/../lua/JSON.lua:808: can't parse JSON at byte 1 of: NOK
2020-07-10 21:08:33.098
2020-07-10 21:08:33.098 Error: dzVents: Error: (3.0.2) collectGarbage: Problem with response (no data). Try using data from earlier run
2020-07-10 21:08:33.098 Error: dzVents: Error: (3.0.2) collectGarbage: No previous data. Are zipcode and housenumber ok and available in afvalkalender?

Raspberry Pi 3B with Buster. Domoticz :version: 2020.2 dzVents Version: 3.0.2
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVents get garbage collection dates (various)

Post by waaren »

DickNi wrote: Friday 10 July 2020 21:13 Error: dzVents: Error: (3.0.2) collectGarbage: Error parsing json to LUA table: /home/pi/domoticz/scripts/dzVents/../lua/JSON.lua: 1234: /home/pi/domoticz/scripts/dzVents/../lua/JSON.lua:808: can't parse JSON at byte 1 of: NOK
If you send me a PM with the zipcode / housenumber you use I will have a look.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
DickNi
Posts: 4
Joined: Thursday 09 July 2020 15:28
Target OS: -
Domoticz version:
Contact:

Re: dzVents get garbage collection dates (various)

Post by DickNi »

Oops sorry
Wrong housenumber,

But now I get the error:
Error: EventSystem: Warning!, lua script /home/pi/domoticz/dzVents/runtime/dzVents.lua has been running for more than 10 seconds
which I had also in some other scripts which use an URL-call.

After a while the errors:
2020-07-11 21:18:56.191 Error: dzVents: Error: (3.0.2) collectGarbage: Error parsing json to LUA table: /home/pi/domoticz/scripts/dzVents/../lua/JSON.lua:1234: /home/pi/domoticz/scripts/dzVents/../lua/JSON.lua:1027: Lua script execution exceeds maximum number of lines
2020-07-11 21:18:56.191 Error: dzVents: Error: (3.0.2) collectGarbage: Problem with response (no data). Try using data from earlier run
2020-07-11 21:18:56.191 Error: dzVents: Error: (3.0.2) collectGarbage: No previous data. Are zipcode and housenumber ok and available in afvalkalender?
2020-07-11 21:18:56.217 Error: dzVents: Error: (3.0.2) collectGarbage: ------ Finished ButtonTest after >342 seconds. (using 349.6 seconds CPU time !)
riko
Posts: 90
Joined: Saturday 22 August 2020 13:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dzVents get garbage collection dates (various)

Post by riko »

Great script, thanks a lot. As mentioned in this threat before twice I'm also looking to customize the notification timing. I would like to have a notification the night before the garbage collection day. I've tried to add a notification myself by changing the 'on timer' to 20:00 and adding the following line:

Code: Select all

if (tonumber(string2Date(alertDate,"%d")) - tonumber(os.date("%d")) == 1) and dz.time.matchesRule("at 18:00-22:00") then
dz.notify(longGarbageName(overallEarliestType) .. "wordt morgen opgehaald")
end
Does anyone already have this implemented, or could you help me with the code above?
delcara wrote: Saturday 10 November 2018 12:48 Already usesd the script from Waaren. So far it's working nice, adjusted the run times and notifications a little bit. I now receive a notification the evening before collection day and some nice notifications through google TTS on my Sonos speakers :D .

Strange thing is that i can't save the script when copy/paste in the domoticz web editor, checked it for weird characters or empty spaces. No problem with other scripts. And it runs fine when i copy it to the scripts folder. Didn't bother to look further for the cause of this issue. Running domoticz beta 4.10171.
imdos wrote: Thursday 14 February 2019 18:11
imdos wrote: Tuesday 05 February 2019 10:00 Never mind. It worked without an additional notification.

Sent from my MI 6 using Tapatalk
I would like to extend the notification to once around 18:30 on the day before the actual pick-up of the garbage. However I don't see where (actually to which) to compare a variable like garbareTomorrow and do a simple check.

Or would it make more sense to compare it in a seperate script and against the alertdevice for example?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest