Weird behavior from the shown humidity - widget - OH3

Hello there,

After a long search, why my humidity is shown some weird stuff, I am going to create this topic in the hope to get someone, who can maybe help or explain to me what happens.

Case:
My widgets from the Main UI are shown the percentage randomly correct and incorrect formatted.
OH Main

This happens to all widgets and it’s random, so someday it’s the kitchen, and someday it’s the living room or something else.
The widget should be correctly programmed, I got it from this topic
https://community.openhab.org/t/oh3-main-ui-examples/117928/198

The widget is only showing what the input delivers.
This only occurs with the OH3 created things with the old OH2 setup, I’ve never run into these problems.
So it must be a problem with my configuration of the item.

I can see in the logs, that the item is randomly switching to this value.

2022-01-15 15:58:30.099 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘BadobenUpdate’ changed from 2022-01-15T15:38:53.827+0100 to 2022-01-15T15:58:30.057+0100
2022-01-15 15:58:30.103 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘BadobenLuftfeuchtigkeit’ changed from 59.75 % to 60.160000000000004 %
2022-01-15 15:58:30.105 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘BadSensorobenLUMI_Humidity’ changed from 59.75 % to 60.160000000000004 %

Here are my .thing and .item



also, I don’t understand, why the item is showing the percentage correctly when I am in the configuration site of the item.
When I take a look at the graph it’s also wrong formatted it’s in “0.6” values formatted.

What am I doing wrong ?
Where can I declare this, I am not able to find my fault.

Maybe someone else sees my problem and can help me.

Thanks a lot

greetings

Put a default unit (for you, %) in your Item’s metadata ‘pattern’. Persistence uses this to reconstruct values from stored numerics.

this is good to know, doesn’t know that.
But this only changes the overview page of the item. (in my setup / maybe it is wrong)
I’ve created the metadata with “%.1f%%”

I’ve triggered new input for the graph, but it is still the same format.
graph

Well, it isn’t going to go back and change historic data.

yeah, thats why I triggered new data, so the new data should be correctly formatted ?
As you can see, it’s from 15.01.22 16:49 so a few minutes ago after I made those changes.
Or does it only change with a new day ?

Similar posting -

similar yes, but all they discuss is which I already made, or am I wrong ?
The state Description is changed after your hint also I changed the Semantic Class now to measurement.
As before it looks the same.
I can trigger the channels manually by pressing a physical button on my sensors.
I got no delay in this, the measurement point is created instantly after my button press.

Is there something left I can try ?

what is also confusing to me, why doesn’t display openhab the item as I configured it?
In my logic, when I set a default Metadata pattern “%.1f %%” is the item shown correctly.

But why does the widget which only “shows” the value of the item shows a different pattern ?
graph

It is the same item, why is it not formatted ? when it is coded in the Metadata as State description in the item ? I thought this would solve at least this problem :open_mouth:

I think I am running in circles with my problem, and I can’t find a hint to solve it.

uid: Card_room_12
tags: []
props:
  parameters:
    - label: Header
      name: text_header
      required: false
      type: TEXT
    - description: icon name without ".png", located in static/icons/ folder
      label: Icon
      name: iconimage
      required: false
      type: TEXT
    - description: HEX or rgba
      label: Backgroundcolor
      name: bgcolor
      required: false
      type: TEXT
    - description: Page which will be opened as popup
      label: Page ID
      name: page
      required: false
    - context: item
      description: select group for status lights
      label: Item
      name: status
      required: false
      type: TEXT
    - context: item
      description: select item for heating
      label: Item
      name: heating
      required: false
      type: TEXT
    - context: item
      description: select item for temperature
      label: Item
      name: temp
      required: false
      type: TEXT
    - context: item
      description: select item for set temperature
      label: Item
      name: settemp
      required: false
      type: TEXT
    - context: item
      description: select item for humidity
      label: Item
      name: humidity
      required: false
      type: TEXT
    - context: item
      description: select item for illuminance
      label: Item
      name: illuminance
      required: false
      type: TEXT
    - context: item
      description: select item for door state(s)
      label: Item
      name: door_state
      required: false
      type: TEXT
    - context: item
      description: select item for door lock(s)
      label: Item
      name: door_lock
      required: false
      type: TEXT
    - context: item
      description: select item for blinds group (SUM)
      label: Item
      name: blinds_closed
      required: false
      type: TEXT
    - context: item
      description: select item for speaker(s)
      label: Item
      name: speakers
      required: false
      type: TEXT
    - context: item
      description: select item for windows(s)
      label: Item
      name: windows
      required: false
      type: TEXT
    - context: item
      description: select item for numbers of windows
      label: Item
      name: windows_numbers
      required: false
      type: TEXT
    - context: item
      description: select item for boiler temp
      label: Item
      name: boiler_temp
      required: false
      type: TEXT
    - context: item
      description: select item for Printer
      label: Item
      name: printer
      required: false
      type: TEXT
