Timer DSL rule reschedule if state

Hi,

I’m using the DSL rule of this tutorial: Design Pattern: Motion Sensor Timer

The problem I’m facing is that sometimes, there is a lot of motion for a longer time, so the state of the motion sensor will stay at ON.
What I tried is this:

var Timer occupancyTimer = null
val timeoutMinutes = 1

rule "Motion gang received ON"
when
    Item Philips_motion2_Occupancy_Gang received update ON
then
    if(occupancyTimer === null || occupancyTimer.hasTerminated() || Philips_motion2_Occupancy_Gang.state == OFF){
        occupancyTimer = createTimer(now.plusMinutes(1), [|
            dummyGanglampDimmerSlow.sendCommand(0)
            occupancyTimer = null
        ])
    }
    else {
        occupancyTimer.reschedule(now.plusMinutes(timeoutMinutes ))
    }
end

So I’m trying to at another dependence to the IF statement, I want it to also check if the sensor state is changed back to OFF, if not, it should go to ELSE IF and reschedule the timer.
But the rule seems to ignore that part and just turn off the light.

Instead of || I also tried && but this no result…
Any thoughts what I’m not doing right?

If you introduce some logging you should be ablt to see what paths you are following.
This rule never turns off the light, the timer does that. Maybe it’s the code within the timer that should do the checking.

Alternative approach -
Motion sensor ON, light ON and cancel any timer.
Motion sensor OFF, start off-timer

Thanks for the quick reply. I also tried the Motion OFF start timer approach, but that didn’t work as well because sometimes there is a lot of motion (it’s the hallway sensor), but you sit still to tie your shoes and the timer get triggered then the moving starts again and the timer keeps counting an eventually turn off the light.

How can I add logging to see what path it’s following?

That’s why you need to cancel the timer (if it exists) when motion updated ON.

Really?

rule "Motion gang received ON"
when
    Item Philips_motion2_Occupancy_Gang received update ON
then
    logInfo("test", "My rule begins")
    if(occupancyTimer === null || occupancyTimer.hasTerminated() || Philips_motion2_Occupancy_Gang.state == OFF){
        logInfo("test", "Creating new timer")
        occupancyTimer = createTimer(now.plusMinutes(1), [|
            logInfo("test", "Executing timer code")
            dummyGanglampDimmerSlow.sendCommand(0)
            occupancyTimer = null
        ])
    }
    else {
        logInfo("test", "Rescheduling old timer")
        occupancyTimer.reschedule(now.plusMinutes(timeoutMinutes ))
    }
    logInfo("test", "Exiting my rule")
end

That could also work indeed, then it should be something like this I think:

var Timer occupancyTimer = null
val timeoutMinutes = 1

rule "Motion gang received OFF"
when
    Item Philips_motion2_Occupancy_Gang received update OFF
then
    logInfo("test", "My rule begins")
    if (Philips_motion2_Occupancy_Gang.state==ON){
        occupancyTimer.reschedule(now.plusMinutes(timeoutMinutes ))}
    if(occupancyTimer === null || occupancyTimer.hasTerminated()){
        logInfo("test", "Creating new timer")
        occupancyTimer = createTimer(now.plusMinutes(1), [|
            logInfo("test", "Executing timer code")
            dummyGanglampDimmerSlow.sendCommand(0)
            occupancyTimer = null
        ])
    }
    else {
        logInfo("test", "Rescheduling old timer")
        occupancyTimer.reschedule(now.plusMinutes(timeoutMinutes ))
    }
    logInfo("test", "Exiting my rule")
end

Thanks a lot, never used the log info like that before but it makes it a lot more clearer what is happening :slight_smile:

So I just updated the rule like suggested, when the first motion is detected, this is the info, nothing strange:

