Timer does not stop as expected

Hello community, since days im fighting with a problem that i dont understand.
Let me show u my rule for controlling the garagedoor:

rule "GaraDist"
	Item Gard1 changed or
	Item Gard2 changed 
	var Number g1 = Gard1.state as DecimalType
	var Number g2 = Gard2.state as DecimalType
	var Number g3 = Gardis1.state as DecimalType
	var Number g4 = Gardis2.state as DecimalType
    var int gt = (Gart.state as Number).intValue

	if (Gars.state == ON && rweContactN2.state == OPEN)
		if (g1 <= g3 && g2 <= g4 && gStart_timer === null)
			haa.postUpdate(tim + "Der Garage schliessen Timer einschalten")
			gStart_timer = createTimer(now.plusMinutes(gt)) [| sendHttpGetRequest(oGa) gStart_timer = null haa.postUpdate(tim + "Die Garage wird geschlossen")]
			if((g1 >= g3 || g2 >= g4 || rweContactN2.state == CLOSED) && gStart_timer !== null)
				gStart_timer = null
				haa.postUpdate(tim + "Der Garage schliessen Timer wird unterbrochen")

My problem is that for example, someone closes the door by hand, than the interrupt starts and should kill the timer. It looks like it is running but after the gt Time the door closing signal is given. It looks like than the kill of the timer does not work. Can somebody help???

Need a bit more context.
Is gStart_timer declared a global variable? What is tim?

But what does that mean in terms of events and Items here? We have no idea what Gard1 etc. represent, they’re just numbers.

It sounds like your problem seems to be about the timer cancel, which is controlled by a complicated if() statement.
I would at least log out the values used in that if()

There is a glaring logic problem though.
The first if() in your rule controls entry to any of the timer code, with
rweContactN2.state == OPEN
The nested if() has another term
rweContactN2.state == CLOSED
which will never be true at the same time.

Don’t be frightened to make another rule to cancel the timer under some circumstances, you don’t have to do everything n one big rule.

1 Like

Thanks for your fast reply.
Yes the timer is declared and thanks the rweContactN2.state == closed is nonsense so i just removed it.
Now a little more about the rule:
We have a garage for 2 cars. with a Rpi system I am measuring the distance between the wall and the cars. This I report to openhab as Gard1 and Gard2 for car one and two.
i have a few more config variables Gardis1 and Gardis2 are the limits in cm for the cars to be detected as inside the garage. If both are inside a closing timer Gart is started and closes the door at the end. With the switch Gars I can stop the measuring system. RweContactN2 is the garage door contact telling me if garage is open or closed. In my openhab system I have a own logging system haa.postUpdate is writing a log string and also gives a vocal output via Alexa. The variable Tim is only the actually time.
I hope u can understand. Thanks in advance.

Okay, so when you log out those variable just before the if() we’ll be able to make sense of them.

Since your rule triggers only when the car-distance Items change, why would you expect it to cancel anything when someone manually closes the door?

Should you have another rule triggered by “door changed to closed” that cancels an existing timer?

Say for example my wife opens the garage to drive shopping, but she finds out she has some dirt on her jeans and decided to change them. Now both cars are still inside and the door is open… so the closing timer starts. When she now comes and drives outside than the door would be closed. I don’t want this so I have to cancel the timer.
The rule works perfect except the cancelling The logging said all done but its not done the cancel does not work

Okay, you’ve changed the condition.
If you share your logging and your events.log we might be able to help.

I think there are flaws in your logic - if your wife opens the door, and goes off to change her jeans, your timer does not start. Car-distance Items did not change to trigger your rule.
That’s a Good Thing, as otherwise when she comes back and starts to drive out, the door may close on the car.

yes that’s why I use this closing timer cause the result of the measurement are not stable (I use ultrasonic sensors) they toggle about 10%) so the rule will be triggered nearly every 60 seconds

and yes its also true that their is a little risk if she needs more than 20 minutes the door might close I don’t have a solution for this

I don’t like this at all. The primary safety feature of your system - “don’t close the door on a moving car” - relies on being triggered by noise in the measuring system? Does the door have independent break-beam or pressure strip protection? If not, I would think very hard about if automating it was sensible at all. You wouldn’t be allowed to sell such a system, it relies on an intelligent operator holding down a button.

Having said that, it’s your problem. When you want help with the rule, show us your events.log and your logInfo() output

Thanks for all, but I found the solution. in the createTimer function I closed the round brackets too early and I forgot a comma. Silly me…