Play sound with squeezebox when entering bathroom

i installed my first peace of multiroom audio in my bathroom.

It is working with the android app squeezer and i can control it with openhab2 also.

Now i want to have a rule, that the music will beginn, when PIR sensor in the bathroom detects motion.

How can i do this? Is the playSound command (the example from the binding-documentation) the right way? Or do i have to make a playlist?

For background music i want to play one song in repeat mode.

And how can i do this, when i want to play an internet radio stream instead?

When i play one song in repeat mode, is there a way, that the song only gets paused, when someone leaves the bathroom and the song starts on the last position again? With pause-command? I dont want to start the song on the start position everytime.

Dont use squeeze myself but from the docs its…

squeezeboxPlayUrl(player, station)


player is the name of the player defined in your squeeze config file.
Station is the url of the station.

some good examples on


Ok, will try this.

And how will this work, if i want to play songs, which are on my LMS?

With the “playSound” command i only can play songs which are in the songs-directory of my openhab-server, i think?

I’ve not actually done this, but here’s one way to approach it.

When motion is detected, you could have one rule that:

  1. determines if the item linked to the stream channel is the url of the desired playlist/song/radio and, if not, sends a command to the stream channel with the playlist/song/radio url
  2. plays the music by sending an ON command to the item linked to the playPause channel
  3. sets repeat mode by sending an ON command to the item linked to the repeat channel.

When someone leave the bathroom (what is the event that you will use to detect someone leaving), you would have another rule that pauses the music by sending an OFF command to the item linked to the playPause channel.

That’s why I suggest #1 above. While I haven’t actually tested this, by only sending a command to the item linked to the stream channel when it is not equal to the desired playlist, you might be able to avoid the song starting from the beginning.

Edit: BTW, in the LMS, if you add the song/playlist/radio as a favorite, you can get the URL you need to send to the stream channel.

This example is from carnival:

