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)
Documentation is hard to find. The expressions in widgets are parsed using jsep but should pretty much follow javascript expressions. If you are having trouble with a particular expression, you can use the developer sidebar’s expression tester to work through the issues.
Use the same expression as your highlight color, but replace your "green" and "red" strings with the label text that you want (check out the example in the image above with arbitrary text in the ternary results).
There is something about your items.Energy_FromGrid.state that is not what you are expecting.
The expression will always evaluate to false (meaning you get green and To Grid results) if the value inside parseFloat cannot be parsed to a number. The parser starts at the beginning of the string and collects everything that is a number or numerical symbol and stops when it gets to a space or non-numerical character.
Using the developer sidebar, you can see that the expression works as expected if you replace the items call with a string that looks like the state of an energy type item and can be parsed:
On the other hand, if the value inside the parseFloat is null or nonsense, you will always get the false results:
You can use the api explorer to see what the state of the item looks like to the widget editor or just temporarily put =items.Energy_FromGrid.state into one of the text display configs such as Header to see what you are actually working with.