[SOLVED] Garage door code not getting alert

I’m having trouble understanding why my code isn’t sending email after door has close
The following if statement doesn’t seem to work but as the loginfo is telling me the values are matching.

if (GarageStateDoor2.state == “CLOSED” && OpenAlertDoor2 == “Y” )

2019-08-29 17:34:13.712 [INFO ] [.smarthome.model.script.garage.rules] - test door alert Door2 state=CLOSED alert=N
2019-08-29 17:34:23.452 [INFO ] [.smarthome.model.script.garage.rules] - test door alert Door2 state=OPEN alert=N
2019-08-29 17:35:23.552 [INFO ] [.smarthome.model.script.garage.rules] - Garage open Door2 for 1 mins
2019-08-29 17:37:15.946 [INFO ] [.smarthome.model.script.garage.rules] - test door alert Door2 state=CLOSED alert=Y
rule "check Garage door2 left open"
when
    Item GarageStateDoor2 received update
then
        door="Door2"
        logInfo("garage.rules","test door alert "+ door + " state=" + GarageStateDoor2.state + " alert=" + OpenAlertDoor2 )
        if (GarageDoorTimer2 !== null) {
                        GarageDoorTimer2.cancel()
                        }

        if (GarageStateDoor2.state == "CLOSED" && OpenAlertDoor2 == "Y" ) {
                logInfo("garage.rules","reset door alert "+ door )
                OpenAlertDoor2 = "N"
                open_duration = ((now.millis - doorOpenTime2) / 60000)
                msg = "Garage closed "+ door  + " was open for " + open_duration + " mins"
                sendMail(email,"Garage closed " + door, msg)
    }

        if (GarageStateDoor2.state.toString == "OPEN") {
                doorOpenTime2 = now.millis
                GarageDoor2_Last_Opened.postUpdate(new DateTimeType())
                // wait and alert if door left open
                GarageDoorTimer2 = createTimer(now.plusMinutes(GarageOpenMax)) [|
                                open_duration = ((now.millis - doorOpenTime2) / 60000)
                                msg = "Garage open "+ door  + " for " + open_duration + " mins"
                                sendMail(email,"Garage Open " + door, msg)
                                OpenAlertDoor2 = "Y"
                                logInfo("garage.rules",msg  )
                 // second alert wait double time
                        GarageDoorTimer1 = createTimer(now.plusMinutes(GarageSecondAlert)) [|
                                        open_duration = ((now.millis - doorOpenTime2) / 60000)
                                        msg = "Garage open "+ door  + " for " + open_duration + " mins"
                                        sendMail(email,"Garage Open " + door + " Second alert", msg)
                                        logInfo("garage.rules",msg  )
                                                        ]
                ]
        }
end

Try that:

if ((GarageStateDoor2.state == CLOSED) && (OpenAlertDoor2 == "Y")) {

nope throws a script error…

GarageStateDoor2 is a Contact item?
What error?

ok it must be some other line.

019-08-29 17:50:23.557 [ERROR] [org.quartz.core.JobRunShell         ] - Job DEFAULT.2019-08-29T17:50:23.553+10:00: Proxy for org.eclipse.xtext.xbase.lib.Procedures$Procedure0: [ | {
  <null>.open_duration = <XBinaryOperationImplCustom>
  <null>.msg = <XBinaryOperationImplCustom>
  sendMail(<XFeatureCallImplCustom>,<XBinaryOperationImplCustom>,<XFeatureCallImplCustom>)
  logInfo(<XStringLiteralImpl>,<XFeatureCallImplCustom>)
} ] threw an unhandled Exception:
java.lang.NullPointerException: null
        at org.eclipse.smarthome.model.script.engine.ScriptError.<init>(ScriptError.java:66) ~[?:?]
        at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.invokeFeature(ScriptInterpreter.java:140) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:902) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:865) ~[?:?]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:224) ~[?:?]
        at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:226) ~[
019-08-29 17:50:23.557 [ERROR] [org.quartz.core.JobRunShell         ] - Job DEFAULT.2019-08-29T17:50:23.553+10:00: Proxy for org.eclipse.xtext.xbase.lib.Procedures$Procedure0: [ | {

That looks like it came from your second timer, inside the first timer.

Does the trigger works now for CLOSED and Y?

yes it works with your suggested CLOSED reference now need to fix the code which its triggering…

Note this was working at one point , some update has regressed this or changed behavior.

ok I think I found it the (GarageStateDoor1.state.tostring == “OPEN” changed to match CLOSED format
ie

if (GarageStateDoor1.state == OPEN )

that seems to have fixed it!!!

thanks

Coolio, please tick the solution, thanks!