If Statement for Piston State Not Working


#1

I have borrowed from a couple posted pistons and merged together some features of each that I like for tiles and piston state. Now, however, I seem to be over my head and can’t figure out what seems it should be simple on its surface.

I want the piston state to show the level of the family room switch when it’s on, and 0 when it’s off. How do I work a simple “if” statement into this? Everything I’ve tried either breaks the range color function, returns on 0, returns a blank, or results in a java exception error.

‘[b, black | Level is currently][b, {rangeValue([Family Room Main Lights : level], ‘Green’, 25, ‘DarkOrange’, 75, ‘FireBrick’)} | ‘[Family Room Main Lights : level]’][b, black |%’

The version above works and color coding is correct. But if I try to put insert an “if” statement where the above is bolded, all I can manage to create are varying ranges of broken. I’ve tried:

[Family Room Main Lights : switch] == ‘on’ ? [Family Room Main Lights : level]"%" : ‘0’"%"

[Family Room Main Lights : switch] == ‘on’ ? [Family Room Main Lights : level] : ‘0’

And every combination of single and double quotes I can think of… what am I missing?

Thanks in advance for any help!


#2

This one worked for me, I used off for testing

[Living Room Hue:switch] == 'off' ? [Living Room Hue : level]"%" : '0' "%"


#3

Thanks! I tried inserted that but still only get 0% (all black text) with both on and off. What did I screw up in this? It has to be a quote or something out of place? I just don’t know the syntax of this stuff well enough to hunt it down… I need some excedrin!

‘[b, black | Level is currently][b, {rangeValue([Family Room Main Lights : level], ‘Green’, 25, ‘DarkOrange’, 75, ‘FireBrick’)} | ‘[Family Room Main Lights:switch] == ‘on’ ? [Family Room Main Lights : level]"%" : ‘0’ “%”’][b, black |%’


#4

I noticed your quotes are different (this came up before on another thread) when I copied and pasted it. Are you on a mac?


#5

No, I’m on Windows. I just copied at pasted the above from a registered browser on WebCore.

Is the problem their distinct open/closed styles? I’ve run into issues with that years ago… been a while!

Here’s how they look in the WebCore window:


#6

I haven’t messed with this in a while… what would the end result look like if it’s off?


#7

In the above, it still shows 45% because I don’t have anything in there to insert a ‘0’ if it’s off. When I insert the “IF” statement, I only get 0% in black text. In fact, the “Level is currently” disappears too.


#8

Ady recently added support for curly quotes to make it easier to paste from the forum, so that shouldn’t cause any issues for you. I usually use the + operator in expressions to make it a bit more explicit and easier to see what’s going on. Give this a try, I think there is an order of operations issue with what you were trying; the () parens isolate your if/else ternary logic:

'[b, black | Level is currently][b, ' +
rangeValue([Family Room Main Lights : level], ‘Green’, 25, ‘DarkOrange’, 75, ‘FireBrick’) +
' | ' +
(
    [Family Room Main Lights:switch] == ‘on’ ? [Family Room Main Lights : level] + '%' : '0%'
) +
'][b, black |%]'

#9

That did it, @ipaterson, thank you!! What does the + do - is that an AND operation or more like concatenate?

Now the text color set in the rangevalue makes it so the 0% shown when a switch is off can be orange or red, but I’ll have to figure that out another day!

Cheers!


#10

In this case it concatenates because we’re working with text, but with two numbers it would sum them. It seems like just putting two strings next to each other (‘0’’%’) works but I hadn’t seen that before and I tend to get confused with that many quotes in play :slight_smile:


#11

You and me both! Once I started playing with those, the expression broke in new ways at a high rate of speed!

Thanks for your help and tips - going to make use of those!