Multiple playSound() commands play over one another

I have a rule that uses the


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.

			if ( stoveState.state != 0 ){
				//Play Warning oven is on
				logInfo("goodnight","!!!!!!!!!!!!!!!!!!! OVEN IS ON WHEN going to bed!")
				sendPushoverMessage(pushoverBuilder("Oven is on and house is set to nightmode!!"))
			if ( gNDoors.state === CLOSED ){
				logInfo("goodnight", "!!!!!!!!!!!!!!!!!!!!!! Played All Doors Closed")
			} else {
				logInfo("goodnight", "!!!!!!!!!!!!!!!!!!!!!! There are Open Doors")
				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?

Not by playing different sounds. Concentrate the complete string and call playSound only once!

Good idea. I can use a string builder to build a string through all of my checks and have a specific string I can call through playSound() at the end. However I’m not sure really how to use that. According to the docs, playSound() only takes one file name as an argument, not a list of files to play sequentially. the only way I can think of making use of this would be to create a unique sound file for each possible combination of announcements and have the string builder create a string that would point to the right unique file name to play. Is there some other way to make sue of this?

I’m sorry, and yes,you are correct.
My solution is for the usage of the TTS service (I.e. for the say comand). Your “speekable” soundfile-names got me carried away.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.