rule "Music bath"
    Item Light_GF_Bath received command
    if(receivedCommand==ON) {
        Squ_GF_Bath_Volume.sendCommand(70)    //normal level
    else if(receivedCommand==OFF) {
        Squ_GF_Bath_Volume.sendCommand(80)   //make the flourish a bit louder
        createTimer(now.plusSeconds(8), [|      //give the audio time to end
            squeezeboxPause("Squ_Bad_EG")   //wait for the next guest

First playlist was for carnival music, the second playlist was to play a flourish when leaving the bath.

I have to comment this: the carnival parade does happen to pass our home every 4 years, and it’s very likely that someone will enter our toilet, so this is a nice gag :smiley:

I used this three years ago, so this is OH1 binding style, but I think it won’t be very different next year…

Speaking of pause mode…

I’m using squeezelite as players, so this might only affect the software player, but I realized that the player will be unavailable after some hours keeping the pause mode. I ended up in setting a rule that stops the playback after 5 Minutes of pause. I’m using big playlists, so the music will not be always the same.

I get the following error:

2018-02-08 17:45:39.694 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Play Sounds': The name 'playsound' cannot be resolved to an item or type; line 30, column 5, length 112


rule "Play Sounds 2"
    Item Squeezebox_PlaySounds2 received command ON
    playsound("squeezebox:squeezeboxplayer:B2C02C4C-9107-4CC8-B2F3-D16387AE9904:Player_Raspi_EG_WC", "shire.mp3")

Whats wrong?

I can see, you use squeezeboxPlay(“Squ_Bad_EG”)

In the docs i have seen my command above.

What is the right one? The song shire.mp3 is in the openhab-conf-sounds folder.

The openHAB action would be playSound(), not playsound(). But this action would not let you chose the player, so I guess this should be part of the squeezebox2 binding.
In question of squeezeboxPlay, this is an action of squeezebox1 binding. But in Squeezebox2, you can use the channels to get the same result.

I’m a little bit confused???

What do I have to do instead of playsound?

I can send play command, but how can I choose the song or stream url?

squeezeboxPlay is an action from the openHAB 1 squeezebox binding, and doesn’t exist in the openHAB 2 squeezebox binding. I assume you’re using the openHAB 2 binding. If not, what I’m posting below is not accurate.

The problem with the rule below is that it doesn’t fully meet your requirements. It starts the song from the beginning every time.


Switch Play      "Play"       { channel="squeezebox:squeezeboxplayer:36b70fd1:b827eb160000:playPause" }
Number Repeat    "Repeat"     { channel="squeezebox:squeezeboxplayer:36b70fd1:b827eb160000:currentPlaylistRepeat" }
String StreamUrl "Stream URL" { channel="squeezebox:squeezeboxplayer:36b70fd1:b827eb160000:stream" }


// Replace with path to your song in LMS library or URL of Internet radio station
var String url = "/media/music/music/artist/album/nn_title.mp3"

rule "TestRule"
    Item TestRule_Switch received command
    if (receivedCommand == ON) {
        logInfo ("testrule", "Playing URL " + url)
        logInfo ("testrule", "Set to repeat song")
    } else if (receivedCommand == OFF) {
        logInfo ("testrule", "Pause and turn off repeat")

Seems to work… Thanks.

To set the volume, i only have to send the command before i send the stream ul?

Yes, I’d set the volume first.

In fact, you can set the volume at any time you want, but it’s more common to set the volume first and then start playing the music.

Great! Now the music starts, when someone enters the bathroom.

I hope i will find solutions for my two other wishes too:

  • show times in min:sec
  • start song from last position, not from start

This adds a bit of complexity. The part that makes it complex is if you play other items when the bathroom is not in use. It’s easy if all you want to do is start/stop the bathroom song when someone enters/leaves the bathroom.

Yes, i know the problematics…

I often play other songs or radio streams manually.

How can i check inside a rule if the squeezebox-player is currently playing a song?

Can i check the channel playpause? If it is ON, then the player is currently ac tive? If OFF then there is no music playing now? Or is this channel only to send commands and is no status channel?

Will this channel change to ON if i play music with squeezer on my android phone?

Got it

if (Squeezeplayer_EG_WC_control.state != PLAY) {

playPause should also work (ON=playing, OFF=paused), but it doesn’t. :frowning: I’ll have to look at the code to see why not…

I have seen this a few minutes before, then i tried the player-item and that worked :slight_smile:

Why is “mute” a switch and “shuffle” and “duration” are numbers?

Also “stop”, “next” and “prev” are switches… Do i need expire binding (1 second) to get a pushbutton or is there a better solution?

“play/pause” is ok, because i have two states.

What will “power” do? Only stop playing?

Is it possible to make a selection widget with some playlistes? Is there a little example somewhere? I don´t have any playlistes yet.

ON=mute OFF=unmute

shuffle and repeat are defined as numbers by the LMS because they can have more than two states.

The “playlist shuffle” command is used to shuffle, unshuffle or query the shuffle state for the current playlist. A value of “0” indicates that the playlist is not shuffled, “1” indicates that the playlist is shuffled by song, and “2” indicates that the playlist is shuffled by album.

The “playlist repeat” command is used to indicate or query if the player will stop playing at the end of the playlist, repeat the current song indefinitely, or repeat the current playlist indefinitely. A value of “0” indicates that the player will stop at the end of the playlist, “1” indicates that the player will repeat the current song indefinitely and a value of “2” indicates that the player will repeat the entire playlist indefinitely

duration is the total length of the playing track in seconds.

I typically use mappings in the sitemap. For example

Switch item=Player_Next label="Next" mappings=[ON="Next"]
Switch item=Player_Prev label="Previous" mappings=[ON="Prev"]

I think it depends on the device. I haven’t looked at the squeezelite code in a while, but I think power does nothing. OTOH, if it’s a Squeezebox Receiver, Boom, etc, it actually powers if off/on.

I just added a feature you might like. Read about it here.