pbm
(Philipp)
January 8, 2025, 7:56am
1
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!!!
ubeaut
(Greg)
January 8, 2025, 10:32am
2
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
pbm
(Philipp)
January 8, 2025, 11:31am
3
Many thanks, I tried:
background: ((Number.parseFloat(items.Heizung_Wohnzimmer_Aktuelle_Temperatur.state))<=
25)?(‘red’):(‘green’)
All white ;-(
Any idea?
Mclupo
(Wolf Kroenert )
January 8, 2025, 11:43am
4
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.
Mclupo
(Wolf Kroenert )
January 8, 2025, 12:16pm
5
And that‘s what
@ubeaut mentioned , if you edit the YAML code
pbm
(Philipp)
January 8, 2025, 12:40pm
6
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?
pbm
(Philipp)
January 8, 2025, 1:01pm
7
Sorry, my headline was wrong: it should have been “card” and not “label”…
Mclupo
(Wolf Kroenert )
January 8, 2025, 1:26pm
8
Instead of ‚green‘ , you place the next condition
If(xxxx)? Red : if(yyyy)? Yellow : green
djal
(Dusan Jaluvka)
January 8, 2025, 1:32pm
9
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'
jimtng
(jimtng)
January 8, 2025, 1:41pm
10
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