Rule with repeater timer

Hi, i’m a beginner and i’m up with the rule with timer function.
but something does not go …

I would like to open the window after 30 minutes, and if the window is not closed, the message will repeat again after 30 minutes, but not infinitum.

I can not repeat the timer after the first 30 minutes.

Thanks for help

here is my rule

hello I added this rule but the software designer gives me a red dot to the line: var Timer timer = null -
the message says: missing EOF at 'var’
how can I fix it?
thanks for help

My Rules

var Timer timer = null

rule "ANNUNCI VOCALI FINESTRA LAVANDERIA aperta"
when
Item I30_1 changed from OPEN to CLOSED
then
timer = createTimer(now.plusSeconds(1800)) [|
setMasterVolume(new PercentType(50))
//playSound (“doorbell.mp3”)
say(“finestra lavanderia aperta”)

timer = createTimer(now.plusSeconds(1800)) [|
		setMasterVolume(new PercentType(50))
		say("finestra lavanderia aperta")
	 	//playSound("doorbell.mp3")

        timer = null   // reset the timer
]]

end

Which version of openHAB do you use? If using OH2, the rule should work. Please keep in mind, that all vars and vals have to be defined at the very beginning from the rules file.

Maybe this rule is a bit more elegant - you can define number of iterations and of course could use various messages (by using the var to decide, what to do) and there is no double code in it.

//Begin of rules file
var Timer timer = null
var int warn = 2

//first rule
rule "ANNUNCI VOCALI FINESTRA LAVANDERIA aperta"
when
    Item I30_1 changed 
then
    if (timer!==null) {  //will cancel the timer when changed to OPEN
        timer.cancel     //will also cancel before scheduling the new timer if changed to CLOSED
        warn = 2         //reset iterations
    }
    if (I30_1.state == CLOSED) {
        timer = createTimer(now.plusMinutes(30)) [|
            setMasterVolume(new PercentType(50))
            //playSound ("doorbell.mp3")
            say("finestra lavanderia aperta")
            warn = warn - 1                    //Count down
            if(warn > 0)
                timer.reschedule(now.plusMinutes(30))  //reschedule timer
        ]
    }
end

bye thank you.
the OH version is 1.8.3.

hello, I’ve tried your rule, but the error persists.
I tried to paste your rule both in the queue and even paste it at the beginning after importing files, but in either case I failed

The rule itself can reside wherever you want, but all var and val definitions (and of course all imports) must be written at the very beginning. First all imports, second all vars and vals (across all rules within this file), third all lambdas, fourth all rules.

In question of imports: Do you have any of them (OH1.8.3 will need at least

import org.openhab.core.library.types.*
import org.openhab.model.script.actions.*
import org.openhab.core.types.Command

and another import wouldn’t hurt:

import org.joda.time.DateTime

though this one is maybe unnecessary.)

here’s my evidence

Hmm…
Another thing I forgot to mention is this:

if (timer!==null)

should be

if (timer!=null)

in OH 1.8.3 (but is correct in OH2.2…)

But the line

var Timer timer = null

is completely correct, if at the beginning of the rules file. Did you use another editor beside openHAB Designer?

I changed the line if (timer!==null) in if (timer!=null)
copy line
var Timer timer = null
var int warn = 2

after import file
new mistake at line var Timer timer = null

Multiple markers at this line - Incompatible types. Expected void but was null - Couldn’t resolve reference to
JvmType ‘Timer’.

you sometimes copy and paste from txt files or web samples

Maybe the double import is bad… Please try if commenting out line 4 (the one with .actions.Timer) will help.

Argh… there are several smart quotes within your rules file. smart quotes are not allowed at all. Please ensure only to use

say("a text")

and never

say(“a text”)

But of course not only in question of say() :wink:

Do you mean this line?
say(“finestra lavanderia aperta”)

yes … I copied your example.
I noticed and changed.
but error remains
thank you

Sorry… I give up… I don’t have any more clues…

ok …
thank you for your dedicated time

I’m sorry…

I commented on the line
// import java.util. *
and line error
var Timer timer = null
disappeared…
but it remains but errors remain:

line: timer = createTimer(now.plusMinutes(30)) [|
error: Multiple markers at this line - Couldn’t resolve reference to JvmIdentifiableElement ‘plusMinutes’. - Couldn’t
resolve reference to JvmIdentifiableElement ‘now’.

line: setMasterVolume(new PercentType(50))
error: Unhandled exception type java.io.IOException

line: timer.reschedule(now.plusMinutes(30)) //reschedule timer
error: Multiple markers at this line - Couldn’t resolve reference to JvmIdentifiableElement ‘now’. - Couldn’t resolve
reference to JvmIdentifiableElement ‘plusMinutes’.

As the rules file seems to be corrupt, I would suggest to define a new rules file and then move the rule to this new file. Only use the imports that are needed and please ensure to move also the needed var definitions. Move only one rule at once, save the rule file and check if there are errors in it.

thanks for the advice…
I’m a beginner, I used several examples provided by the web.
how do I know which imports are needed?

In question of the actual rule i would guess

import org.openhab.core.library.types.*
import org.openhab.core.types.*
import org.joda.time.*

should suffice.