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