Squeezebox favorites cycle by rules

Tags: #<Tag:0x00007efee713e6a0>

Hi all, I feel a bit stupid, because basically everything is working and I think I just miss something on type conversion site.

Basic syntax should be,
pressForward -> next favourite channel
pressBack->previous favourite channel

I just want to cycle though my favourite channels with the press of a button.

Item is defined as:

String EGPlayer_PlayFavorite    "EG Play Favorite [%s]"             (EGPlayerControl)       {channel="squeezebox:squeezeboxplayer:XXXXXXXXX:XXXXXXXXX:playFavorite" }

From rules I can set my channel with

If I do

logInfo("IR", "channel ID: " + (EGPlayer_PlayFavorite.state))

I get the correct number

When I try

EGPlayer_PlayFavorite.sendCommand((EGPlayer_PlayFavorite.state as Number) - 1)

i get

[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Received ON': Could not cast 2 to java.lang.Number;

My rule is:

EGPlayer_PlayFavorite.sendCommand((EGPlayer_PlayFavorite.state as Number) - 1)

it would also be great to get suggetion on how to cycle though instead of stopping at a fixed max channel id or 0.

Having something like cycling though the channels would be quite helpfull rule, to change channels if no gui is near and just a wallmount switch or ir remote is available

Your Item is a String type, the state will be a string like “5”.
If you want to do maths on that, or compare it with numbers, you’ll have to parse it to number first. As an integer, I would guess.

var realNumber = Integer::parseInt(someItem.state.toString)


worked very well, I use a seperate rule to count the max number of channels and than I use

                    /* converts current ID to integer*/
                    var Number string2IntID = Integer::parseInt(EGPlayer_PlayFavorite.state.toString)
                    logInfo("EGPlayer IR", "current channel ID : " + string2IntID)
                            string2IntID = string2IntID - 1
                            logInfo("EGPlayer IR", "new channel ID : " + string2IntID)
                            string2IntID = (FavouritesMaxChannels.state as Number) 
                            logInfo("EGPlayer IR", "new channel ID : " + string2IntID)

to continously cycle through the channels with one button