Irrigation rule based on weather

Hi,
I’m trying to get my head around how this rule works i picked up from here

val maxOffDays = 2
val minPrecipPercent = 40
val minPrecip = 1

rule "Rain Delay"
when
    Time cron "0 25 11 ? * * "
then

    if(Rain_Delay.lastUpdate.before(new Date(now.minusDays(maxOffDays).millis))) {
        Rain_Delay.sendCommand(OFF)
    }
    else {
        var boolean delay = false
        if (Weather_Precip_Today.state as DecimalType >= minPrecip) delay = true
        if(Weather_Prob_Precip_Tomorrow.state as DecimalType >=  minPrecipPercent ) delay = true

        if(delay) {
            Rain_Delay.sendCommand(ON)
        }
        else {
            Rain_Delay.sendCommand(OFF)
        }
    }

this is giving me this error that I don’t understand

Error during the execution of rule 'Rain Delay': 'before' is not a member of 'null'; line 10, column 8, length 72

here’s my .items file

Number Weather_Precip_Today         "Precip Today"      <rain>      (gGarden)          {channel="weatherunderground:weather:local:forecastToday#precipitationDay"}
Number Weather_Prob_Precip_Tomorrow "Probability of Rain Tomorrow" <rain> (gGarden)     {channel="weatherunderground:weather:local:forecastTomorrow#probaPrecipitation"}
Switch Rain_Delay                   "Turn Off Sprinkler"           (gGarden)
Switch GardenBack_Irrigation       "Back Garden" <rain>           (gGarden)  { channel="cbus:light:57957242:cliffo1254:48:state" }
Switch GardenLawn_Irrigation      "Back Lawn" <rain>             (gGarden)  { channel="cbus:light:57957242:cliffo1254:46:state" }
Switch GardenFront_Irrigation      "Front Garden" <rain>           (gGarden)  { channel="cbus:light:57957242:cliffo1254:49:state" }
Switch Irrigation_control

Any help will be be appreciated

Rain_Delay does not have an entry in the database so lastUpdate returns null.

If your persistence set up correctly?

I think so???..

influxdb.persist

Strategies {
    everyHour : "0 0 * * * ?"
    everyDay  : "0 0 0 * * ?"

    default = everyChange
}

Items {
    // persist all members of gGarden Group on every change
    gGarden* : strategy = everyChange, everyHour, everyDay
}

I’m getting a different error now?

2018-04-28 16:49:03.070 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'Rain Delay': 'time' is not a member of 'org.joda.time.DateTime'; line 10, column 8, length 26

So one problem I see is the lastUpdate will return the timer if the most recent entry in the database. With every hour and every day strategies that means your lastUpdate will change every hour even if the item hasn’t changed state.

But that isn’t the case of your null problem.

Verify that the item is actually being saved in the database and had a most recent value. Look at the influxdb docs or you can use the OH REST API.

Does Rain_Delay have a not NULL value? Persistence will not save NULL to the database.

Cheers for the tip!!

2018-04-28 18:00:00.308 [DEBUG] [sistence.rrd4j.internal.RRD4jService] - Stored 'Rain_Delay' with state 'OFF' in rrd4j database (again)
2018-04-28 18:00:00.321 [DEBUG] [sistence.rrd4j.internal.RRD4jService] - Stored 'Rain_Delay' with state '0' in rrd4j database
2018-04-28 18:00:00.411 [DEBUG] [sistence.rrd4j.internal.RRD4jService] - Stored 'GardenBack_Irrigation' with state 'OFF' in rrd4j database (again)
2018-04-28 18:00:00.416 [DEBUG] [sistence.rrd4j.internal.RRD4jService] - Stored 'GardenBack_Irrigation' with state '0' in rrd4j database
2018-04-28 18:00:00.497 [DEBUG] [sistence.rrd4j.internal.RRD4jService] - Stored 'Porch_LightChannel' with state 'OFF' in rrd4j database (again)
2018-04-28 18:00:00.502 [DEBUG] [sistence.rrd4j.internal.RRD4jService] - Stored 'Porch_LightChannel' with state '0' in rrd4j database
2018-04-28 18:00:00.556 [DEBUG] [sistence.rrd4j.internal.RRD4jService] - Stored 'Weather_Prob_Precip_Tomorrow' with state '40' in rrd4j database
2018-04-28 18:00:00.633 [DEBUG] [sistence.rrd4j.internal.RRD4jService] - Stored 'GardenLawn_Irrigation' with state 'OFF' in rrd4j database (again)
2018-04-28 18:00:00.637 [DEBUG] [sistence.rrd4j.internal.RRD4jService] - Stored 'GardenLawn_Irrigation' with state '0' in rrd4j database
2018-04-28 18:00:00.747 [DEBUG] [sistence.rrd4j.internal.RRD4jService] - Stored 'Garden3mainspots_LightChannel' with state 'OFF' in rrd4j database (again)
2018-04-28 18:00:00.754 [DEBUG] [sistence.rrd4j.internal.RRD4jService] - Stored 'Garden3mainspots_LightChannel' with state '0' in rrd4j database
2018-04-28 18:00:00.848 [DEBUG] [sistence.rrd4j.internal.RRD4jService] - Stored 'GardenFront_Irrigation' with state 'OFF' in rrd4j database (again)
2018-04-28 18:00:00.857 [DEBUG] [sistence.rrd4j.internal.RRD4jService] - Stored 'GardenFront_Irrigation' with state '0' in rrd4j database
2018-04-28 18:00:00.910 [DEBUG] [sistence.rrd4j.internal.RRD4jService] - Stored 'Weather_Precip_Today' with state '1' in rrd4j database
2018-04-28 18:00:00.997 [DEBUG] [sistence.rrd4j.internal.RRD4jService] - Stored 'GardenPillar_LightChannel' with state 'OFF' in rrd4j database (again)
2018-04-28 18:00:01.004 [DEBUG] [sistence.rrd4j.internal.RRD4jService] - Stored 'GardenPillar_LightChannel' with state '0' in rrd4j database
201

it seems that the items are being stored