[SOLVED] Alarm based on slider value

Hi,
I am testing a simple rule which triggers based on time-of-day where the trigger setting is derived from a slider in the sitemap. the JS numbertoclock transformation is just to display the setpoint value correctly.

Items
Number TimerOn

Sitemap
Setpoint item=TimerOn label=“TimerOn [JS(numberToClock.js):%s]” minValue=0 maxValue=1440 step=15

Rules
rule “Alarm”
when
//run every minute
Time cron “0 * * ? * *”
then
var int Var_TimerOn = TimerOn.state
if (now.getMinuteOfDay > Var_TimerOn ) {
//Alarm triggered so do something
postUpdate(Alarm, ON )
}
end

Error message:
2019-09-06 09:50:00.254 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule ‘Alarm’: An error occurred during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.IntegerExtensions.operator_greaterThan(int,int) on instance: null

TimerOn.state as Number

same error, it does look like it is a type mismatch though. My editor flags “Type mismatch: cannot convert from Number to int”

Rules often just sorts out vague typing, but the comparison operators are especially picky.

The now method returns an integer, so we have to force the state to integer.
(TimerOn.state as Number).intValue

1 Like

Great, that works. Very picky!

Many Thanks