2021-11-14 11:22:03.327 [INFO ] [org.openhab.core.model.script.test  ] - My rule begins
2021-11-14 11:22:03.346 [INFO ] [org.openhab.core.model.script.test  ] - Creating new timer
==> /var/log/openhab/events.log <==
2021-11-14 11:22:03.355 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'dummyGanglampDimmer' received command 50
==> /var/log/openhab/openhab.log <==
2021-11-14 11:22:03.360 [INFO ] [org.openhab.core.model.script.test  ] - Exiting my rule
==> /var/log/openhab/events.log <==
2021-11-14 11:22:03.369 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'universaldimmer' received command Light_DimmerGanglamp,50,6000
2021-11-14 11:22:03.377 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'universaldimmer' changed from Light_DimmerGanglamp,0,16000 to Light_DimmerGanglamp,50,6000
2021-11-14 11:22:03.381 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Philips_motion2_Illuminance_Gang' changed from 0.0 to 7.267991091178708
==> /var/log/openhab/openhab.log <==
2021-11-14 11:22:03.392 [INFO ] [ab.core.model.script.UniversalDimmer] - Transition Light_DimmerGanglamp PercentType from 50 => 50 over 6000 ms
2021-11-14 11:22:03.600 [INFO ] [ab.core.model.script.UniversalDimmer] - Finished transitioning Light_DimmerGanglamp from 50 => 50

Then, after 1 minute of constant movement, it just starts the Executing timer code part:

==> /var/log/openhab/openhab.log <==
2021-11-14 11:23:03.354 [INFO ] [org.openhab.core.model.script.test  ] - Executing timer code
==> /var/log/openhab/events.log <==
2021-11-14 11:23:03.367 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'dummyGanglampDimmerSlow' received command 0
2021-11-14 11:23:03.390 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'universaldimmer' received command Light_DimmerGanglamp,0,16000
2021-11-14 11:23:03.395 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'universaldimmer' changed from Light_DimmerGanglamp,50,6000 to Light_DimmerGanglamp,0,16000
==> /var/log/openhab/openhab.log <==
2021-11-14 11:23:03.413 [INFO ] [ab.core.model.script.UniversalDimmer] - Transition Light_DimmerGanglamp PercentType from 50 => 0 over 16000 ms
2021-11-14 11:23:03.631 [INFO ] [ab.core.model.script.UniversalDimmer] - itemName=Light_DimmerGanglamp set to 49.33, iteration=1, elapsedMs=213

So it doesn’t seem to look at the state dependence of the motion sensor

Oooh I found a better/smatter solution in the topic mentioned in my first message, that’s this rule:

var Timer occupancyTimer = null
val int timeoutMinutes = 1

rule "Motion stopped, set a timer to turn off the lights"
when
    Item Laundry_Motion received update
then
    // No motion detected, set a timer
    if(Laundry_Motion.state == OFF) {
        logInfo("Laundry", "Motion change: Setting timer for " + timeoutMinutes + " minutes.")
        occupancyTimer = createTimer(now.plusMinutes(timeoutMinutes, [ |
            Laundry1_Toggle.sendCommand(OFF)
            Laundry2_Toggle.sendCommand(OFF)
            occupancyTimer = null
        ])
    }
    else {
        occupancyTimer?.cancel
        occupancyTimer = null
    }
end

When saving the rule, it complains about a missing ) at line 15, so I placed it there and used my items, now it looks like this:

var Timer occupancyTimer = null
val int timeoutMinutes = 1

rule "Motion stopped, set a timer to turn off the lights"
when
    Item Philips_motion2_Occupancy_Gang received update
then
    // No motion detected, set a timer
    if(Philips_motion2_Occupancy_Gang.state == OFF) {
        logInfo("Laundry", "Motion change: Setting timer for " + timeoutMinutes + " minutes.")
        occupancyTimer = createTimer(now.plusMinutes(timeoutMinutes, [ |
            dummyGanglampDimmerSlow.sendCommand(0)
            occupancyTimer = null
        ])
    )}
    else {
        occupancyTimer?.cancel
        occupancyTimer = null
    }
end

But it gives me this error after the item changes it state to OFF:

2021-11-14 12:36:27.773 [INFO ] [org.openhab.core.model.script.Test  ] - Motion change: Setting timer for 1 minutes.
2021-11-14 12:36:27.777 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'Motion_Gang_OFF-1' failed: An error occurred during the script execution: index=1, size=1 in Motion_Gang_OFF

So the loginfo did run correctly, but the timer function seems to create an error, but I can’t figure out what’s wrong with it…

The extra/missing bracket belongs in there, its xx.plusMinutes(zz) in form.

Beware of

in case of your device sending routine updates that report the same unchanged state.
Say for example your motion went OFF and started a 5-minute timer. After two minutes, the device reports “still OFF”. This update will trigger your rule and blindly start yet another timer.

change rule triggers are also available to allow to choose appropriate triggers.

Yea I know, so that’s correct now. But when the rule runs, it gives me this error when it runs the create timer part:

