Knob gets red but should be green

Hi,

following 2 knob get red between value 4 and 9.9 but should be green there.

Lightblue lower 0 works and red when bigger 30 also.

Green from 0 to 3.9 and 10 to 30 is right, but should be from 0 to 30.

component: oh-knob-card
config:
  item: Klima_1_Eltern_Outdoor_Temperature
  max: 40
  min: -40
  rangeColor: '=(items.Klima_1_Eltern_Outdoor_Temperature.state < "0") ?
    "lightblue" : (items.Klima_1_Eltern_Outdoor_Temperature.state > "30") ?
    "red" : "green"'
  step: 0.1
  title: Außentemp. Klima




component: oh-knob-card
config:
  item: NetatmoAussen_Aussentemperatur
  max: 40
  min: -40
  rangeColor: '=(items.NetatmoAussen_Aussentemperatur.state < "0") ? "lightblue" :
    (items.NetatmoAussen_Aussentemperatur.state > "30") ? "red" : "green"'
  step: 0.1
  title: Netatmo

Thx and br
Edi

Try taking the quotes from the numbers like below.

rangeColor: '=(items.NetatmoAussen_Aussentemperatur.state < 0) ? "lightblue" :
    (items.NetatmoAussen_Aussentemperatur.state > 30) ? "red" : "green"'

thx, but does not work. without the quores around the numbers the knob is always green.

may something like this?

uid: test_knob_widget
tags: []
props:
  parameters:
    - description: A text prop
      label: Prop 1
      name: prop1
      required: false
      type: TEXT
    - context: item
      description: An item to control
      label: Item
      name: Klima_1_Eltern_Outdoor_Temperature
      required: false
      type: TEXT
  parameterGroups: []
timestamp: Jan 6, 2024, 5:14:16 AM
component: oh-knob-card
config: 
  item: = props.Klima_1_Eltern_Outdoor_Temperature
  max: 40
  min: -40
  rangeColor: '= (Number.parseFloat(items[props.Klima_1_Eltern_Outdoor_Temperature].state)) >= 30.0 ? "red" : (Number.parseFloat(items[props.Klima_1_Eltern_Outdoor_Temperature].state)) >= 25.0 ? "orange" : (Number.parseFloat(items[props.Klima_1_Eltern_Outdoor_Temperature].state)) <= 0.1 ? "lightblue" : "green"'   
  step: 0.1
  title: Außentemp. Klima

I added orange just because it shows more conditions

Hi and thx, does not work. Tried with .0 and with .0. Also with and without quotes around the number. THX and BR

This produces red when the value reaches 4 because you are not comparing numbers, you are comparing string. In widget expressions, items.itemName.state always returns a string representation of the item state, so in this case "4", not 4. A string comparison tests each character in the two strings one at a time (it is “alphabetizing” them). So the first check is "4" > "3" which is true and so the ternary statement returns "red".

You want a number comparison. So, as @ubeaut pointed out you need to not have the "..." around the value, and @justaoldman also gave you the other part of the solution which is that you have to enclose the item state in something that converts the state string to a number such as Number.parseFloat. If you have both those piece then you are comparing two numbers and 4 will indeed be less than 30.

If you properly converted that example it should have worked. Note that the provided example is getting the item state via a property and yours is not, so for your widget the conversion looks more like this:

Number.parseFloat(items.Klima_1_Eltern_Outdoor_Temperature.state) < 0

Hello Justan and Justin,

thank you both, now it works.
Seems I had some other sign or so i didn’t see at my first tries at all.

THX and BR