In Rules I try to switch something ON and switching OFF after x seconds

Hopefully this was not already asked a thousand times, I found some stuff for the former Versions of openHAB, but nothing for a pure openHAB3 (at least it seema to me).
I started with openHAB3 from the scratch, coming from FHEM, cause OH3 looked easier.
Thats the Rule:

The script I call:

If I only “switch on” with “events.sendCommand(“HMSwitchx4KellerKanal1_State”, “ON”)” it works, but the createTimer throws an error:

2021-01-04 13:39:59.126 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘Treppenhausbeleuchtung’ failed: :2:32 Expected an operand but found |
createTimer(now.plusMinute(1), [| events.sendCommand(“HMSwitchx4KellerKanal1_State”, “OFF”)])
^ in at line number 2 at column number 32

I’m lost now, any help? :slightly_smiling_face:

The text based rules work exactly the same way.

That might be, but afaik it is suggested not to mix file-based Configuration and ui-based configuration with OH3?!?!?!
Like I already have written, i’m completely new to OH.

Hello Andreas,

you can use the system-integrated Expire-Function without any rules to get that working

Does that fit your need?

1 Like

That fits perfectly, thanks! :+1:
It is well hidden, isn’t it? :wink:

Yup hidden in the documentation. :roll_eyes:

That’s a mix of JavaScript and Rules DSL. Pick one or the other and stick with it.

To create a Timer in JavaScript it looks something like:

var ZonedDateTime = Java.type("java.time.ZonedDateTime");
this.ScriptExecution.createTimer(, function() { 
    // do stuff

I can’t remember if you have to import ZonedDateTime like that or not. I created a set of libraries so I never have to deal with this sort of stuff any more. See GitHub - rkoshak/openhab-rules-tools: Library functions, classes, and examples to reuse in the development of new Rules. time_utils and timer_mgr.

For a given type, and it’s only a recommendation. You could put all your rules in text files and everything else done through the UI and still be consistent.

But there will be times where you can’t do that. The recommendation is for consistency. It makes it easier for you to understand and find where stuff is configured. But there will be cases where being able to just copy and paste something to a .rules file is easier than trying to be consistent.

Thanks for the explanation, appreciated!
I was not brave enough to simply try to use more file-based stuff, but thats over now! :slight_smile: