State Colour for Oh-Item Online/Offline

Hello

I would like to have the online at the back, which you can see in the picture. When online, the online should be green and when offline, the offline should be red.

Can someone please tell me what the code should look like?

Thank you


bild2

iconColor: "=(items.youritem.state) ===  "Online" ? 'green' : 'red' "

You don’t need iconUseState because that is used for a switch and it would change from green to red anyway as far as I know.
Don’t know about fallbackIconToInitial but I would remove that as well.

Hello Greg
Thanks

Sorry, I don’t know how to look at it now, so the code
I wanted to add a code but that doesn’t work!

component: oh-label-item
config:
  item: GigabitSwitchBuro1GS108Ev3_Online
  title: Gigabit Switch Büro 1 (GS108Ev3)
  fallbackIconToInitial: true
  iconColor: "=(items.youritem.state) ===  "Online" ? 'green' : 'red' "
  icon: oh:switch-off

You replace the words youritem with GigabitSwitchBuro1GS108Ev3_Online (the item you want to check)

1 Like

I’ve changed it like this now, but when I click on Done it isn’t taken over → so it would be overwritten again immediately

It will simply be overwritten again immediately

component: oh-label-item
config:
  item: GigabitSwitchBuro1GS108Ev3_Online
  title: Gigabit Switch Büro 1 (GS108Ev3)
  fallbackIconToInitial: true
  iconColor: "=(GigabitSwitchBuro1GS108Ev3_Online) ===  "Online" ? 'green' : 'red' "
  icon: oh:switch-off
  
  iconColor: "=(items.GigabitSwitchBuro1GS108Ev3_Online.state) ===  "Online" ? 'green' : 'red' "

No idea what’s there when I paste the code
then it is as if the code is read-only

No Idea what you are looking at but here is the page that describes the oh-label-item

I created the code like you said

But as soon as I click on Done the original code is there again

component: oh-label-item
config:
  item: GigabitSwitchBuro1GS108Ev3_Online
  title: Gigabit Switch Büro 1 (GS108Ev3)
  fallbackIconToInitial: true
  iconColor: "=(items.GigabitSwitchBuro1GS108Ev3_Online.state) ===  "Online" ? 'green' : 'red' "
  icon: oh:switch-off
component: oh-label-item
config:
  item: GigabitSwitchBuro1GS108Ev3_Online
  title: Gigabit Switch Büro 1 (GS108Ev3)
  fallbackIconToInitial: true
  iconColor: green
  icon: oh:switch-off
  iconUseState: true

I just want to set this word ONLINE to green or red at the back where it says online!

Thanks

OK NOT the icon.
I cannot see an option for the colour of the state text in the documentation, so I don’t know how to do it.

Yes, exactly

Thank you anyway

If my code looks like this, the label text changes but online is still gray

component: oh-label-item
config:
  item: GigabitSwitchBuro1GS108Ev3_Online
  title: Gigabit Switch Büro 1 (GS108Ev3)
  fallbackIconToInitial: true
  iconColor: green
  icon: oh:switch-off
  iconUseState: true
  style:
    color: '=(items.GigabitSwitchBuro1GS108Ev3_Online.state == "OFF") ? "red" : "green"'

oh-icons do not use the color config.
They have individual icons for on and off state.
Your icon therefore just needs to be

oh:switch

For reference:
https://openhabforum.de/viewtopic.php?p=58384#p58384