i want to create a rule and need some help at this point now.
what i want to do:
i got two switch items and i want to fire the rule if item2 changed to on, but only if item1 changed to on, too, in a period of time before item2 (for excample 10 minutes)
usually i would do something like this:
when
item2 changed to on
then
if item1.state == ON (for max. 10 minutes) …
Set a global variable with the time stamp when item1 changes to ON and check that variable in the Rule triggered by item2.
var item1Changed = now.minusDays(1) // initialize to sometimes in the past
rule "item 1 changed to ON"
when
Item item1 changed to ON
then
item1Changed = now
end
rule "item2 changed to ON"
when
Item item2 changed to ON
then
if(item1.state == ON && item1Changed.isAfter(now.minusMinutes(10)) {
...
}
end
Set up persistence on item1 and use lastUpdate.
rule "item2 changed to ON"
when
Item item2 changed to ON
then
if(item1.state == ON && item1.lastUpdate.isBefore(now.minusMinutes(10).millis){
...
}
end
I am trying to do this but for some reason, I can’t get either option to work is there a different way you have to do this in the 2.5 version of openhab?