I have a rule that when a music player is stopped (Sonos) (itemstate changed to PAUSE), it turns off an amplifer after 10 min (by sending commands to a Global caché IP controler onnect by RS232 to the amp)
But if the state of player changes to PLAY again during this 10min (during the timer), it should cancel the timer and not turn off the amp after those 10min.
2022-12-10 21:31:36.498 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'SonosConnectSalon_MediaControl' changed from UNDEF to PLAY
It’s really helpful to show the full rule trigger here, by using the code tab.
As you’ve helpfully included a logInfo to show when the trule runs, it would be helpful to include the log of that (openhab.log) as well as the events.log
But you misunderstand how rules and timers work, perhaps.
When the rule is triggered and run, it sets up the timer code for future execution. Then having done the setup, the rule immediately continues executes any following code (the if() block in this case) and the rule exits, all within milliseconds.
It’s like setting an alarm clock - the clock does not stop.
Then the timer code runs at some later time.
Perhaps you meant to trigger the rule on some other changes or updates, so that it can examine the current change and cancel any running timer.
After the state goed to PAUSE it turns off the amp after 2min which is normal.
But if i press P¨LAY again during those 2 min it does nog cancel the timer
2022-12-11 09:10:02.548 [INFO ] [org.openhab.rule.eb31657142 ] - Sonos Salon state change to Play
==> /var/log/openhab/events.log <==
2022-12-11 09:10:02.567 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'GlobalCacheGC10012_Slm1_C1direct' received command %02%04%a0%60%00%01%fb
2022-12-11 09:10:02.569 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'GlobalCacheGC10012_Slm1_C1direct' predicted to become %02%04%a0%60%00%01%fb
2022-12-11 09:10:02.579 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'GlobalCacheGC10012_Slm1_C1direct' changed from %02%06%a0%52%00%01%e2%00%25 to %02%04%a0%60%00%01%fb
2022-12-11 09:10:03.174 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'GlobalCacheGC10012_Slm1_C1direct' received command %02%04%a0%42%00%02%18
2022-12-11 09:10:03.176 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'GlobalCacheGC10012_Slm1_C1direct' predicted to become %02%04%a0%42%00%02%18
2022-12-11 09:10:03.179 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'GlobalCacheGC10012_Slm1_C1direct' changed from %02%04%a0%60%00%01%fb to %02%04%a0%42%00%02%18
2022-12-11 09:10:03.784 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'GlobalCacheGC10012_Slm1_C1direct' received command %02%06%a0%52%00%01%ff%fe%0a
2022-12-11 09:10:03.787 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'GlobalCacheGC10012_Slm1_C1direct' predicted to become %02%06%a0%52%00%01%ff%fe%0a
2022-12-11 09:10:03.792 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'GlobalCacheGC10012_Slm1_C1direct' changed from %02%04%a0%42%00%02%18 to %02%06%a0%52%00%01%ff%fe%0a
2022-12-11 09:10:05.984 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'SonosConnectSalon_MediaControl' changed from UNDEF to PLAY
==> /var/log/openhab/openhab.log <==
2022-12-11 09:10:14.586 [INFO ] [org.openhab.rule.911aba0794 ] - Sonos Salon state change to Pause
==> /var/log/openhab/events.log <==
2022-12-11 09:10:14.540 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'SonosConnectSalon_MediaControl' changed from PLAY to PAUSE
==> /var/log/openhab/openhab.log <==
2022-12-11 09:11:58.418 [INFO ] [org.openhab.rule.911aba0794 ] - Set volume to -30.0
==> /var/log/openhab/events.log <==
2022-12-11 09:11:58.430 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'GlobalCacheGC10012_Slm1_C1direct' received command %02%06%a0%52%00%01%e2%00%25
2022-12-11 09:11:58.433 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'GlobalCacheGC10012_Slm1_C1direct' predicted to become %02%06%a0%52%00%01%e2%00%25
2022-12-11 09:11:58.446 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'GlobalCacheGC10012_Slm1_C1direct' changed from %02%06%a0%52%00%01%ff%fe%0a to %02%06%a0%52%00%01%e2%00%25
==> /var/log/openhab/openhab.log <==
2022-12-11 09:11:59.438 [INFO ] [org.openhab.rule.911aba0794 ] - Turn Amp Off
==> /var/log/openhab/events.log <==
2022-12-11 09:11:59.450 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'GlobalCacheGC10012_Slm1_C1direct' received command %02%04%a0%60%00%00%fc
2022-12-11 09:11:59.453 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'GlobalCacheGC10012_Slm1_C1direct' predicted to become %02%04%a0%60%00%00%fc
2022-12-11 09:11:59.460 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'GlobalCacheGC10012_Slm1_C1direct' changed from %02%06%a0%52%00%01%e2%00%25 to %02%04%a0%60%00%00%fc