Icalendar binding - show complete next day

Hey guys,

I tried to implement a garbage calendar in my openHAB 3 installation.
At some days they are picking up two kinds of garbage in my place (for example tomorrow):
Bildschirmfoto 2021-03-04 um 15.56.17

I tried to use the iCalendar Binding, but it shows only the next entry (“Gelber Sack/…”). But I need all entries for the next day.

Any idea how to solve this problem?

Thank you :slight_smile:

Use a different binding. This one won’t do what you want. Unfortunately there may not be any that do.

1 Like

I had the same issue and use a script to grab the info via the API of my ‘trash-company’. I have an item for every type of trash and these are updated through the script.

Or someone should create a binding for OH like this one: GitHub - pippyn/Home-Assistant-Sensor-Afvalbeheer: Provides Home Assistant sensors for multiple Dutch and Belgium waste collectors :smile:

1 Like

Hi,

Just use switch items as proxy.
I have an Item for each kind of garbage. In my calendar event, I switch the specific item to on with the BEGIN statement.
For example, our trash gets collected on Monday - my calendar event starts Sunday morning and ends on Monday. When it begins on Sunday, it will switch my trash reminder item to on. This works for as many calendar entries as you want!

1 Like

Hi
You could create an eventfilter thing for each garbage type.

Than you will have multiple items which will store the next date of the garbage pickup of the configured garbage type

1 Like

Hey guys,

thank you for your answers.

I created a php script, to extract the necessary dates and save them into items.

Why PHP? I’m better using PHP than shell script or python :wink:

Maybe it is helpful for someone, here is my script:

<?php

$ics = ""; // url to the calendar file 

$filename = "Abfallkalender.ics";
$max_age = 3600;

require("class.ical.php");

if (!file_exists($filename)) {
    if (!file_put_contents($filename, file_get_contents($ics)) ) {
        die("Beim Download ist ein Fehler aufgetreten");
    }
}
else {
    $filemtime = filemtime($filename);
    
    if (time() >= ($filemtime + $max_age)) {
        // Datei zu alt - lade erneut herunter
        if (!file_put_contents($filename, file_get_contents($ics)) ) {
            die("Beim Download ist ein Fehler aufgetreten");
        }
    }
}


$ical = new iCal($filename);

$eventsByDate = $ical->eventsByDate();

$eventsByDateSince = $ical->eventsByDateSince(time());

$array = array();
$count_gelber_sack = 0;
$count_papier = 0;
$count_bio_restmuell = 0;

foreach($eventsByDateSince as $key => $value) {

    foreach ($value as $key2 => $value2) {

        if ($value2->summary == "Gelber Sack/Gelbe Tonne") {

            if ($count_gelber_sack == 0) {
                $array['next_gelber_sack'] = $key;
                $count_gelber_sack++;
            }
            else if ($count_gelber_sack == 1) {
                $array['next_but_one_gelber_sack'] = $key;
                $count_gelber_sack++;
            }
        }
        else {
            if ($value2->summary == "Papiertonne") {
                if ($count_papier == 0) {
                    $array['next_papier'] = $key;
                    $count_papier++;
                }
                else if ($count_papier == 1) {
                    $array['next_but_one_papier'] = $key;
                    $count_papier++;
                }
            }
            else {
                if ($value2->summary == "Restabfall/Bioabfall") {
                    if ($count_bio_restmuell == 0) {
                        $array['next_bio_restmuell'] = $key;
                        $count_bio_restmuell++;
                    }
                    else {
                        $array['next_but_one_bio_restmuell'] = $key;
                        $count_bio_restmuell++;
                    }
                }
            }
        }
    }


}

if ($argc > 1) {

    $param = trim($argv[1]);

    if (array_key_exists($param, $array)) {
        echo $array[$param];
    }
    else {
        die("Falscher Parameter");
    }

}
else {
    die("Kein Parameter");
}


?>

For reading the ical file I’m using this php class: iCal PHP Parser · GitHub

These are my items:

String Muellkalender_next_papier "Nächste Leerung Papiertonne"
String Muellkalender_next_but_one_papier "Übernächste Leerung Papiertonne "
String Muellkalender_next_gelber_sack "Nächste Leerung Gelber Sack"
String Muellkalender_next_but_one_gelber_sack "Übernächste Leerung Gelber Sack"
String Muellkalender_next_bio_restmuell "Nächste Leerung Restabfall/Bioabfall"
String Muellkalender_next_but_one_bio_restmuell "Übernächste Leerung Restabfall/Bioabfall"

This is the rule to actualize the items:

rule "Müllkalender"
when
    Time cron "0 0 * ? * * *"
