Change color of label depending on temperature

Hello,

I am running OH4 and integrated some controls from Livisi (fromer innogy). Here we are dealing with temperature controls…
I am trying t change the background color of a created label card if the current temperature in a specific room drops below a defined value.

That’s what I tried:

background: “=items.Heizung_Wohnzimmer_Aktuelle_Temperatur.value as Number <= 25
? ‘red’ : ‘green’”

The background is always “green”.

How t solve that?

Many thanks in advance!!!

Try something like this:

component: oh-label-cell
config:
  color: =((Number.parseFloat(items.FroniusSymoInverter_GridPower.state))>=0)?('red'):('green')
  on: true

And you can condition the on: statement to show the colour or not.
Example:

  on: =((Number.parseFloat(items.FroniusSymoInverter_GridPower.state))!=0)

1 Like

Many thanks, I tried:

background: ((Number.parseFloat(items.Heizung_Wohnzimmer_Aktuelle_Temperatur.state))<=
25)?(‘red’):(‘green’)

All white ;-(
Any idea?


The parameter ‚Highlight color‘ is only active, if the condition of the parameter ‚Label‘ is ‚ON‘. Otherwise your widget stays white. Therefore I used an Item , which is allways ON, but as you can see, if you use the comment of @ubeaut and modify the yaml, my version is not needed.


And that‘s what @ubeaut mentioned , if you edit the YAML code

It’s working with the following:

background: =(Number.parseFloat(items.Heizung_Wohnzimmer_Aktuelle_Temperatur.state)<
25)?(‘red’):(‘green’)

I obviously missed the " = "

Many thanks all!!

Next question: how can I dal with 3 colors? up to 19° → blue, up to 21° orange and hotter red?

Sorry, my headline was wrong: it should have been “card” and not “label”…

Instead of ‚green‘ , you place the next condition
If(xxxx)? Red : if(yyyy)? Yellow : green

component: oh-label-card
config:
  title: Temperature
  item: Heizung_Wohnzimmer_Aktuelle_Temperatur
  background: =items.Heizung_Wohnzimmer_Aktuelle_Temperatur.numericState>19?(items.Heizung_Wohnzimmer_Aktuelle_Temperatur.numericState>21?'red':'orange'):'blue'

If you want the whole card have the desired color then try to use background property under style:

component: oh-label-card
config:
  title: Temperature
  item: Heizung_Wohnzimmer_Aktuelle_Temperatur
  style:
    background: =items.Heizung_Wohnzimmer_Aktuelle_Temperatur.numericState>19?(items.Heizung_Wohnzimmer_Aktuelle_Temperatur.numericState>21?'red':'orange'):'blue'

See this: A more compact way to do "conditional" label/icon/color/whatever in MainUI page - #3 by jimtng

Instead of items.YourItemName.numericState use: #'YourItemName'. This is documented here: Widget Expressions & Variables | openHAB

  background: =#'Heizung_Wohnzimmer_Aktuelle_Temperatur' > 21 ? 'red' : #'Heizung_Wohnzimmer_Aktuelle_Temperatur' > 19 ? 'orange' : 'blue'
3 Likes