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”)
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
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
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.