Hello, I am trying to do something super simple for all but have been continuously failing.
I want to change the colour of the “ON/OFF”. Attached you will see the YAML. Please send me the full command to be able to control the colouring based on the text. Example: When its ON to make the “ON” text red. When its OFF to make no change and keep it as it is.
Hello Justin! Thans for taking the time! I actually have seen this comments before I created this thread and the reason was because I was not able to adapt to what the comment said. I am not a developer nor know any coding (I understand very basic stuff but have managed to do some stuff on openhab). Given the YAML i posted above, how would you change it in order to make it work?
What you have just posted is correct except for two small changes:
In yaml the level of the indentations is part of the syntax. If you have too many or too few indentations on a line then your syntax is incorrect. In this case you have the label item’s slots property lined up wrong. It should be on the same level as the config property, not on the same level as the other keys under the config.
If you fix just that you should see that the whole things works, except that you will have a little black dash after the red text. That dash is there because the label item is still trying to show an automatic label which you don’t want.
The first thing the post I linked to says is “using the more generic oh-list-item” so you have to change your oh-label-item component to an oh-list-item. That will also get rid of the black dash.
The && is a logical AND, and the way that expression is processed the parser looks at the first part (items.Boiler_Pump_Running.state == "ON") which is a boolean test so it can only either equal true or false. In order for an AND expression to be true the first part must always be true, so if this first part is false the parses just stops and returns false which will cancel color property and you’ll get the default text color. If the first part is true, then the parser looks at the second part which is just “red” (and any non-zero, defined value is also true). The trick here is that the parser returns the second value of the AND so the final result, if the boiler state is ON, is “red” which is the value you want for the color.
Thank you again for the info! I think I am getting there. Now my issue is that the when I put the slots: part the state chnages from ON/OFF to CLOSED/OPEN. The colour coding is correct but now I see values are different.
You have to use displayState instead of state when you want to access the mapped label.
You could also use @'Boiler_Pump_Running' which is a shortcut for ‘item.stateDescription and if not available item.state’