2021-11-14 12:36:27.773 [INFO ] [org.openhab.core.model.script.Test  ] - Motion change: Setting timer for 1 minutes.
2021-11-14 12:36:27.777 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'Motion_Gang_OFF-1' failed: An error occurred during the script execution: index=1, size=1 in Motion_Gang_OFF

Okay, what does the rule look like now? Shifting brackets about has dramatic effects and “I think its in the right place now” doesn’t help much with accurate analysis.
The unhelpful error message s usually about more or less parameters than expected, e.g. the effect you might get from misplaced brackets.

Ok, because you said this, I found it :slight_smile:

It was this:

var Timer occupancyTimer = null
val int timeoutMinutes = 1

rule "Motion stopped, set a timer to turn off the lights"
when
    Item Philips_motion2_Occupancy_Gang received update
then
    // No motion detected, set a timer
    if(Philips_motion2_Occupancy_Gang.state == OFF) {
        logInfo("Laundry", "Motion change: Setting timer for " + timeoutMinutes + " minutes.")
        occupancyTimer = createTimer(now.plusMinutes(timeoutMinutes, [|
            dummyGanglampDimmerSlow.sendCommand(0)
            occupancyTimer = null
        ])
    )}
    else {
        occupancyTimer?.cancel
        occupancyTimer = null
    }
end

The logging said it was missing at line 15 so I placed it there, then it gives me the error I posted earlier. But then I placed the bracket at line 11 around timeoutMinutes → (timeoutMinutes) and removed it from line 15 again like this:

var Timer occupancyTimer = null
val int timeoutMinutes = 1

rule "Motion stopped, set a timer to turn off the lights"
when
    Item Philips_motion2_Occupancy_Gang received update
then
    // No motion detected, set a timer
    if(Philips_motion2_Occupancy_Gang.state == OFF) {
        logInfo("Laundry", "Motion change: Setting timer for " + timeoutMinutes + " minutes.")
        occupancyTimer = createTimer(now.plusMinutes(timeoutMinutes), [|
            dummyGanglampDimmerSlow.sendCommand(0)
            occupancyTimer = null
        ])
    }
    else {
        occupancyTimer?.cancel
        occupancyTimer = null
    }
end

Now it’s working like I wanted, when I keep moving in the hallway, it stays on, if I pause for 30 secondes and start again, it cancels the timer so the light will stay on! :slight_smile:

Thanks a lot for thinking with me.

Interpret the error logging as saying “I got to line 15 and hadn’t found the expected bracket by then”. If it knew where it really belonged, it wouldn’t need to flag an error.

1 Like

That’s a good point, will try to look differently at error’s like this.

@rossko57 maybe you can think with me again, I experience some strange behaviour.
When I keep moving in front of the sensor, sometimes stops and then move again, there get created 2 timers… you can see here:

2021-11-16 08:13:27.172 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Philips_motion_Occupancy_WC' changed from ON to OFF

==> /var/log/openhab/openhab.log <==

2021-11-16 08:13:27.178 [INFO ] [org.openhab.core.model.script.WC BG ] - Motion change: Setting timer for 2 minutes.

==> /var/log/openhab/events.log <==

2021-11-16 08:13:35.177 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Philips_motion_Occupancy_WC' changed from OFF to ON

==> /var/log/openhab/openhab.log <==

2021-11-16 08:13:35.183 [INFO ] [org.openhab.core.model.script.WC BG ] - Timer canceled, value is now: null.

==> /var/log/openhab/events.log <==

2021-11-16 08:13:35.190 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'WCLamp_Switch' received command ON

2021-11-16 08:13:35.200 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'WCLamp_Switch' predicted to become ON

2021-11-16 08:13:35.236 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Philips_motion_Illuminance_WC' changed from 1.5351286304979075 to 1.4249344310334724

2021-11-16 08:13:40.195 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Philips_motion_Illuminance_WC' changed from 1.4249344310334724 to 1.5351286304979075

2021-11-16 08:13:43.618 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ThermostaatLogeerKamer_Temperature' changed from 17.71 °C to 17.77 °C

2021-11-16 08:13:43.621 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ThermostaatLogeerKamer_Humidity' changed from 60.70 to 60.40

2021-11-16 08:13:45.174 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Philips_motion_Occupancy_WC' changed from ON to OFF

==> /var/log/openhab/openhab.log <==

2021-11-16 08:13:45.179 [INFO ] [org.openhab.core.model.script.WC BG ] - Motion change: Setting timer for 2 minutes.

