I have a rule that uses the
playSound()
command to provide feedback dynamically with some if/then statements. Below is a code snippet from my good night rule. It says “good night” then - will warn if a door is open and warn if I’ve oven on.
playSound("goodnight-house.mp3")
Thread::sleep(3000)
if ( stoveState.state != 0 ){
//Play Warning oven is on
logInfo("goodnight","!!!!!!!!!!!!!!!!!!! OVEN IS ON WHEN going to bed!")
sendCommand(ovenwarn,ON)
sendPushoverMessage(pushoverBuilder("Oven is on and house is set to nightmode!!"))
Thread::sleep(3000)
}
if ( gNDoors.state === CLOSED ){
logInfo("goodnight", "!!!!!!!!!!!!!!!!!!!!!! Played All Doors Closed")
playSound("all_doors_are_closed.mp3")
Thread::sleep(2000)
} else {
logInfo("goodnight", "!!!!!!!!!!!!!!!!!!!!!! There are Open Doors")
playSound("an_outside_door_is_open.mp3")
if (frontdoorSensor.state === OPEN){
sendPushoverMessage(pushoverBuilder("Front Door Open"))
}
if (sidedoorSensor.state === OPEN){
sendPushoverMessage(pushoverBuilder("Side Door Open"))
}
if (backdoorSensor.state === OPEN){
sendPushoverMessage(pushoverBuilder("Back Door Open"))
}
if (upporchdoorSensor.state === OPEN){
sendPushoverMessage(pushoverBuilder("Upstairs Porch Door Open"))
}
}
If I don’t have all of these Thread::sleep() commands in here, all of these will play all in one garbled mess. However even these Thread::sleep() commands don’t always work quite right as it sometimes takes longer to start playing and some parts get played over anyway.
What is the best way to make openHAB wait until one command is completed playing before it will start playing the next. In other words, how can I ensure these play in series rather than parallel?