# How do I determine if a timer is set (but not currently executing)?

**URL:** <https://community.openhab.org/t/how-do-i-determine-if-a-timer-is-set-but-not-currently-executing/8369>\
**Category:** Scripts & Rules\
**Created:** [March 7, 2016, 1:52am UTC](https://community.openhab.org/t/how-do-i-determine-if-a-timer-is-set-but-not-currently-executing/8369 "2016-03-07T01:52:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheKorn](https://community.openhab.org/user_avatar/community.openhab.org/thekorn/32/3669_2.png) [@TheKorn](https://community.openhab.org/u/TheKorn)\
**Post date:** [March 7, 2016, 1:52am UTC](https://community.openhab.org/t/how-do-i-determine-if-a-timer-is-set-but-not-currently-executing/8369/1 "2016-03-07T01:52:54Z")

</div>

Trying to set up a rule something like

- first press of a button, set up timer to do something in 60 minutes
- second press, re-set timer to now + 60 minutes

In order to do this, I need to determine if a timer is set to go off in the future. It would seem that the .isRunning feature of a timer would be what I need, but it seems that .isRunning only returns true if the timer is actually executing the timer’s code block, not if it’s merely scheduled sometime in the future.

Sooooo… how do I determine if a timer is set in the future, so I can reset it? I’d rather not blindly call timer.reschedule, since if the timer isn’t set in the first place it’ll generate an error.

Thanks!

---

<div class="post-metadata">

**Author:** ![bob\_dickenson](https://community.openhab.org/user_avatar/community.openhab.org/bob_dickenson/32/856_2.png) [@bob\_dickenson](https://community.openhab.org/u/bob_dickenson)\
**Post date:** [March 7, 2016, 2:10am UTC](https://community.openhab.org/t/how-do-i-determine-if-a-timer-is-set-but-not-currently-executing/8369/2 "2016-03-07T02:10:18Z")

</div>

how about …

```
if (timer_whatever !=null {

}
```

---

<div class="post-metadata">

**Author:** ![TheKorn](https://community.openhab.org/user_avatar/community.openhab.org/thekorn/32/3669_2.png) [@TheKorn](https://community.openhab.org/u/TheKorn)\
**Post date:** [March 7, 2016, 2:57am UTC](https://community.openhab.org/t/how-do-i-determine-if-a-timer-is-set-but-not-currently-executing/8369/3 "2016-03-07T02:57:01Z")

</div>

That’d work for the first run through, but once the timer expires, does it revert back to null? (I.e. would that work the next day?)

---

<div class="post-metadata">

**Author:** ![TheKorn](https://community.openhab.org/user_avatar/community.openhab.org/thekorn/32/3669_2.png) [@TheKorn](https://community.openhab.org/u/TheKorn)\
**Post date:** [March 7, 2016, 4:07am UTC](https://community.openhab.org/t/how-do-i-determine-if-a-timer-is-set-but-not-currently-executing/8369/4 "2016-03-07T04:07:15Z")

</div>

Nevermind, guess timers revert back to null once they’ve gone off. Thanks!

---

<div class="post-metadata">

**Author:** ![Udo\_Hartmann](https://community.openhab.org/user_avatar/community.openhab.org/udo_hartmann/32/70871_2.png) [@Udo\_Hartmann](https://community.openhab.org/u/Udo_Hartmann)\
**Post date:** [March 7, 2016, 9:40am UTC](https://community.openhab.org/t/how-do-i-determine-if-a-timer-is-set-but-not-currently-executing/8369/5 "2016-03-07T09:40:47Z")

</div>

Don’t forget to set `timer_whatever = null` if you cancel `timer_whatever` 🙂

---

<div class="post-metadata">

**Author:** ![TheKorn](https://community.openhab.org/user_avatar/community.openhab.org/thekorn/32/3669_2.png) [@TheKorn](https://community.openhab.org/u/TheKorn)\
**Post date:** [March 7, 2016, 4:04pm UTC](https://community.openhab.org/t/how-do-i-determine-if-a-timer-is-set-but-not-currently-executing/8369/6 "2016-03-07T16:04:25Z")

</div>

> [@Udo\_Hartmann](#):
>
> Don’t forget to set `timer_whatever = null` if you cancel `timer_whatever` 🙂

Good tip, thanks for the reminder!

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [March 7, 2016, 4:37pm UTC](https://community.openhab.org/t/how-do-i-determine-if-a-timer-is-set-but-not-currently-executing/8369/7 "2016-03-07T16:37:44Z")

</div>

There is `timer.hasTerminated` or you can make sure that the timer gets set to null after it has gone off. As others have suggested, make sure to set the variable to null wherever you happen to cancel it.
