If function stacking


#1

Can someone help me with stacking if( functions in an expression?

I’m trying to use an expression to change the color of text and a symbol in a piston status based on the state of a sonos player. ie. playing = green, paused = purple and stopped = red. now i’ve had some success by blindly fumbling around robbing bits and pieces from various other pistons and coming up with this

({StatusPlayer} = "playing" ? '[color-green | :fal fa-play: {StatusPlayer}]' : ({StatusPlayer} = "stopped" ? '[color-red | :fal fa-stop: {StatusPlayer}]' : ({StatusPlayer} = "paused" ? '[color-purple | :fal fa-pause: {StatusPlayer}]' : ':fal fa-question:')))

where {StatusPlayer}is a variable writen by the piston and can be playing, stopped or paused. when the player is stopped I get a play symbol and stopped in green.

Im lost now…


#2

You need to change the equals “=” to “==”, i.e., {StatusPlayer} == “playing”

Wiki

You can also remove the {} around StatusPlayer. They don’t do any harm, but they’re not needed here and clutter up the expression a bit.

(StatusPlayer == “playing” ? ‘[color-green | :fal fa-play: StatusPlayer]’ :
(StatusPlayer == “stopped” ? ‘[color-red | :fal fa-stop: StatusPlayer]’ :
(StatusPlayer == “paused” ? ‘[color-purple | :fal fa-pause: StatusPlayer]’ : ‘:fal fa-question:’)))


#3

Thanks for that. Clearly a case of RTFM!

you do need the {} on the second StatusPlayer though otherwise it just says StatusPlayer not stopped

(expression) (StatusPlayer == “playing” ? ‘[color-green | :fal fa-play: StatusPlayer]’ : (StatusPlayer == “stopped” ? ‘[color-red | :fal fa-stop: StatusPlayer]’ : (StatusPlayer == “paused” ? ‘[color-purple | :fal fa-pause: StatusPlayer]’ : ‘:fal fa-question:’))) »»» (string) StatusPlayer

(expression) (StatusPlayer == “playing” ? ‘[color-green | :fal fa-play: {StatusPlayer}]’ : (StatusPlayer == “stopped” ? ‘[color-red | :fal fa-stop: {StatusPlayer}]’ : (StatusPlayer == “paused” ? ‘[color-purple | :fal fa-pause: {StatusPlayer}]’ : ‘:fal fa-question:’))) »»» (string) stopped

my PC has stopped showing the icons but I suspect thats an internet explorer issue. which serves me right for doing this at work :wink:


#4

Oops, should’ve caught that. :roll_eyes:


#5

No worries its all working nicely now
cheers