Working Squeezebox Example?

Hi

Im completely new to openhab (but not Linux) and have 7 squuezeplugs (raspberry pi squeezebox) with O2 jogglers controllers working in my house. I have spent a few days struggling to get the squeezebox examples working with no joy. I found that this example was missing a couple of declarations:

and I struggled to find out how to install the squeezebox io addons, but I think I have them (3) installed now.

I then followed this example:

but when I select a player, i get the following error:
2016-04-14 14:43:01.679 [INFO ] [hab.model.script.squeeze.rules] - squeezeSelectedStation (Type=NumberItem, State=Uninitialized)
2016-04-14 14:43:03.545 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule ‘SqueezePlayerRadioStation’: Cannot cast org.openhab.core.types.UnDefType to org.openhab.core.library.types.DecimalType

If anyone has a working squeezebox setup with openhab, Id appreciate any help as Im stumped.

Thanks

It’s clear that squeezeSelectedStation is Uninitialized, so I would recommend to search for typos in item or rule definition. Feel free to post the related code here :slight_smile:

Hi

Here the ddefinition section of the players in the openhab.cfg file

Id (MAC address) of your first Squeezebox. MAC addresses of players are case-sensitive.

Use small letters (a-f) if the address contains them. Example:

entries for players/raspberry pi’s

squeeze:livingroom.id=b8:27:eb:85:60:b7
squeeze:kitchen.id=74:da:38:26:9d:48
squeeze:guestroom1.id=74:da:38:26:b1:28
squeeze:library.id=b8:27:eb:e5:1f:6b
squeeze:mainbedroom.id=b8:27:eb:cd:16:00
squeeze:guestroom2.id=b8:27:eb:d4:cb:fe
squeeze:unknownplayer.id=b8:27:eb:bf:d0:91

entries ending in sq are the entries for the o2jogglers/controllers

squeeze:livingroomsq.id=00:0e:8e:22:8e:44
squeeze:kitchensq.id=00:0e:8e:24:fc:59
squeeze:guestroom1sq.id=00:0e:8e:24:d7:b8
squeeze:mainbedroomsq.id=00:0e:8e:24:c4:09
squeeze:guestroom2sq.id=00:0e:8e:24:cc:36

and here is the items file (i only did 2 of the players to start with)

/* SqueezeBox */

Missing declarations

Group gPlayerPower
Group gPlayerPowerAll
Group gPlayerPowerOG
Group gPlayerVolume
Group gTV
Group gPlayerPowerEG

Number squeezeSelectedPlayer
Number squeezeSelectedStation
Switch squeezePlay

Switch squeezelivingroomPower “livingroom” (gPlayerPower, gPlayerPowerOG) { squeeze=“livingroom:power” }
Switch squeezelivingroomPlay “livingroom” { squeeze=“livingroom:play” }
Dimmer squeezelivingroomVolume “livingroom [%.1f %%]” (gPlayerVolume) { squeeze=“livingroom:volume” }

Switch squeezekitchenPower “kitchen” (gPlayerPower, gPlayerPowerOG) { squeeze=“kitchen:power” }
Switch squeezekitchenPlay “kitchen” { squeeze=“kitchen:play” }
Dimmer squeezekitchenVolume “kitchen [%.1f %%]” (gPlayerVolume) { squeeze=“kitchen:volume” }

and finall the rules file

import org.openhab.core.library.types.*
import org.openhab.model.script.actions.*
import org.openhab.action.squeezebox.*

// Handle squeezebox radio station UI
rule "SqueezePlayerRadioStation"
  when 
    Item squeezePlay changed
  or
    Item squeezeSelectedStation changed
  or
    Item squeezeSelectedPlayer changed
  then
    logInfo("squeeze.rules", "SqueezePlayerPlay")

    var String [] players = newArrayList("livingroom", "kitchen","guestroom1","guestroom2","library","mainbedroom");
    var String[] urls = newArrayList(
      "http://stream.srg-ssr.ch/drs1/mp3_128.m3u", // Radio SRF1
      "http://stream.srg-ssr.ch/drs2/mp3_128.m3u", // Radio SRF2
      "http://stream.srg-ssr.ch/drs3/mp3_128.m3u", // Radio SRF3
      "http://www.swissgroove.ch/listen.m3u",      // Swiss Groove
      "http://icecast.argovia.ch/argovia128.m3u",  // Radio Argovia
      "http://stream.srg-ssr.ch/rsj/mp3_128.m3u",  // Swiss Jazz
      "http://mp3-live.swr3.de/swr3_m.m3u"         // SWR 3
      )

    logInfo("squeeze.rules", squeezeSelectedStation.toString)

    var stationIndex = ((squeezeSelectedStation.state as DecimalType).intValue - 1)
    var station = urls.get(stationIndex) as String;

    var playerIndex = ((squeezeSelectedPlayer.state as DecimalType).intValue - 1) 
    var player = players.get(playerIndex) as String

    logInfo("squeeze.rules", player)
    logInfo("squeeze.rules", station)

    if (squeezePlay.state == ON) {
      squeezeboxPlayUrl(player, station)
    } else {
      squeezeboxStop(player)
    }

  end

I tried to keep to the examples but had to translate the german example to english

Any advice would be appreciated - Thanks

Hi

and the sitemap files for good measure

sitemap home label=“Home”
{
Frame {
Text label=“Audio” icon=“squeeze” {
Frame label=“All” {
Switch item=gPlayerPowerAll label="Ground floor & 1st Floor"
Switch item=gPlayerPowerEG label="Ground Floor"
Switch item=gPlayerPowerOG label="1st Floor"
Group item=gPlayerPower label=“On / Off” {
Switch item=squeezelivingroomPower
Switch item=squeezekitchenPower
}
Group item=gPlayerVolume label=“Volume” {
Slider item=squeezelivingroomVolume switchSupport
Slider item=squeezekitchenVolume switchSupport
}
Slider item=gPlayerVolume label=“Volume”
}
Frame label=“Individually” {
Selection item=squeezeSelectedPlayer label=“Player” mappings=[1=“livingroom”, 2=“kitchen”]
Selection item=squeezeSelectedStation label=“Sender” mappings=[1=“SRF 1”, 2=“SRF 2”, 3=“SRF 3”, 4=“Swiss Groove”, 5=“Argovia”, 6=“Swiss Jazz”, 7=“SWR 3”]
Switch item=squeezePlay label=“Stop / Play” mappings=[OFF=“Stop”, ON=“Play”]

            Switch item=squeezelivingroomPower    visibility=[squeezeSelectedPlayer==1]             
            Switch item=squeezekitchenPower       visibility=[squeezeSelectedPlayer==2]
    

            Slider item=squeezelivingroomVolume switchSupport   visibility=[squeezeSelectedPlayer==1]
            Slider item=squeezekitchenVolume switchSupport       visibility=[squeezeSelectedPlayer==2]          
        }       
    }       
}   

}

Ah. I think, the problem is, neither squeezeSelectedPlayer nor squeezeSelectedStation is initialized when starting openHAB, so try setting both to a correct value, to see, if the error still occurs.

Hi

Sorry, im quite new to openhab. is this correct ?

Number squeezeSelectedPlayer=1
Number squeezeSelectedStation=1

Im not convinved i have added/imported the squeezebox binding files correctly as I see errors in the logfile such as

2016-04-14 18:58:16.781 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrieve item squeezekitchenVolume for widget org.openhab.model.sitemap.Slider
2016-04-14 18:58:16.796 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrieve item squeezekitchenVolume for widget org.openhab.model.sitemap.Slider
2016-04-14 18:58:16.824 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrieve item squeezekitchenVolume for widget org.openhab.model.sitemap.Slider

could you explain how the dqueezebox binding filles these should be added and where the files come from ?

Thanks.

Hi, Im sorry

I can see the squeezebox jar files in the addons folder so I must have installed them correctly but they are owned by root so I had to manually change them to the openhab owner. The 1st error in the files is now