then
   
    // Bio/ Restmüll
    var String next_papier = executeCommandLine(Duration.ofSeconds(10), "/usr/bin/php", "/etc/openhab/scripts/muellkalender/garbage.php", "next_papier2")
    logInfo(rulename, next_papier)

    if (next_papier == "Beim Download ist ein Fehler aufgetreten" || next_papier == "Falscher Parameter" || next_papier == "Falscher Parameter" || next_papier == "Kein Parameter") {
        Notification_Sebastian.sendCommand("Abfrage nächste Leerung Papiermüll: "+ next_papier)
    }
    else {
        Muellkalender_next_papier.sendCommand(next_papier)
    }

    var String next_but_one_papier = executeCommandLine(Duration.ofSeconds(10), "/usr/bin/php", "/etc/openhab/scripts/muellkalender/garbage.php", "next_but_one_papier")
    logInfo(rulename, next_but_one_papier)
    
    if (next_but_one_papier == "Beim Download ist ein Fehler aufgetreten" || next_but_one_papier == "Falscher Parameter" || next_but_one_papier == "Falscher Parameter" || next_but_one_papier == "Kein Parameter") {
        Notification_Sebastian.sendCommand("Abfrage übernächste Leerung Papiermüll: "+ next_but_one_papier)
    }
    else {
        Muellkalender_next_but_one_papier.sendCommand(next_but_one_papier)
    }


    var String next_gelber_sack = executeCommandLine(Duration.ofSeconds(10), "/usr/bin/php", "/etc/openhab/scripts/muellkalender/garbage.php", "next_gelber_sack")
    logInfo(rulename, next_gelber_sack)

    if (next_gelber_sack == "Beim Download ist ein Fehler aufgetreten" || next_gelber_sack == "Falscher Parameter" || next_gelber_sack == "Falscher Parameter" || next_gelber_sack == "Kein Parameter") {
        Notification_Sebastian.sendCommand("Abfrage nächste Leerung gelber Sack: "+ next_gelber_sack)
    }
    else {
        Muellkalender_next_gelber_sack.sendCommand(next_gelber_sack)
    }

    var String next_but_one_gelber_sack = executeCommandLine(Duration.ofSeconds(10), "/usr/bin/php", "/etc/openhab/scripts/muellkalender/garbage.php", "next_but_one_gelber_sack")
    logInfo(rulename, next_but_one_gelber_sack)

    if (next_but_one_gelber_sack == "Beim Download ist ein Fehler aufgetreten" || next_but_one_gelber_sack == "Falscher Parameter" || next_but_one_gelber_sack == "Falscher Parameter" || next_but_one_gelber_sack == "Kein Parameter") {
        Notification_Sebastian.sendCommand("Abfrage übernächste Leerung gelber Sack: "+ next_but_one_gelber_sack)
    }
    else {
        Muellkalender_next_but_one_gelber_sack.sendCommand(next_but_one_gelber_sack)
    }


    var String next_bio_restmuell = executeCommandLine(Duration.ofSeconds(10), "/usr/bin/php", "/etc/openhab/scripts/muellkalender/garbage.php", "next_bio_restmuell")
    logInfo(rulename, next_bio_restmuell)

    if (next_bio_restmuell == "Beim Download ist ein Fehler aufgetreten" || next_bio_restmuell == "Falscher Parameter" || next_bio_restmuell == "Falscher Parameter" || next_bio_restmuell == "Kein Parameter") {
        Notification_Sebastian.sendCommand("Abfrage nächste Leerung Bio-/ Restmüll: "+ next_bio_restmuell)
    }
    else {
        Muellkalender_next_bio_restmuell.sendCommand(next_bio_restmuell)
    }


    var String next_but_one_bio_restmuell = executeCommandLine(Duration.ofSeconds(10), "/usr/bin/php", "/etc/openhab/scripts/muellkalender/garbage.php", "next_but_one_bio_restmuell")
    logInfo(rulename, next_but_one_bio_restmuell)

    if (next_but_one_bio_restmuell == "Beim Download ist ein Fehler aufgetreten" || next_but_one_bio_restmuell == "Falscher Parameter" || next_but_one_bio_restmuell == "Falscher Parameter" || next_but_one_bio_restmuell == "Kein Parameter") {
        Notification_Sebastian.sendCommand("Abfrage übernächste Leerung Bio-/ Restmüll: "+ next_but_one_bio_restmuell)
    }
    else {
        Muellkalender_next_but_one_bio_restmuell.sendCommand(next_but_one_bio_restmuell)
    }

end

While I’m writing this, I see there could be a much better way to write the rule :sweat_smile: