I am trying to create a label cell that changes color and label based on condition. The following code works for tagging the cell green and changing the label. However, when it changes state to OFF, only the label work. The color does not change to red
Changing the color state to == âJa :-)â makes no difference, however if I remove the âlabelâ line, the color yet again works. Any tips to make both work would be most welcome
Thanks for the reply @Sunny. This is what I have in my initial attempt as per the code in my first post. However, this yields the result seen in the attached screenshot. It evaluates correctly to green, but when itâs supposed to evaluate to red, something goes amiss.
sorry I should have elaborated a little more on it rather just dropping lines of code.
From my understanding a cell can have itâs own ON/OFF state. When it is on, the color in color: will be displayed, otherwise it will use the default color and ignore your setting.
Now, when you donât explicitly define what the ON state of the cell is (i.e. no on: property) it must use the switch item as ON/OFF state. So in your case, when your item was OFF, the cell also was OFF and ignored your color setting.
Hope this explains it a little more?
Widgets get their item data from the api, but thereâs no initial parsing. Every state is a string, regardless of the type of the item. If you want a numerical comparison in your ternary statement, then you need to first parse that string into a number.
Thank you! that makes the text change color, but I was trying to color the entire cell. Definitely closer
Is there any documentation on the expression function? Id love to be able check if the value is negative, then the Energy Export should be 0 and red, but if its positive, green!
Is there any real life examples of this Label/Label - expression? Iâd like to change the label depending on the item state (if its greater than 0, Consuming, if its less than 0, feeding in to the grid)