Issues with date calculations


I took this as a reference ( and it was working once but for some time I am receiving this error message:

[ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule ‘Muellkalender’: Could not cast NULL to org.eclipse.smarthome.core.library.types.DateTimeType; line 20, column 40, length 41

This is my rule:

rule “Muellkalender”
Time cron “0 * * ? * *” //every 1 Minute for testing
//Time cron “0 00 18 * * ?” //once per Day 18:00
var String muelltonne_1
muelltonne_1 = CalDAV_Muell_1.state.toString

var String muelltonne_2
muelltonne_2 = CalDAV_Muell_2.state.toString

var String muelltonne_1_date
muelltonne_1_date = CalDAV_Muell_1_Date.state.toString

if (muelltonne_1 != "UNDEF") {
    // Datum der Abholung wird mit dem aktuellen Datum verglichen
    // die erste Bedingung prüft, ob das aktuelle Datum vor dem Ablaufdatum + 24 Std. liegt
    // die zweite Bedingung prüft, ob das aktuelle Datum nach dem Datum der Abholung liegt
    if (now.isBefore(new DateTime((CalDAV_Muell_1_Date.state as DateTimeType).getZonedDateTime.toInstant.toEpochMilli).plusHours(24)) && now.isAfter(new DateTime((CalDAV_Muell_1_Date.state as DateTimeType).getZonedDateTime.toInstant.toEpochMilli).minusHours(8))) {
        if(muelltonne_2 == "UNDEF") {
            sendTelegram("h1", "Müllkalender: morgen, %s, wird %s geleert", muelltonne_1_date, muelltonne_1)
            logInfo("INFO","abfall.rules - Müllkalender: %s", muelltonne_1)           
        } else {
            sendTelegram("h1", "Müllkalender: morgen, %s, wird %s & %s geleert", muelltonne_1_date, muelltonne_1, muelltonne_2)
            logInfo("INFO","abfall.rules - Müllkalender: %s %s & %s", muelltonne_1_date, muelltonne_1, muelltonne_2)           


any help is highly appreciated

Use loginfo to figure out which variable is null.