Hi, I am trying to test a rules script but seem to have a problem with createTimer. This is the rules script:
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:
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
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?
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