What is this command?

Quick question I have got some help by copying a rule and modified it to my belongings, but there is one command I don´t understand, especially what is the (1) for - is this for one minute?

var DateTime lastRun = now.minusMinutes(1)

yes

1 Like

Thanks,
Sorry to ask such questions but
what really does it mean, why should I set something minus minutes

now.minusMinutes(1)

For example to check if between now.minusXxx(x) and now a item was changed.

1 Like

now returns the current time, minusMinutes() is a method that returns a time a set number of minutes before the DateTime you attach it to.

As an example of how it can be used, If your openHAB system uses persistence, i.e. A database that records a value each minute, the function would be useful to finding out what that saved value was.

If you need more information, it might be helpful to post the rule you’re looking at. We might be able to explain in context.

Oh OK, here is the rule, another member (Scot) helped me here and he was commenting //on a reboot switch on sirene on the first event - but I don´t understand the sense of that command I mean this “now.minusMinutes(1)”

var Timer shutoffTimer = null
var DateTime lastRun = now.minusMinutes(1)// on a reboot switch on sirene on the first event

rule “PIR Neo_PIR_1 for Switch with Siren”
when
Item NEO_PIR_1_Bewegung changed from OFF to ON
then
if (shutoffTimer === null && AlarmInnen.state == ON && lastRun.isBefore(now.minusMinutes(1))) {
zwave_device_296beed3_node4_switch_binary.sendCommand(ON)
lastRun = now
logInfo(“RuleInfo”, “Siren START”)
shutoffTimer = createTimer(now.plusSeconds(10)) [|// you should have been using the global variable here
zwave_device_296beed3_node4_switch_binary.sendCommand(OFF)
logInfo(“RuleInfo”, “Siren STOP”)
shutoffTimer = null// and here
]
}
end

If the last run of this rule was before more than one minute

1 Like

I didn’t put in that cimment… it was in the original rule you’d posted. :slight_smile:

The lastRun variable needs a value assigned to it, so that it can be used in the comparison lastRun.isBefore(now.minusMinutes(1)). Setting it to now.minusMinutes(1) puts it at a time that will allow the rule to always run the first time it is triggered after a rule file save or OH restart.

Thank you!