Trying to migrate from NodeRed to openHab

Hi!

For the last 14+ years I developed my own home automation / monitoring / home security system.

First using arduino and now running in a RPI + NodeRed.

Now I’m trying to migrate to openHab to simplify things and use a suitable platform for these functions.

A point I need help is with gauge graphs.

Using NodeRed is very easy to configure a gauge that change color based on values you put in the graph like the one bellow.

Title and messages inside graphs are in brazilian portuguese.

How can I configure openHab gauge to “mimic” NodeRed gauge graphs as much as possible?

Thank you for any guidance.

NR-02-01

The oh-gage-card has a number of properties including fields to control the background colors, font colors, and the “border” color (which is the gage arc itself).

All of these fields support expressions which will let you choose the color, width, etc. based on the state of this or any other Item.

Hi Rich!

In NodeRed you can define a range of values say up to 30% the border is yellow from 31% to 65% is green and above 66% up to the limit is red.

This is what I’m trying do to in openHab oh-gage-card

But the border color is fixed no matter the value.

Thank you.

OH-Gage-01

This is for an icon color but it’s the same idea:

'=(Number.parseInt(items[props.item].state) > 45) ? "purple" : (Number.parseInt(items[props.item].state) > 30) ? "blue" : "orange"'

Though the docs have more concise ways to represent this type of chained expression.

=({'heat':'orange','cool':'blue','auto':'green','off':'white'})[@@hvacModeItem

Though that only really works for discrete states, not ranges.

The first option you suggested seems to be the way to go.

I’ll try to do something like this to “automatically” change border color of oh-gage-card.

Thank you again!

In the oh-gauge-card → Edit YAML I changed

borderBgColor: blue

To

'=(Number.parseInt(items[props.item].state) > 25) ? "red" : (Number.parseInt(items[props.item].state) > 18) ? "blue" : "green"'

But I always get the last color i.e. default option from expression.

OH-Gauge-02

OK, so have you created a property for this widget named “item”?

Maybe show your full widget code.

As discussed in the docs, it’s very helpful to gradually build up an expression like this in the expression tester. But be aware that the expression tester won’t have access to widget properties so you’ll need to use the actual Item name instead.

Note that the “next” version of the docs is much improved when it comes to expressions like this. See Widget Expressions & Variables | openHAB

I just changed oh-gauge-card YAML.

I think the “item” was defined in the YAML.

Is that correct?

Thank you.

component: oh-gauge-card
config:
  bgColor: lightblue
  borderColor: darkgrey
  item: Local_Weather_and_Forecast_Temperatura_Externa
  borderBgColor: '=(Number.parseInt(items[props.item].state) > 25) ? "red" : (Number.parseInt(items[props.item].state) < 18) ? "blue" : "green"'
  max: 50
  min: -10
  type: semicircle

As far as I know no. You have to use the actual Item’s name in expressions. If you define properties on a custom widget you can access those through props but the variable “item” is not a property.

component: oh-gauge-card
config:
  bgColor: lightblue
  borderColor: darkgrey
  item: Local_Weather_and_Forecast_Temperatura_Externa
  borderBgColor: '=(Number.parseInt(items[Local_Weather_and_Forecast_Temperatura_Externa].state) > 25) ? "red" : (Number.parseInt(items[Local_Weather_and_Forecast_Temperatura_Externa].state) < 18) ? "blue" : "green"'
  max: 50
  min: -10
  type: semicircle

Now it’s working. Final version is:

component: oh-gauge-card
config:
  bgColor: lightblue
  borderBgColor: grey
  borderColor: '=(Number.parseFloat(items.Local_Weather_and_Forecast_Temperatura_Externa.state) >= 25) ? "red" : (Number.parseFloat(items.Local_Weather_and_Forecast_Temperatura_Externa.state) <= 18) ? "blue" : "green"'
  item: Local_Weather_and_Forecast_Temperatura_Externa
  max: 50
  min: -10
  type: semicircle
slots: null

I changed from parseInt to parseFloat and use item’s name.

Latter I’ll try to define a custom widget.

Anyway it will be great to have such options in oh-gauge-card in the future.

Thank you very much for your help and attention.

See A more compact way to do "conditional" label/icon/color/whatever in MainUI page

If you’re on openhab 4.2 (milestone or snapshot)

  borderColor: '=#"Local_Weather_and_Forecast_Temperatura_Externa" >= 25 ? "red" : #"Local_Weather_and_Forecast_Temperatura_Externa" <= 18 ? "blue" : "green"'
 

Thank you for the advice.

I’ll try it when I update to 4.2.

I’m running version 4.1 at the moment.

Another improvement is to use the “item” already configured in the card parameter.

This way I don’t need to repeat the name of the test item.

Has this made it into the docs yet? I expected to find it here but it’s not there.

We need to make sure it gets documented before 4.2 release for sure.

I don’t remember whether a PR was made to the docs to add this. I’m currently in holiday mode for several months (travelling, lots of distractions, very little time to focus), so if someone else could add it, it would be great.