OH2: No modulo?

OHv2 on rPi3

I am trying to get the minutes via modulo using the “%” sign.
It throws an error:

2021-10-18 06:00:00.012 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'SLO window blind non-astro time ON': Unknown variable or command '%'; line 67, column 33, length 6

in this rule:

rule "SLO window blind non-astro time ON"
        //         s m  h  D M DoW Y
        Time cron "0 0/5 5-7 * * ? *"
        // here: every 5 minutes between 5 and 7; use http://www.cronmaker.com/
        if (Shed_SLO_Blind_NonAstro.state == ON)
            var Number i = (Shed_SLO_TimeSetter.state as DecimalType).intValue()
            var Number h = (i / 60)

            if (h == now.getHourOfDay())
                var Number m = (i % 60)

                if (m == now.getMinuteOfHour())

… with the line number pointing to this line:

var Number m = (i % 60)

… which VScode also red lined.

This post claims it should work:

Any hints appreciated.

That’s not an integer.
In general, don’t try to force types in DSL until you have to.
var i = (Shed_SLO_TimeSetter.state as DecimalType).intValue()

Are you trying to schedule an action? Why not schedule it when your target time Item changes.

var Timer TODtimer = null    // for time-of-day rule

rule "Schedule stuff"
	Item someMinutesTarget changed
	    // get the DateTime for the start of the timer
	    // this works on DST change days, unlike plusMinutes
    var next = now.withTimeAtStartOfDay.plusDays(1).minusMinutes(1440-(someMinutesTarget.state as Number).intValue)
	TODtimer?.cancel // kill any old timer
	if (now.isAfter(next)) { next = next.plusDays(1) } // fix day if too late today
	TODtimer = createTimer(next) [ |
		// do your thing

I cribbed this from this forum somewhere years ago (@rlkoshak probably).
You may refine it to deal with system reboot, if you persist and restore your target minutes Item.
You may set it up to run again next day, say run rule once at 00:05

1 Like

Thanks, removing ‘Number’ removed the wiggly line.