I have a little problem with a simple rule.
it happens after reboot or after reload the rule file.
When the rule is the first time triggered it has a delay, when it triggers additional times there is no delay anymore and the rule works as expected.
I have several *.rule files with nearly similar code in it and it is the same delay on all files.
(I use a RPi3 with OH 2.2.0 newest snapshot version)
Rule:
var long whenStarted2
rule "Button Pressed2"
when
Item Mod_2i changed from OFF to ON
then
whenStarted2=now.millis
end
rule "Button Released2"
when
Item Mod_2i changed from ON to OFF
then
val whenStopped2 = now.millis
val timeTaken2 = whenStopped2-whenStarted2
if (timeTaken2 < 800 ) {
if (Mod_4.state != ON ) {
sendCommand(Mod_4, ON)
}else {
sendCommand(Mod_4, OFF)
}
}
if (timeTaken2 >= 800 && timeTaken2 < 2000 ){
if (Mod_5.state != ON ) {
sendCommand(Mod_5, ON)
}else {
sendCommand(Mod_5, OFF)
}
}
if (timeTaken2 > 2000 ){
sendCommand(Mod_4, OFF)
sendCommand(Mod_5, OFF)
}
end
Log File:
2017-07-29 14:15:57.802 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'longpress2.rules'
==> /var/log/openhab2/events.log <==
2017-07-29 14:27:17.645 [ItemStateChangedEvent ] - Mod_2i changed from OFF to ON
2017-07-29 14:27:18.166 [ItemStateChangedEvent ] - Mod_2i changed from ON to OFF
2017-07-29 14:27:19.559 [ItemCommandEvent ] - Item 'Mod_4' received command ON
2017-07-29 14:27:19.595 [ItemStateChangedEvent ] - Mod_4 changed from OFF to ON
2017-07-29 14:27:21.923 [ItemStateChangedEvent ] - Mod_2i changed from OFF to ON
2017-07-29 14:27:22.263 [ItemStateChangedEvent ] - Mod_2i changed from ON to OFF
2017-07-29 14:27:22.285 [ItemCommandEvent ] - Item 'Mod_4' received command OFF
2017-07-29 14:27:22.299 [ItemStateChangedEvent ] - Mod_4 changed from ON to OFF
2017-07-29 14:27:26.204 [ItemStateChangedEvent ] - Mod_2i changed from OFF to ON
2017-07-29 14:27:26.379 [ItemStateChangedEvent ] - Mod_2i changed from ON to OFF
2017-07-29 14:27:26.398 [ItemCommandEvent ] - Item 'Mod_4' received command ON
2017-07-29 14:27:26.431 [ItemStateChangedEvent ] - Mod_4 changed from OFF to ON
2017-07-29 14:27:27.754 [ItemStateChangedEvent ] - Mod_2i changed from OFF to ON
2017-07-29 14:27:28.103 [ItemStateChangedEvent ] - Mod_2i changed from ON to OFF
2017-07-29 14:27:28.123 [ItemCommandEvent ] - Item 'Mod_4' received command OFF
2017-07-29 14:27:28.141 [ItemStateChangedEvent ] - Mod_4 changed from ON to OFF