timestamp: Jan 15, 2022, 3:39:40 PM
component: f7-card
config:
  style:
    background-color: "=props.bgcolor ? props.bgcolor : ''"
    border-radius: var(--f7-card-expandable-border-radius)
    box-shadow: 5px 5px 10px 1px rgba(0,0,0,0.1)
    class:
      - padding: 0px
    height: 125px
    margin-left: 5px
    margin-right: 5px
    noShadow: false
slots:
  content:
    - component: f7-block
      config:
        style:
          left: 50px
          position: absolute
          top: -5px
      slots:
        default:
          - component: Label
            config:
              style:
                font-size: 17px
                font-weight: 600
                margin-left: 0px
                margin-top: 0px
              text: "=props.text_header ? props.text_header : 'Set Props'"
    - component: f7-block
      config:
        style:
          bottom: -37px
          left: 16px
          position: absolute
      slots:
        default:
          - component: f7-chip
            config:
              iconColor: "=themeOptions.dark === 'dark' ? 'white' : 'black'"
              iconF7: "=(Number(items[props.status].state) > 0) ? 'lightbulb' : 'lightbulb_slash'"
              iconSize: 18
              style:
                --f7-chip-bg-color: rgba(255, 255, 255, 0)
              text: "=(Number(items[props.status].state) > 0) ? items[props.status].state : ''"
              visible: "=props.status ? true : false"
          - component: f7-chip
            config:
              iconColor: "=themeOptions.dark === 'dark' ? 'white' : 'black'"
              iconF7: flame
              iconSize: 18
              style:
                --f7-chip-bg-color: rgba(255, 255, 255, 0)
              text: "=items[props.heating].state === 'ON' ? '' : ''"
              visible: =items[props.heating].state === 'ON'
          - component: f7-chip
            config:
              iconColor: "=themeOptions.dark === 'dark' ? 'white' : 'black'"
              iconF7: printer
              iconSize: 18
              style:
                --f7-chip-bg-color: rgba(255, 255, 255, 0)
              text: "=items[props.printer].state === 'ON' ? '' : ''"
              visible: =items[props.printer].state === 'ON'
          - component: f7-chip
            config:
              style:
                --f7-chip-bg-color: rgba(255, 255, 255, 0)
              text: "=items[props.door_state].state === 'ON' ? '' : ''"
              visible: "=props.door_state ? true : false"
            slots:
              media:
                - component: oh-icon
                  config:
                    icon: "=items[props.door_state].state === 'ON' ? 'door-open' : 'door-closed'"
                    style:
                      filter: "='brightness(' + (themeOptions.dark === 'dark' ? '1' : '0.4') + ')'"
                      height: 18px
          - component: f7-chip
            config:
              style:
                --f7-chip-bg-color: rgba(255, 255, 255, 0)
              text: "=items[props.windows_numbers].state > 0 ? items[props.windows_numbers].state : ''"
              visible: "=items[props.windows].state === 'OPEN' ? true : false"
            slots:
              media:
                - component: oh-icon
                  config:
                    icon: window-open
                    style:
                      filter: "='brightness(' + (themeOptions.dark === 'dark' ? '1' : '0.4') + ')'"
                      height: 18px
          - component: f7-chip
            config:
              iconColor: "=themeOptions.dark === 'dark' ? 'white' : 'black'"
              iconF7: "=items[props.door_lock].state === 'ON' ? 'lock_open' : 'lock'"
              iconSize: 18
              style:
                --f7-chip-bg-color: rgba(255, 255, 255, 0)
              text: "=items[props.door_lock].state === 'ON' ? '' : ''"
              visible: "=props.door_lock ? true : false"
          - component: f7-chip
            config:
              style:
                --f7-chip-bg-color: rgba(255, 255, 255, 0)
              text: "=(Number(items[props.blinds_closed].state) === 0) ? '' : Math.floor(items[props.blinds_closed].state)"
              visible: "=(Number(Math.floor(items[props.blinds_closed].state)) > 0) ? true : false"
            slots:
              media:
                - component: oh-icon
                  config:
                    icon: "=(Number(items[props.blinds_closed].state) === 0) ? 'cinemascreen-30' : 'cinemascreen-100'"
                    style:
                      filter: "='brightness(' + (themeOptions.dark === 'dark' ? '100' : '0.3') + ')'"
                      height: 18px
          - component: f7-chip
            config:
              iconColor: "=themeOptions.dark === 'dark' ? 'white' : 'black'"
              iconF7: "=items[props.speakers].state === 'PLAY' ? 'speaker_2' : 'speaker'"
              iconSize: 18
              style:
                --f7-chip-bg-color: rgba(255, 255, 255, 0)
              visible: "=items[props.speakers].state === 'PLAY' ? true : false"
          - component: f7-chip
            config:
              iconColor: "=themeOptions.dark === 'dark' ? 'white' : 'black'"
              iconF7: sun_min
              iconSize: 18
              style:
                --f7-chip-bg-color: rgba(255, 255, 255, 0)
              text: =items[props.illuminance].displayState
              visible: "=props.illuminance ? true : false"
    - component: f7-block
      config:
        style:
          bottom: -65px
          left: 16px
          position: absolute
      slots:
        default:
          - component: f7-chip
            config:
              iconColor: "=themeOptions.dark === 'dark' ? 'white' : 'black'"
              iconF7: thermometer
              iconSize: 18
              style:
                --f7-chip-bg-color: rgba(255, 255, 255, 0)
              text: "=(items[props.temp].displayState  ? items[props.temp].displayState : items[props.temp].state) +  (props.settemp ? ' (' + items[props.settemp].state + ')' : '')"
              visible: "=props.temp ? true : false"
          - component: f7-chip
            config:
              iconColor: "=themeOptions.dark === 'dark' ? 'white' : 'black'"
              iconF7: drop
              iconSize: 18
              style:
                --f7-chip-bg-color: rgba(255, 255, 255, 0)
              text: =items[props.humidity].state
              visible: "=props.humidity ? true : false"
          - component: f7-chip
            config:
              style:
                --f7-chip-bg-color: rgba(255, 255, 255, 0)
              text: =items[props.boiler_temp].state
              visible: "=props.boiler_temp ? true : false"
            slots:
              media:
                - component: oh-icon
                  config:
                    icon: waterheater2
                    style:
                      filter: "='invert(' + (themeOptions.dark === 'dark' ? '1' : '0') + ')'"
                      height: 18px
    - component: oh-image
      config:
        style:
          height: 25px
          left: 16px
          opacity: 0.7
          position: absolute
          top: 10px
        url: ='/static/icons/' + props.iconimage + '.png'
        visible: "=props.iconimage ? true : false"
    - component: oh-link
      config:
        action: popup
        actionModal: ='page:' + props.page
        style:
          height: 110px
          left: 0px
          position: absolute
          top: 0px
          width: 100%

The state returned by the items object in widgets is always the unformatted state. If you have applied a pattern to the state and want to see the state with that format applied you have to use displayState instead.

text: =items[props.humidity].displayState
2 Likes

wow, thanks for that hint.
That’s the solution for the widget problem. ! :slight_smile:
Thank you

only one problem with the graph to got :smiley:

edit: that hint also fixed the graph problem.
after that change, the graph is shown correctly ! :slight_smile: thanks

One question left :slight_smile:
I noticed after those changes in the widget, the humidity seems to timeout.
For example, my office humidity values are 5min old and the humidity is not shown in the widget.
I don’t know at which point the humidity is not shown but it has something to do with the saved values.

This occurs in every room at some time, so it is a widget problem I think.

home


as you can see, the last update on that item was around 5 min ago.

If I manually trigger the item to update (the Xiaomi sensors got a physical button for this)
the humidity is instantly shown and displayed correctly.

home2

Is there any chance I can change that behavior ?
And why does this happen ? the last value of the item should be saved or at least displayed until new data comes in or am I wrong ?
At my Sitemap(BasicUI) the values are constantly shown correctly.

There’s one more level of complication here. Even if your item has a pattern, it might not always have a displayState. In order to optimize performance of the UI, if the state and displayState of an item are identical then only the state is passed to the items object. So if you have an item where the state and displayState can occasionally be the same (as appears to be happening here) then you need to test for displayState and fall back to the state if necessary.

text: =items[props.humidity].displayState || items[props.humidity].state
2 Likes

okay, I didn’t know that, it worked.
Thanks for that hint !!
I’d never have guessed it.