OH3 Changing color based on Temperature Item

I need some help.
I want to change color based on temperature.
I have searched but not find anything based on temperature.

Number:Temperature    Outdoor_Sensor_Temperature        "Garden Temperature [%.1f °C]"          <temperature>    (geOutdoor_Sensor, gpC)                              ["Measurement", "Temperature"]    {channel="rfxcom:temperaturehumidity:usb0:35585:temperature" [profile="offset", profile-parameterID="-1 °C"]}

This is what i have tried

color: '=(items.Outdoor_Sensor_Temperature_1.state <= 0) ? "blue" : "red"'

But it does not handle a temperature item as decimal it seems.

Hello Michael,

I am changing colour based on air quality using the RGB colour code

                    item: AirQuality_AirQualityIndex
                    background: =(items.AirQuality_AirQualityIndex.state < 60) ? '#00ffaa':'#ff0000'
                    title: AQI'

Note that you’ve got an available channel that gives you the color : aqiColor

Your Number:Temperature type Item has a state that includes units e.g. 7°C
You might need to strip that to a numeric to do your comparison, I don’t know how you do that in a widget. (In a rule you would compare with units e.g. mystate > 10 | °C but I do not think you can do that in HABpanel)

Thanks @rossko57 that is exactly my problem.
I think this will be needed from others also.
I know that i can create a parallell item that is decimal type but i want to keep down the number of items that needs to be updated.
So a way to parse this in the OH3 widget would be the preferred solution.

You could strip out the value symbol and do your comparison like this:

color: '=(items.Outdoor_Sensor_Temperature_1.state.split(" ")[0] <= 0) ? "blue" : "red"'

Thank you, it works lika a charm.
Can i also ask you how to nest if, i have tried this but it does not work

color: '=(items.SMHI_Temperature_Min_1.state.split(" ")[0] <= 0) ? "blue" : (items.SMHI_Temperature_Min_1.state.split(" ")[0] <= 20) ? "black" : "red"'

I think, this should work (enclosing the 2nd condition in your expression with brackets):

color: '=(items.SMHI_Temperature_Min_1.state.split(" ")[0] <= 0) ? "blue" : ((items.SMHI_Temperature_Min_1.state.split(" ")[0] <= 20) ? "black" : "red")'

Sorry but that did not work get blue on everything.
Having problems to test red in Sweden now :slight_smile:

Ups, I didn’t checked the logic itself - the blue condition as well as the black condition are true at the same time if the values are lower or equal to 20 so you’ve to add an AND statement here, something like this:

=(items.SMHI_Temperature_Min_1.state.split(" ")[0] <= 0) ? "blue" : ((items.SMHI_Temperature_Min_1.state.split(" ")[0] > 0 && items.SMHI_Temperature_Min_1.state.split(" ")[0] <= 20) ? "black" : "red")'