This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

garbage can trigger
#1
Hi @all,

I want to create a script that gives me a trigger object when a garbage can will be picked up today. Therefore I have all possible pick up dates available in an .ics calendar or I can easiliy convert it to an Excel.

Is there any script / starting point you can help me with?

Many thanks for your help.

Best Regards
Steffen
Reply
#2
ICS is a text format so it can be parsed via a script. Can you provide an example ICS that you want to use? Is it stored somewhere where LM can retrieve it automatically?
Reply
#3
Hi Admin

many thanks for your reply. 

Attached you can find the example file. I want to check if the actual date is similar to a pick up date in the ics and if yes a group address with the kind of garbage ("Restmüll", "Gelber Sack", etc.) should be send. 

The ics I getting from a website as a download and is not stored anywhere.

Many thanks for your help!

Best Regards
Steffen

Attached Files
.zip   2022_entsorgungskalender.ics.zip (Size: 3.96 KB / Downloads: 6)
Reply
#4
Here's an example that you can use a starting point. data variable should contain the ICS file contents that you get externally.

First the script parses ICS events into a table. Then it looks for an event with a matching date. summary variable is the summary field (kind of garbage in your case) of the found event or an empty string. Change 1/1/1 as needed and use 250 byte string as the data type of this object.

Code:
url = 'https://p35-caldav.icloud.com/published/2/MTQzMzA1NjcxOTE0MzMwNXFFkpAlN-RmUw02iYPAHdjXli1qufT3m2kVvFAFS2VXJLUhJ6r02NrhV15B8p_WoReJ0k5wrU4I1th5F6eq8UI'
data, err = require('socket.http').request(url)

if not data then
  log('request failed', err)
  return
end

data = data:split('\n')

events = {}

for _, line in ipairs(data) do
  line = line:trim()

  if line == 'BEGIN:VEVENT' then
    event = {}
  elseif line == 'END:VEVENT' then
    events[ #events + 1 ] = event
    event = nil
  elseif event then
    pos = line:find(':')
    if pos then
      key = line:sub(1, pos - 1)
      value = line:sub(pos + 1)

      event[ key ] = value
    end
  end
end

now = os.date('%Y%m%d')
summary = ''

for _, event in ipairs(events) do
  if event['DTSTART;VALUE=DATE'] == now then
    summary = event['SUMMARY']
    break
  end
end

grp.checkupdate('1/1/1', summary)
Reply
#5
Hi Admin,

many thanks for your help! Highly appreciated!

Two questions:

The content of the variable data. Do I need just to replace „\n“ with the copy and paste text string out of the ics opened by a text editor? I tried to and getting failure messages. Or do you have a recommendation how to convert it?

Would it be also possible to parse it directly from a webcal address?

Many thanks for your help!

Best Regards
Steffen
Reply
#6
What is the URL to get the ICS file?
Reply
#7
Here is a test url:

webcal://p35-caldav.icloud.com/published/2/MTQzMzA1NjcxOTE0MzMwNXFFkpAlN-RmUw02iYPAHdjXli1qufT3m2kVvFAFS2VXJLUhJ6r02NrhV15B8p_WoReJ0k5wrU4I1th5F6eq8UI

Many thanks for your help!
Reply
#8
I've modified my original example to fetch ICS from the URL.
Reply
#9
Awesome! It works! Many thanks for all of your help!
Reply
#10
@admin: If I want to get a message today for a planned pickup tomorrow, how is the modification look like? Sorry for the rookie question I‘ve tried to find a solution via search function without any success.

Many thanks for your help!
Reply
#11
Replace line 32 with this:
Code:
now = os.date('%Y%m%d', os.time() + 86400)
Reply
#12
Awesome! Many thanks again! :-)
Reply


Forum Jump: