Rule issue and question

Hi,
I’m trying to create 2 rules. First when I enter the bathroom witch on Sonos and keep this on until in this case 60 sec no movement. Second rule I don’t know how to create this one. It should start when the timer from the first rule is expired.
var Timer BadkamerBezetTimer = null
var Number StartVochtigheid
var Number BadkamerBezet // do we have a boolean ??
var Number BadkamerRadio

rule “BadkamerIsBezet”
when
Item Beweging_gEVBadkamer changed from OFF to ON
then {
if (BadkamerBezetTimer === null) {
BadkamerBezet = 1
BadkamerBezetTimer = createTimer(now.plusSeconds(60))
sendCommand(SonosBadkamerVolume, 12)
sendCommand(SonosBadkamerControl, PLAY)
BadkamerRadio = 1
} else {
BadkamerBezetTimer.reschedule(now.plusSeconds(60))
}
}
end

// in the above rule I get error message Rule ‘BadkamerIsBezet’: An error occurred during the script execution: index=1, size=1

rule “BadkamerIsVrij”
when
Item BadkamerBezetTimer === nill // need to do something when trigger is zero
end

See this Topic:

Also please use code fences when posting your rules, logs, items, etc… It’s the paper icon located to the left of the gear icon.

Second rule I don’t know how to create this one. It should start when the timer from the first rule is expired.

Create a proxy item and add it to the rule so it gets turned on/off after the timer finishes in the first rule.

It’s really hard to read without code fences but there are tons and tons of syntax errors in this code. Are you using VSCode?

  • You don’t use curly brackets after then and before end
  • createTimer requires a lambda which is defined by a starting [ | and a closing ], you have not defined a lambda
  • use the method on the Item instead of the action for sendCommand and postUpdate, see https://www.openhab.org/docs/configuration/rules-dsl.html#myitem-sendcommand-new-state-versus-sendcommand-myitem-new-state
  • Rules are triggered based on events on Items and in some cases time or Things. BadkamerBezetTimer === null is a state, not an event, and BadkamerBezetTimer isn’t an Item it’s a varaible. You can’t trigger a Rule in this way. If you need to do something when the Timer variable becomes null, add the code right after you set the Timer to null. Note that when the Timer runs it does not set the variable to null, you have to do that yourself, usually as the last line of the lambda that you pass to the Timer.