Set piston state text color based on text


#1

Has anyone in here worked with the text formatting yet for piston state? I’ve got this piston that sends me weather alerts and it’s got in the piston state a section where it tells you if there are any weather alerts and if not it’ll say “clear”. All I’m using is the smart weather tile for the information. Basically why I’d like to do is if that section doesn’t say clear then I want the text to be written in red font. I know it’s possible to change text color but not sure how to write a statement that’ll do what I want. Here’s the piston and the part I’m talking about.


#2

Here are 3 examples written as an expression:

temp


More information can be found here.


#3

As far as how to code that specifically, I often simplify it by first dumping the data I want into a variable, then calling it like this:

Which returns this on my Dashboard:

temp

or this way if I bold it:

temp


#4

How can I set the piston state conditional? Basically if text doesn’t equal X then change color?


#5

Think maybe I’ve got it.


#6

If you are using an expression, line 53 might be easier to decipher if you use this syntax:

title(Weather)" | "Temperature"° | ['Red' | "Alert"]"

which returns something like this:

temp

The logic behind this is:
When using Expressions, then variables do not require curly brackets, and should be placed outside the quotation marks.


#7

You’re right. Is there any harm in leaving them like that though? I’ve done a ton of pistons all using that same formatting.


#8

Use an expression:

contains(weatherconditionhere, clear) ? ‘Piston state in black text’ : ‘Piston state in red text’


#9

If it works, it works.
I only suggested it because there seemed to be an abundance of brackets.

(well, that plus other people may try to copy your code into their piston)