# createTimer error in rules script

**URL:** <https://community.openhab.org/t/createtimer-error-in-rules-script/75744>\
**Category:** Scripts & Rules\
**Tags:** rules\
**Created:** [June 4, 2019, 5:51am UTC](https://community.openhab.org/t/createtimer-error-in-rules-script/75744 "2019-06-04T05:51:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aatshi](https://community.openhab.org/letter_avatar_proxy/v4/letter/a/90db22/32.png) [@Aatshi](https://community.openhab.org/u/Aatshi)\
**Post date:** [June 4, 2019, 5:51am UTC](https://community.openhab.org/t/createtimer-error-in-rules-script/75744/1 "2019-06-04T05:51:19Z")

</div>

- Platform information:
  - Hardware: x86\_64 Intel Dual Core CPU
  - OS: Debian 9
  - Java Runtime Environment: Zulu 8.38.0.13
  - openHAB version: 2.4.0.1

- Issue of the topic:

Hi, I am trying to test a rules script but seem to have a problem with createTimer. This is the rules script:

```auto
import org.joda.time
import org.openhab.model.script.actions.Timer

var Timer timer = null    

rule "Pump Timer1"
when
    Item Sonoff_4CH_Power4 changed to ON      
then
    sendCommand(Sonoff_4CH_Power1, ON)
    logInfo("Switch on","My switch on rule triggered on")
    timer = Timer.createTimer(now.plusSeconds(1) [|
        sendCommand(Sonoff_4CH_Power1, OFF)
        timer = null // reset the timer
    ])
    logInfo("Switch off","My switch on rule triggered off")
end

```

Sonoff\_4CH\_Power1 does switch on but seem to stop there  
I cannot locate the packages to import anywhere on the system.  
I have cleared the cache as some posts have suggested. Before I reinstall OH again, maybe someone can help me with this issue. The error in the log file:

```auto
2019-06-04 12:31:47.370 [INFO] [pse.smarthome.model.script.Switch on] - My switch on rule triggered on
2019-06-04 12:31:47.529 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Pump Timer1': 'createTimer' is not a member of 'java.lang.Class<org.eclipse.smarthome.model.script.actions.Timer>'; line 13, column 13, length 135

```

Many thanks in advance.

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [June 4, 2019, 8:51am UTC](https://community.openhab.org/t/createtimer-error-in-rules-script/75744/2 "2019-06-04T08:51:41Z")

</div>

> [@Aatshi](#):
>
> import org.joda.time  
> import org.openhab.model.script.actions.Timer

This gives away that you have started from an old tutorial or example for OH1.  
Assuming you use OH2, these are not needed and indeed mess things up.

Better example

> [@Design Pattern: Motion Sensor Timer](https://community.openhab.org/t/design-pattern-motion-sensor-timer/14954):
>
> Edit: Updates for OH 4 Please see [Design Pattern: What is a Design Pattern and How Do I Use Them](https://community.openhab.org/t/design-pattern-what-is-a-design-pattern-and-how-do-i-use-them/40319) for details on how to use DPs. Problem Statement Many motion detectors only report ON when they detect motion but do not send a corresponding OFF after no motion has been detected after a period of time. In addition, often one wants to control a device like a light for a certain period after the last motion is seen, not after the motion sensor goes to OFF. Therefore one needs to keep a Contact OPEN…

Restructuring like this will give you a better idea of how timer works

```php
   ...
    timer = Timer.createTimer(now.plusSeconds(1) [|
        logInfo("Switch off","My timer executing")
        sendCommand(Sonoff_4CH_Power1, OFF)
        timer = null // reset the timer
    ])
    logInfo("Switch off","My switch on rule exiting")
end

```

---

<div class="post-metadata">

**Author:** ![Aatshi](https://community.openhab.org/letter_avatar_proxy/v4/letter/a/90db22/32.png) [@Aatshi](https://community.openhab.org/u/Aatshi)\
**Post date:** [June 5, 2019, 1:59am UTC](https://community.openhab.org/t/createtimer-error-in-rules-script/75744/3 "2019-06-05T01:59:57Z")

</div>

Thank you very much for your reply. I tried running the rule without the import declarations but I am still getting the same error in the logs. Seems like the Timer class is missing on my system? If I can locate or know where it should now be living then maybe I can take it from there. I should also mention that I am doing these tests offline. Will this have a negative effect?

```auto
var Timer PumpTimer = null

rule "Pump Timer On"

when
    Item Sonoff_4CH_Power4 changed to ON
then
    sendCommand(Sonoff_4CH_Power1, ON)
    logInfo("Switch on","My Pump Timer On rule triggered on")
    PumpTimer = Timer.createTimer(now.plusSeconds(5) [|
        logInfo("Switch off","My Pump Timer On rule triggered off")
        sendCommand(Sonoff_4CH_Power1, OFF)
        sendCommand(Sonoff_4CH_Power4, OFF)
        PumpTimer = null // reset the timer
    ])

end

```

2019-06-05 08:54:21.151 [INFO] [el.core.internal.ModelRepositoryImpl] - Loading model ‘default.rules’  
2019-06-05 08:54:52.600 [INFO] [pse.smarthome.model.script.Switch on] - My Pump Timer On rule triggered on  
2019-06-05 08:54:52.602 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Pump Timer On’: ‘createTimer’ is not a member of ‘java.lang.Class\<org.eclipse.smarthome.model.script.actions.Timer\>’; line 10, column 17, length 254

```auto

```

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [June 5, 2019, 9:46am UTC](https://community.openhab.org/t/createtimer-error-in-rules-script/75744/4 "2019-06-05T09:46:13Z")

</div>

> [@Aatshi](#):
>
> PumpTimer = Timer.createTimer(now.plusSeconds(5) [|

Oh, I missed this. As per all the examples you’ve seen, get rid of Timer here.

`PumpTimer = createTimer(now.plusSeconds(5) [|`
