Don’t feel bad about following it with your finger.
when
your rule is triggered
then
the first thing it does, every time it runs, is -
Abwesenheits_timer?.cancel
and the next thing it does after that is the switch-case selecting
switch Gruppe_Anwesenheit.state {
As I said, once the Timer is cancelled, it’s cancelled.
The funny-looking ? placed in there serves a purpose - it says “only do this if not-null”. That’s useful here because if you try to cancel a Timer that does not exist, it (quite rightly) fails.
When this rule starts there may or may not be a pre-existing timer.
Abwesenheits_timer?.cancel
boils down to “if it exists, cancel it”.
Further down in your rule …
It’s already dead, stop hitting it.
Note also that this version will throw an error when the Timer does not yet exist.
Maybe the part that is not clear is that when you use createTimer()
it makes a Timer outside of, and independent of the rule. The rule doesn’t stop and wait, it carries on and usually exits long before the Timer executes.
That means of course that you can run the rule again before the Timer has executed, that’s how you’re going to cancel it.
None. Why don’t you find out? All the tools are at your disposal, use them.
Apply some logic - if the rule does nothing, is it even loaded? I don’t know, find out.
After you edit your xxx.rules
file, you should get a message in your openhab.log
to tell you its been loaded or refreshed. Can you find that? If it doesn’t like your syntax and can’t make a working rule out of it at that point, it will tell you.
If you’re happy that your rule is loaded, but the rule does nothing, is it even running? I don’t know, find out.
rule "Wohnungstür abschließen bei Abwesenheit"
when
Item Gruppe_Anwesenheit changed
then
logInfo("test", "My rule has triggered")
Abwesenheits_timer?.cancel //Das ? überspringt diese Zeile, wenn der Abwesenheits-Timer = 0 ist
... etc ...
If you don’t get the log message, you know that you need to look into the triggering condition. Have you misspelled the Item name? Does the Item actually change when you thought it should? I don’t know, find out - look in your events.log
which will tell you about every Item change and how the system thinks the Item is named.
From there, you’ll know whether to look further into your rule or instead at what your Items are doing, etc.
EDIT - late observation
You’ve missed out a non-obvious character from the example you found. createTimer()
syntax requires a | pipe character inside the square brackets.
Some technical explanation about lambdas functions, but just take it that like every example you’ve seen, you need a structure [ | your code ]
Abwesenheits_timer = createTimer(now.plusSeconds(50), [ |
if (Schloss_Eingang_Status.state !=4) {
personally I put it on the createTimer()
line so the code’s easier to read.