How to change Text in Widget Based on Itemstat


i want to change a Text in a widget based on a item state, but i want to change the text via property.

here i define what text should be shown when item is ON or OFF

    - label: On Text
      name: ontext
      required: false
      type: TEXT
    - label: Off Text
      name: offtext
      required: false
      type: TEXT

but how is the syntax for that in Label? the text here change on item state from/to text1 and text2. This works but how i “add” here the 2 props from above ontext and offtext

          - component: Label
              text: '=(items[props.item].state === "ON") ? "text1" : "text2"'
                font-size: 12px
                margin-top: 0px

As described at Building Pages - Components & Widgets | openHAB

props is a dictionary of the key/values of self-defined props for the current personal widget, or page (pages, like any root UI components, may indeed have props).

So, like any dict props.ontext and props.offtext will reference those two properties by name. So replace your hard coded string with the references to props.

Thank you :slight_smile: sometimes the solution is so easy.