- Platform information:
- Hardware: CPUArchitecture/RAM/storage
Raspberry Pi 3 (RPi3) Model B - OS: what OS is used and which version
Rasbian 2.3
- Hardware: CPUArchitecture/RAM/storage
I have a rule that I really like, even though it isn’t critical, but it takes many times longer to load than all the other rules combined. Up to 5 or 10 minutes just for it alone to load. After it has loaded it works fine. I am pretty new to all this, but I was wondering if there was any way I could reduce the load time of this seemingly simple looking rule.
import java.util.concurrent.ThreadLocalRandom
var int MaxBrightness = 65
var int MinBrightness = 15
rule "party - Party"
when
Item Party changed to ON or
System started
then
if (triggeringItem === null) {
Party.postUpdate(OFF)
logInfo("info", "Loaded model 'party.rules'")
return;
}
sendCommand(Bedroom, OFF)
sendCommand(Hallway, 0)
sendCommand(Kitchen, OFF)
sendCommand(Livingroom, 0)
Thread::sleep(1000)
sendCommand(DiscoBall_Switch, ON)
Thread::sleep(2000)
sendCommand(Livingroom_Sync, ON)
Livingroom.postUpdate(100)
while (Party.state == ON) {
if (MaxBrightness > MinBrightness) {
sendCommand(Light1_Color, ThreadLocalRandom::current().nextInt(360) + ",100," + (ThreadLocalRandom::current().nextInt(1 + MaxBrightness - MinBrightness) + MinBrightness))
sendCommand(Light2_Color, ThreadLocalRandom::current().nextInt(360) + ",100," + (ThreadLocalRandom::current().nextInt(1 + MaxBrightness - MinBrightness) + MinBrightness))
sendCommand(Light3_Color, ThreadLocalRandom::current().nextInt(360) + ",100," + (ThreadLocalRandom::current().nextInt(1 + MaxBrightness - MinBrightness) + MinBrightness))
sendCommand(Light4_Color, ThreadLocalRandom::current().nextInt(360) + ",100," + (ThreadLocalRandom::current().nextInt(1 + MaxBrightness - MinBrightness) + MinBrightness))
sendCommand(Light5_Color, ThreadLocalRandom::current().nextInt(360) + ",100," + (ThreadLocalRandom::current().nextInt(1 + MaxBrightness - MinBrightness) + MinBrightness))
sendCommand(Hallway, ThreadLocalRandom::current().nextInt(360) + ",100," + (ThreadLocalRandom::current().nextInt(1 + MaxBrightness - MinBrightness) + MinBrightness))
} else {
sendCommand(Light1_Color, ThreadLocalRandom::current().nextInt(360) + ",100," + MaxBrightness)
sendCommand(Light2_Color, ThreadLocalRandom::current().nextInt(360) + ",100," + MaxBrightness)
sendCommand(Light3_Color, ThreadLocalRandom::current().nextInt(360) + ",100," + MaxBrightness)
sendCommand(Light4_Color, ThreadLocalRandom::current().nextInt(360) + ",100," + MaxBrightness)
sendCommand(Light5_Color, ThreadLocalRandom::current().nextInt(360) + ",100," + MaxBrightness)
sendCommand(Hallway, ThreadLocalRandom::current().nextInt(360) + ",100," + MaxBrightness)
}
Thread::sleep(900)
}
sendCommand(Livingroom, 0)
sendCommand(Hallway, 0)
sendCommand(DiscoBall_Switch, OFF)
Thread::sleep(1000)
sendCommand(Livingroom_Temperature, new PercentType(84))
sendCommand(Livingroom, new PercentType(100))
end