OH3 rule: timer issue

Hi there,

I am running OH3.1 on a synology docker and i do have troubles with rules and timers.
As blockly does not support timers (yet?) i tried to just copy&paste my code from OH2.5 to OH3 but it did not work out. The code is as follows:

  - id: "1"
      itemName: LupusAlarmsensoren_LupusAlarmsensorGaragentor
      state: "{WEB_MSG_DC_OPEN}"
      previousState: "{WEB_MSG_DC_CLOSE}"
    type: core.ItemStateChangeTrigger
conditions: []
  - inputs: {}
    id: "2"
      type: application/vnd.openhab.dsl.rule
      script: |-
        var Timer Garagenlichttimer = null

        Garagenlichttimer = createTimer(now.plusSeconds(240)) [|
          Garagenlichttimer = null
    type: script.ScriptAction

In the event monitor stream i could see that the trigger was touched, the rules started but it did not work at all (nothing happened inside the rule). Can you help me?
Screenshot 2021-10-23 152501

anyone? :frowning:

Do your “before” commands get issued, you’ve not said?

I think the timer code will fail at the first line when it executes, there are no global variables in GUI entered DSL rules, so Garagenlichttimer will not exist at that time.
There should be complaints in your openhab.log.

I am not sure what you meant with “before” … please see attached screenshot on how i jump into that rule.
Do you have an idea how to solve that issue with the variable?
(or any other solution)

Your script does a bunch of commands, then sets up a timer to do a bunch more commands later.
Is the ‘sooner’ or ‘later’ part going wrong?

Don’t use the (global) variable, you’re not doing anything useful with it. You can create ‘anonymous’ timers without a preceding variable = createTimer(...), just createTimer(...)

1 Like

Works great, thanks for helping me out!

One more question:
This was the syntax for the DSL type of rule.
How would you do the timer in ECMA/Javascript form?

I tried this in my rule (in application/javascript editor), but it did not work out:
(first of all turn on the lights, wait 1 minute and switch it off again)

if (itemRegistry.getItem('UmgebungslichtGarten_Beleuchtungsstaerke').getState() > '200') {
  events.sendCommand('LichtGarageSeite_Betrieb', 'ON');

var timer = ScriptExecution.createTimer(ZonedDateTime.now().plusMinutes(1), function(){
  events.sendCommand('LichtGarageSeite_Betrieb', 'OFF');

Try to give people more information than “not working”.

Sorry, of course i should:
The rule starts accordingly and powers on the Light but after the timer should have finished, they dont power off.
Therefore i thought the timer part was/is not working