Stop playsound

Hi,

I am using the playsound action to start a sound to wake up my girlfriend if her phone fails… this is pretty simple and it works fine, but the sound is a track about 3 mins long thats why I am searching for a way to stop it befor it ends. Is there any way to do so?

Thanks
Eric

NO there isn’t I am afraid.

Right there is not. But you could use an audio tool to split that track into multiple to improve unwanted play time.

That depends on what you are playing it on. I for example use Google Home devices to play notifications or wake-up songs on (via say() and playSound() respectively), and there you can use the media control item of the Chromecast Thing to stop the sound from playing.

Alternatively you could, depending on the type of device, set the volume to 0 temporarily, if that suffices.

1 Like

Hello,

same problem, but maybe 1 year later a solution appeared?
Is there a way to stop or kill a running playSound() song/sound/… ??

What i have: I mounted a NAS to my /etc/sound/ folder and want to play certain mp3-tracks with playSound(path filename). This works so far.
The problem is, when I chose another track, both are playing in parallel with certain time-delay until end of the song.
What i want to do: I want to stop the first one song running and start the next one.
Is there a way to do so?

Thanks!

Is there now a solution for this?

I use openhab as a „Security System“ to detect windows or doors which change the state to open at night.
The played alarm is short, so I would like to extend it to several minutes. But then I would need a stop button in openhab.

Dirk
Good on you for using the search function to find a thread about something like you are trying to do. As noted by the original post and the replies, there is no way to stop a playing sound once it is started but Rolf’s idea is basically the best solution for the original question. Depending on what you are playing the sound on, you can simply mute or turn down the volume programiclly then restore the volume or unmute after enough time for the sound file to finish playing. Bize’s issue is more difficult, it sounds like he was looking for a media player.
Your idea requires a different solution. It sounds like you want to make a sound play but the sound file is to short, you want it to play longer. You could obviously use a sound file editor to make the file longer. I’m guessing it is a siren or buzzer sound or something. The other option is to simply repeat the playing of the file over and over until it reaches the length of time you want the sound to be heard. your issue seems to be:

OK… well… I’m sure putting a button on your UI of choice to stop the sound is easy enough, it sounds like you want a way of possibly playing the sound for a varying amount of time, then once something occurs, it stops playing.
Are you looking for a way to acknowledge you (or somebody) has heard the sound and not have to go to the user interface to turn it off? What exactly occurs that needs to be that acknowledgement?
The power of OpenHAB is that it can work with so many technologies and they can be tied together and rules can be used to program those devices. It is only limited by your own ingenuity and resourcefulness. That is what automation is all about. The system just does what it is supposed to do… by itself
Tell us what you want to do and we’ll help

@Andrew_Rowe
My security system is pretty simple… rule is:
when a window or door contact change to open,
play sound file, but only when alarmsystem state = armed.

At the moment a 25sec siren mp3 starts playing at the raspberry via a wired connected speaker.
It would be nice if I can play the siren eg for 1h or until the intruder has left. (Modifying the mp3 is no problem for me)
Because of the long playback I would like to have a button which stops playback of the mp3 at the raspberry when I want to stop it.
That’s all :slight_smile:

So I am basically looking for a command to send to stop the playback.
My idea was to start another mp3 (just a short beep) to end the siren playback. But the mp3‘s are just playing simultaneously.

OK, right… well as Vincent stated in the second post, there is no way to stop a playsound action once it is started. You just have to let it finish playing the mp3 file in it’s entirety so… the solution, as Rolf said in the forth post, your only alternative is to turn down the volume or mute what ever you are playing the sound thru.

since the track is only 25 seconds long and

so if it is playing for an hour, and mister burglar decides he has what he wants and leaves, twenty five second maximum to finish the track after he leaves is acceptable. (since the alarm has been going off for an hour already) the obvious solution is to loop the track. OH can easily play a sound file every 25 seconds. The trick is figuring out when Mr. Burglar is gone and shutting off the loop.
In reality, we both know that is not what we want.
If scaring off the intruder is the goal, how about a recording of a dog barking or a phone dialing and the police answering and saying someone is on the way and maybe some strobe lights out in the driveway :rofl:
Anyhow… the point of an alarm noise is to alert someone and maybe initially scaring somebody off. An alarm playing for over an hour is just going to piss off all your neighbors. (think car alarm)
so… create an proxy item, perhaps a switch. Write a rule (in the language of your choice) that loops the sound file until you click the button.
— pseudo code only ----

Rule "alarm triggered"
When item alarmtrigger changes to ON or mytimer runs out
Then if ( myalarmswitch == OFF)
                playsound (alarm sound.mp3)
                set mytimer for length of recording
         elseif (myalarmswitch == ON)
                set myalarmswitch to OFF
End

@Andrew_Rowe
Thanks for the idea with the loop…
Now it is working perfect.
This is what I‘ve done:

Created a rule which changes the security system‘s state (to an unused one) if a window or door change to open and the system is armed.

Created a second rule which plays the alarm sound (10sek.) in loop as long the security system‘s state isn’t changed back via button.

rule “alarm ton abspielen”
when
Item Alarmanlage changed
then
while (Alarmanlage.state == “AWAY_ARM”) {
playSound(“security2.mp3”)
Thread::sleep(11000)
}
Thread::sleep(1)
end

So the Alarm will be played as long as I don’t change the state to Disarmed or Armed again.

Perfect, thanks :slight_smile:

Great
ah… just asking, is this OpenHAB3 ?
because in OpenHAB2 Thread::sleep isn’t really a good idea because it holds a running thread and there are only 5 total threads for rules to run on and you may run out and lock up the system
If you know this already or you are on OpenHAB3 then no worries

I didn’t know that, but luckily I’m on OH 3 :smile:

OK, well my understanding is that OH3 uses a new thread for each rule and so this isn’t as big a deal but it is still using memory and a whole bunch of similar rules could eventually swamp the system depending on your hardware.
I don’t want to overload you with a bunch of new stuff but maybe look into eventually replacing your rule with one that uses a timer instead. DSL can do timers but other languages offer easy solutions as well. Take your time learn as you go.

If the rule would be a rule which I use in a daily basis, I would invest more time in optimization.
But in my case as an alarm (which hopefully will never be needed) it will do it Job I think.

1 Like