2016-04-14 19:23:41.734 [WARN ] [.o.u.w.i.render.SwitchRenderer] - Cannot determine item type of ‘gPlayerPowerAll’

Thanks

:slight_smile: What I ment was, after starting openHAB, switch to a Player and switch to a Playlist. After that, the first error

[ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'SqueezePlayerRadioStation': Cannot cast org.openhab.core.types.UnDefType to org.openhab.core.library.types.DecimalType

shouldn’t occur, since squeezeSelectedPlayer and squeezeSelectedStation then have a valid value.

This one:

[WARN ] [.o.u.w.i.render.SwitchRenderer] - Cannot determine item type of 'gPlayerPowerAll'

is because the group gPlayerPowerAll is empty, so openHAB cannot decide which widget to choose. I think you should add squeezelivingroomPower and squeezekitchenPower to this group.

There should be no need to change the ownership of the addons (as long as the files are readable and executable for group and others)

As for this one

2016-04-14 18:58:16.781 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrieve item squeezekitchenVolume for widget org.openhab.model.sitemap.Slider

I have no idea at the moment.

OK. We have progress. I had stupidly left an unclosed comment when adding comments that caused the errors.

Now Im back to the original problem, that the value of squeezeSelectedPlayer and squeezeSelectedStation, are uninitialised on first entry, so the sitemap files looks like this on viewing

If I set these variables to 1 in their initial definition, that does not work, so Im wondering where and how they should be initialised.

Once they are initialised (ie once I use the browser to set them to a value), then they do now control the squeezebox.

So its the initial lack of initialisation that causes the problem. Can anyone explain the correct initialisation for the variables ?

Thanks.

You can’t initialize items (!) in it’s definition. It’s possible to do it via persistence (restoreOnStartup), but for a first test, please ignore the Errors as long as you didn’t set a valid value for Player & Station via openHAB UI. If more errors occur, even if Player & Station are set, we have to analyze more, for the uninitialized-error there is a workaround:

import org.openhab.core.library.types.*
import org.openhab.model.script.actions.*
import org.openhab.action.squeezebox.*

// Handle squeezebox radio station UI
rule "SqueezePlayerRadioStation"
when 
    Item squeezePlay changed or
    Item squeezeSelectedStation changed or
    Item squeezeSelectedPlayer changed
then
    logInfo("squeeze.rules", "SqueezePlayerPlay")
    var String [] players = newArrayList("livingroom", "kitchen","guestroom1","guestroom2","library","mainbedroom")
    var String[] urls = newArrayList(
      "http://stream.srg-ssr.ch/drs1/mp3_128.m3u", // Radio SRF1
      "http://stream.srg-ssr.ch/drs2/mp3_128.m3u", // Radio SRF2
      "http://stream.srg-ssr.ch/drs3/mp3_128.m3u", // Radio SRF3
      "http://www.swissgroove.ch/listen.m3u",      // Swiss Groove
      "http://icecast.argovia.ch/argovia128.m3u",  // Radio Argovia
      "http://stream.srg-ssr.ch/rsj/mp3_128.m3u",  // Swiss Jazz
      "http://mp3-live.swr3.de/swr3_m.m3u"         // SWR 3
      )
    if (!(squeezeSelectedStation.state instanceof DecimalType))
        squeezeSelectedStation.postUpdate(1)                   // initialize if uninitialized
    if (!(squeezeSelectedPlayer.state instanceof DecimalType))
        squeezeSelectedPlayer.postUpdate(1)                    // initialize if uninitialized

    logInfo("squeeze.rules", squeezeSelectedStation.toString)

    var stationIndex = ((squeezeSelectedStation.state as DecimalType).intValue - 1)
    var station = urls.get(stationIndex) as String;

    var playerIndex = ((squeezeSelectedPlayer.state as DecimalType).intValue - 1) 
    var player = players.get(playerIndex) as String
    logInfo("squeeze.rules","Player: {} -> Station: {}", player, station)
    if (squeezePlay.state == ON)
        squeezeboxPlayUrl(player, station)
    else
        squeezeboxStop(player)
end

The essential part is the if(item instanceof DecimalType) which will fail when the item is uninitialized. :wink:

EDIT: negation of instanceof decimalType corrected

Hi Udo.

You are a star. Those 2 lines of code ensures the unitialised error is removed at first run. I see that a few others have also commented on the fact that this error occurs but there was no response so they will also benefit from this.

I was reading more about items this morning and I see now that they are not variables. So many thanks for your help on this.

Im now moving on to the topic of the volume control and power on/off which dont see to work (ie when i select the sliders or toggle buttons, the sliders update but there are no new entries in the logfile and the volume on the player does not change.

Do I need a rule for this ?

Thanks - cloveoil1

as to the volume, it depends on how the sliders are plotted. If they are “real” sliders, they should set the absolut value (between 0 and 100) to the item and therefore the volume correctly. If there are up/down buttons (current version of Classic UI), the buttons will send increase/decrease commands, which maybe won’t be converted, so you would have to use a little rule for each player:

rule "Volume player 1"
when
    Item player_1_volume received command
then
    if (receivedCommand == DECREASE)
        player_1_volume.sendCommand(player_1_volume.state as DecimalType - 5)
    else if (receivedCommand == INCREASE)
        player_1_volume.sendCommand(player_1_volume.state as DecimalType + 5)
end

Power Button should work without any rules, at least I have the same binding configuration (I use squeezelite on Linux)

Hi Udo

Yes Im using the classic UI and the up/down buttons seem to increase/descrease the volume by 50% or more (but the actual volume does not change).

I have added your rule as follows:

rule "Volume livingroom"
when
Item squeezelivingroomVolume received command
then
if (receivedCommand == DECREASE)
squeezelivingroomVolume.sendCommand(squeezelivingroomVolume.state as DecimalType - 5)
else if (receivedCommand == INCREASE)
squeezelivingroomVolume.sendCommand(squeezelivingroomVolume.state as DecimalType + 5)
end

I believe the relavant item is the one defined in the items file as:

Dimmer squeezelivingroomVolume “livingroom [%.1f %%]” (gPlayerVolume) { squeeze=“livingroom:volume” }

However, im not sure if the syntax is correct. Is this ok ?

(it doesnt seem do do anything at the moment so I think I have not connected the rule with the item condiition correctly).

Thanks.

Hi

I have added some logging to the rule and found that even though the item has been defined as a dimmer, when the volume up or downm button is pressed, an on or off command is sent (not increase or decrease)

I have added logging to the rule to check this

rule "Volumelivingroom"
when
Item squeezelivingroomVolume received command
then
val com = receivedCommand.toString.lowerCase
logInfo(“Livingroom volume=”,com);
if (receivedCommand == DECREASE)
{
logInfo(“Livingroom”,“Living room volume DECREASE triggered”);
squeezelivingroomVolume.sendCommand(squeezelivingroomVolume.state as DecimalType - 5)
}
else if (receivedCommand == INCREASE)
{
logInfo(“Livingroom”,“Living room volume INCREASE triggered”);
squeezelivingroomVolume.sendCommand(squeezelivingroomVolume.state as DecimalType + 5)
}
}

However, the rule is being called but not with increase/decrease, just on/off.

Thanks.

Hi

I have checked the demo map and it behaves the same way for the dimmer (100% or 0%) so Im not sure what I have done wrong.

Thanks

Ah. I have missed that.

Please delete switchSupport for the volume dimmers, as this dimmers shouldn’t have switch support at all :slight_smile:
And be aware that a short press to the up/down buttons will send 0 respectively 100, where a long press will send DECREASE respectively INCREASE. This is for “switching” Light off and on without more buttons. With switchSupport the up/down button will send OFF respectively ON when short pressed. If you want to raise and lower the volume without clicking multiple times, you have to set sendFrequency=400 in sitemap:

Slider item=squeezekitchenVolume sendFrequency=400 visibility=[squeezeSelectedPlayer==2] 

This will make openHAB sending INCREASE/DECREASE commands repeatedly as long as you hold the button every 400msec.

Hi

We are almost there.

I changed the home sitemap slightly to make life simpler while im learning about openhab. Combined with your change it now looks as follows:

sitemap home label=“Home”
{
Frame
{
Text label=“Squeezebox Audio Control” icon=“squeeze”
{
Frame
{
Group item=gPlayerPower label=“Power”
{
Switch item=squeezelivingroomPower
Switch item=squeezekitchenPower
Switch item=squeezeguestroombPower
Switch item=squeezemainbedroomPower
Switch item=squeezelibraryPower
Switch item=squeezeguestroomaPower
}
Group item=gPlayerVolume label=“Volume”
{
Slider item=squeezelivingroomVolume SendFrequency=400
Slider item=squeezekitchenVolume SendFrequency=400
Slider item=squeezeguestroombVolume SendFrequency=400
Slider item=squeezemainbedroomVolume SendFrequency=400
Slider item=squeezelibraryVolume SendFrequency=400
Slider item=squeezeguestroomaVolume SendFrequency=400
}

            Selection item=squeezeSelectedPlayer label="Player" mappings=[1="livingroom", 2="kitchen", 3="library", 4="mainbedroom", 5="guestrooma", 6="guestroomb" ]
            Selection item=squeezeSelectedStation label="Station" mappings=[ 1="SRF 1", 2="SRF 3", 3="SRF 3", 4="Swiss Groove", 5="Argovia", 6="Swiss Jazz", 7="SWR 3", 8="Midwest", 9="RTE Lyric FM"]
            Switch item=squeezePlay label="Start/Stop" mappings=[OFF="Stop", ON="Play"]    
        }
    }      
}
Frame 
{
    Text label="Kodi Media Control" icon="kodi"  
    {
    	Slider item=kodilivingroomVolume
    }
}  
Frame 
{
    Text label="Frame 3" icon="wind"  
    {   
    	Slider item=frame3livingroomVolume
    }
}      

}

Now when I use the home sitemap from openhab on my phome, I see a real slider and the volume increases/descreases nicely. However, if I use the web browser oin my PC, I see the up/down buttons and they dont change when I press them.

In addition, I can see that the rule livingroomVolume is nolonger called (which is fine if its nolonger needed). Instead I see info messages in the logfile showing that the volume has been adjusted directly without the rule.
2016-04-16 19:13:27.176 [INFO ] [odel.script.Livingroom volume=] - 78
2016-04-16 19:13:35.002 [INFO ] [odel.script.Livingroom volume=] - 45
2016-04-16 19:13:44.538 [INFO ] [odel.script.Livingroom volume=] - 38
2016-04-16 19:13:54.901 [INFO ] [odel.script.Livingroom volume=] - 71
2016-04-16 19:14:02.878 [INFO ] [odel.script.Livingroom volume=] - 29
2016-04-16 19:14:19.120 [INFO ] [odel.script.Livingroom volume=] - 4
2016-04-16 19:14:20.908 [INFO ] [odel.script.Livingroom volume=] - 0
2016-04-16 19:14:23.195 [INFO ] [odel.script.Livingroom volume=] - 52

Im not too worried about the browser view as will generally use the openhab app on a tablet. However, if you have any ideas, I would welcome your input.

Thanks.

Yes, the HABdroid or iOS UI draws real sliders which will send absolute values and therefor there is no need for translate INCREASE/DECREASE with a rule.

The correct spelling is sendFrequency="400" (starts with lower case, the value stands in double quotes), so give it a try :slight_smile: it should work with the classic UI from webbrowser.

Hi Udo

Do you have any example of an openhab setup to play muisc/artists/titles on the squeezebox (as opposed to internet radio stations) as I cannot find anything about how to do this.

Thanks.

Hi

I corrected the sendFrequency spelling and put the values in quotes. It works fine from the UI but on the browser nothing happens when I press the buttons

Its not critical though but would be nice to finish it off.

Thanks for all your help.