2021-11-16 08:13:46.772 [INFO ] [org.openhab.core.model.script.WC BG ] - Motion change: Setting timer for 2 minutes.

==> /var/log/openhab/events.log <==

2021-11-16 08:13:52.749 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Philips_motion_Occupancy_WC' changed from OFF to ON

==> /var/log/openhab/openhab.log <==

2021-11-16 08:13:52.757 [INFO ] [org.openhab.core.model.script.WC BG ] - Timer canceled, value is now: null.

What will happen next is that on the next movement the rule cancels only 1 timer and the 2nd keeps running, when it is done, it just turns off…
Any thoughts why it creates 2 timers instead of 1?

Well done, figuring out the underlying problem.

Yes, I already said

Hehe thank you :slight_smile: getting better in understanding it!

But that is the thing I don’t understand, because the device isn’t sending routine updates, only when there is motion, it changes to ON, when no motion is detected for 10 secondes, it turns to OFF. But say for example I keep moving for several minutes it isn’t sending a update that’s says STILL ON.
And it this case, the trigger to start a timmer is when it updates to OFF, it seems like the cancelling of the first timer don’t happen when this part off the rule runs:

    else {
        if(occupancyTimer !== null) occupancyTimer.cancel
        occupancyTimer = null

First I had this, and was hoping that the above change did help, but not…

    else {
        occupancyTimer?.cancel
        occupancyTimer = null

Just to eradicate one possible source of confusion -
If/when you edit a xxx.rules file, drastic stuff happens. Internal variables all reset etc. In this case that would mean occupancyTimer set to null.
What doesn’t happen is aborting any timer that is already running, they just carry on. It might blow up when the time comes, as any variables it uses have been messed about. But simple tasks can still execute.
There’s nothing you can do about that because your only lifeline to the independent timer, the handle variable occupancyTimer, has been destroyed.

I don’t think that’s what your looking at, but it easily pops up as additional confusion when fiddling with an existing problem. Be aware of what might still be timing when editing.

Something (re) triggers your rule, because that’s the only way to get a timer made. Updates-to-same value don’t get visibly logged. Some device technologies give more or less updates (your device is still a mystery here).

Let’s find out -

when
    Item Philips_motion2_Occupancy_Gang received update
then
    logInfo("test", "There is an update")
    logInfo("test", "triggering state " + newState.toString) // from the update event
    logInfo("test", "Item state " + Philips_motion2_Occupancy_Gang.state.toString) // from the Item
    ...

My previous suggestion was that, for this rule, you don’t need or want to know about updates at all. You’re interested in changes.

Good to keep in mind, so when editing rules and discovering strange behaviour then expected, a reboot can be the solution :slight_smile:

Didn’t know that, so I changed my rule to this to test out:

var Timer occupancyTimer = null
val int timeoutMinutes = 2

rule "Motion WC turn OFF"
when
    Item Philips_motion_Occupancy_WC received update
then
    logInfo("test", "There is an update")
    logInfo("test", "triggering state " + newState.toString) // from the update event
    logInfo("test", "Item state " + Philips_motion2_Occupancy_Gang.state.toString) // from the Item
    // No motion detected, set a timer
    if(Philips_motion_Occupancy_WC.state == OFF) {
        logInfo("WC BG", "Motion change: Setting timer for " + timeoutMinutes + " minutes.")
        occupancyTimer = createTimer(now.plusMinutes(timeoutMinutes), [|
            WCLamp_Switch.sendCommand(OFF)
            logInfo("WC BG", "Timer done, light off!")
            occupancyTimer = null
        ])
    }
    else {
        if(occupancyTimer !== null) occupancyTimer.cancel
        logInfo("WC BG", "Timer canceled.")
        occupancyTimer = null
        logInfo("WC BG", "Value is now set to: " + occupancyTimer + ".")
    }
end

And… I think you’re right, it does more then I normally see in the logging:

==> /var/log/openhab/openhab.log <==

2021-11-16 12:42:00.107 [INFO ] [org.openhab.core.model.script.test ] - There is an update

2021-11-16 12:42:00.113 [INFO ] [org.openhab.core.model.script.test ] - triggering state ON

==> /var/log/openhab/events.log <==

2021-11-16 12:42:00.164 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'WCLamp_Switch' received command ON

==> /var/log/openhab/openhab.log <==

2021-11-16 12:42:00.175 [INFO ] [org.openhab.core.model.script.test ] - Item state OFF

2021-11-16 12:42:00.183 [INFO ] [org.openhab.core.model.script.WC BG ] - Timer canceled.

==> /var/log/openhab/events.log <==

2021-11-16 12:42:00.186 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'WCLamp_Switch' predicted to become ON

==> /var/log/openhab/openhab.log <==

2021-11-16 12:42:00.189 [INFO ] [org.openhab.core.model.script.WC BG ] - Value is now set to: null.

==> /var/log/openhab/events.log <==

2021-11-16 12:42:00.197 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'WCLamp_Switch' changed from OFF to ON

2021-11-16 12:42:00.296 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'WCLamp_Switch_HK' changed from OFF to ON

2021-11-16 12:42:05.094 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Philips_motion_Illuminance_WC' changed from 0.0 to 1.2044487164510587

2021-11-16 12:42:14.413 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Philips_motion_Occupancy_WC' changed from ON to OFF

==> /var/log/openhab/openhab.log <==

2021-11-16 12:42:14.417 [INFO ] [org.openhab.core.model.script.test ] - There is an update

2021-11-16 12:42:14.423 [INFO ] [org.openhab.core.model.script.test ] - triggering state OFF

2021-11-16 12:42:14.430 [INFO ] [org.openhab.core.model.script.test ] - Item state OFF

2021-11-16 12:42:14.437 [INFO ] [org.openhab.core.model.script.WC BG ] - Motion change: Setting timer for 2 minutes.

==> /var/log/openhab/events.log <==

2021-11-16 12:42:14.468 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Philips_motion_Illuminance_WC' changed from 1.2044487164510587 to 1.0945946985813975

2021-11-16 12:42:29.820 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Sensor_CPUTemp' changed from 37.0 to 36.5

==> /var/log/openhab/openhab.log <==

2021-11-16 12:42:33.699 [INFO ] [org.openhab.core.model.script.test ] - There is an update

==> /var/log/openhab/events.log <==

2021-11-16 12:42:33.705 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Philips_motion_Occupancy_WC' changed from OFF to ON

==> /var/log/openhab/openhab.log <==

2021-11-16 12:42:33.707 [INFO ] [org.openhab.core.model.script.test ] - triggering state ON

==> /var/log/openhab/events.log <==

2021-11-16 12:42:33.712 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'WCLamp_Switch' received command ON

==> /var/log/openhab/openhab.log <==

2021-11-16 12:42:33.714 [INFO ] [org.openhab.core.model.script.test ] - Item state OFF

2021-11-16 12:42:33.722 [INFO ] [org.openhab.core.model.script.WC BG ] - Timer canceled.

==> /var/log/openhab/events.log <==

2021-11-16 12:42:33.725 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'WCLamp_Switch' predicted to become ON

==> /var/log/openhab/openhab.log <==

2021-11-16 12:42:33.729 [INFO ] [org.openhab.core.model.script.WC BG ] - Value is now set to: null.

==> /var/log/openhab/events.log <==

2021-11-16 12:42:33.753 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Philips_motion_Illuminance_WC' changed from 1.0945946985813975 to 1.2044487164510587

2021-11-16 12:42:38.715 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Philips_motion_Illuminance_WC' changed from 1.2044487164510587 to 1.0945946985813975

==> /var/log/openhab/openhab.log <==

2021-11-16 12:42:43.673 [INFO ] [org.openhab.core.model.script.test ] - There is an update

==> /var/log/openhab/events.log <==

2021-11-16 12:42:43.673 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Philips_motion_Occupancy_WC' changed from ON to OFF

==> /var/log/openhab/openhab.log <==

2021-11-16 12:42:43.680 [INFO ] [org.openhab.core.model.script.test ] - triggering state OFF

2021-11-16 12:42:43.694 [INFO ] [org.openhab.core.model.script.test ] - Item state OFF

2021-11-16 12:42:43.700 [INFO ] [org.openhab.core.model.script.WC BG ] - Motion change: Setting timer for 2 minutes.

2021-11-16 12:42:45.291 [INFO ] [org.openhab.core.model.script.test ] - There is an update

2021-11-16 12:42:45.296 [INFO ] [org.openhab.core.model.script.test ] - triggering state OFF

2021-11-16 12:42:45.301 [INFO ] [org.openhab.core.model.script.test ] - Item state OFF

2021-11-16 12:42:45.307 [INFO ] [org.openhab.core.model.script.WC BG ] - Motion change: Setting timer for 2 minutes.

==> /var/log/openhab/events.log <==

2021-11-16 12:42:57.979 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Philips_motion_Occupancy_WC' changed from OFF to ON

==> /var/log/openhab/openhab.log <==

2021-11-16 12:42:57.982 [INFO ] [org.openhab.core.model.script.test ] - There is an update

2021-11-16 12:42:57.994 [INFO ] [org.openhab.core.model.script.test ] - triggering state ON

==> /var/log/openhab/events.log <==

2021-11-16 12:42:57.994 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'WCLamp_Switch' received command ON

==> /var/log/openhab/openhab.log <==

2021-11-16 12:42:58.001 [INFO ] [org.openhab.core.model.script.test ] - Item state OFF

==> /var/log/openhab/events.log <==

2021-11-16 12:42:58.007 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'WCLamp_Switch' predicted to become ON

==> /var/log/openhab/openhab.log <==

2021-11-16 12:42:58.013 [INFO ] [org.openhab.core.model.script.WC BG ] - Timer canceled.

2021-11-16 12:42:58.022 [INFO ] [org.openhab.core.model.script.WC BG ] - Value is now set to: null.

==> /var/log/openhab/events.log <==

2021-11-16 12:43:03.059 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Philips_motion_Illuminance_WC' changed from 1.0945946985813975 to 3.519600000304825

2021-11-16 12:43:08.030 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Philips_motion_Illuminance_WC' changed from 3.519600000304825 to 3.9602092739597463

2021-11-16 12:43:16.261 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Philips_motion_Occupancy_WC' changed from ON to OFF

==> /var/log/openhab/openhab.log <==

2021-11-16 12:43:16.263 [INFO ] [org.openhab.core.model.script.test ] - There is an update

2021-11-16 12:43:16.270 [INFO ] [org.openhab.core.model.script.test ] - triggering state OFF

2021-11-16 12:43:16.275 [INFO ] [org.openhab.core.model.script.test ] - Item state OFF

2021-11-16 12:43:16.281 [INFO ] [org.openhab.core.model.script.WC BG ] - Motion change: Setting timer for 2 minutes.

==> /var/log/openhab/events.log <==

2021-11-16 12:44:43.705 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'WCLamp_Switch' received command OFF

==> /var/log/openhab/openhab.log <==

2021-11-16 12:44:43.705 [INFO ] [org.openhab.core.model.script.WC BG ] - Timer done, light off!

==> /var/log/openhab/events.log <==

2021-11-16 12:44:43.712 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'WCLamp_Switch' predicted to become OFF

2021-11-16 12:44:43.718 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'WCLamp_Switch' changed from ON to OFF

2021-11-16 12:44:43.794 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'WCLamp_Switch_HK' changed from ON to OFF

2021-11-16 12:44:55.948 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ThermostaatMasterBedroom_Temperature' changed from 15.87 °C to 15.83 °C

2021-11-16 12:44:55.956 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'ThermostaatKleineKamer_Temperature' changed from 18.63 °C to 18.64 °C

2021-11-16 12:45:16.287 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'WCLamp_Switch' received command OFF

==> /var/log/openhab/openhab.log <==

2021-11-16 12:45:16.287 [INFO ] [org.openhab.core.model.script.WC BG ] - Timer done, light off!

==> /var/log/openhab/events.log <==

2021-11-16 12:45:16.296 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'WCLamp_Switch' predicted to become OFF

Now I’m already breaking my brain how to work around this issue… would a proxy item be a solution because the state won’t change or triggers another timer?

The problem is having the rule trigger on update, which (by design) includes update-to-same. Don’t do that, have the rule trigger on change, which, well, means what it says.
This is why the designers offered the choice.

That’s probably over-drastic. You only get surprises if the edited file has spawned some long-running timers, and then usually it doesn’t cause any problem beyond “what’s this funny timer error in my log?” or “why did that light go off?” - which you wouldn’t notice unless you’re looking for something else.
Editing rules files is not everyday work. Put any critical timers in a separate rules file where they won’t get messed with.

Yea that seems to do the trick, brilliant :slight_smile: I changed:

when
    Item Philips_motion_Occupancy_WC received update

to

when
    Item Philips_motion_Occupancy_WC changed

and didn’t see any double timers ever since.

True, and I did indeed placed any rule with a timer in a separate rule so nothing get messed with each other.
Thanks for the help again :slight_smile: