Popup for Shutter-Widget

That is a little tricky. The oh-label-item is made of of several different pieces, and the only way to change the styles on the item state label part is to access it directly with css. You do this using a special property tag stylesheet and putting a full css declaration in that (this is similar to, but not the same as the style property, and you can use both in one component)… To change the text color that would look like this:

               - component: oh-label-item
                  config:
                    style:
                      font-size: 14px
                      margin-left: 0px
                      margin-bottom: 0px
                      margin-top: 5px
                      margin-right: 0px
                      -index: 1
                    title: =props.title5
                    item: =props.item5
                    stylesheet: >
                      .item-after div {
                        color: green
                      }
1 Like

I know CSS declarations in dealing with HTML files. Some.css data had to be created and made available in specific directories.
But how does that work under Openhab 3, how is one structured and where is it stored?

When you’re working with the widgets, you don’t have to worry at all about separate css files. You can just use the stylesheet property demonstrated above and the css will be applied at that level of the page/widget (i.e., the new declarations will be applied to the widget and any of its direct descendants). Many of the page types can also take advantage of this stylesheets property as well so you can customize the look of an entire page easily if that is your desire.

It currently looks like this:

screenshot_7

Can the color of the item value also be changed automatically when the value itself changes (from green to red)?

Could it work like this? I can only really test it when a new firmware update is available.

                      - component: oh-label-item
                        config:
                          style:
                            font-size: 13px
                            margin-bottom: 0px
                            margin-left: 0px
                            margin-top: 5px
                            width: 220px
                            z-index: 1
                          title: =props.title1
                          item: =props.item1
                          stylesheet: >
                            .item-after div { color: green }  
                          color: '=(items[props.item1].state === "aktuell") ? "red" : green"'

The way to make this work is actually a two part process. The problem is that the stylesheet property does not get processed by the expression parser that allows for things like the x == y ? if true : if false ternary expressions. So the stylesheet property is just going to be a static string no matter what. The properties under the style heading, on the other hand, do get processed by the expression parser so we can make those dynamic, but we can’t use those to access the label text for formatting. The solution is to combine the two using css variables. We can set a variable in the style property to a dynamic expression and then reference just the static name of the variable in the stylesheet.

                      - component: oh-label-item
                        config:
                          style:
                            font-size: 13px
                            margin-bottom: 0px
                            margin-left: 0px
                            margin-top: 5px
                            width: 220px
                            z-index: 1
                            --custom-label-color: '=(items[props.item1].state === "aktuell") ? "red" : green"'
                          title: =props.title1
                          item: =props.item1
                          stylesheet: >
                            .item-after div { color: var(--custom-label-color) }  

But that is very complicated and without their help I would never have gotten it off the ground on my own.
Once again I am very impressed and once again I say: thank you very much

Unfortunately it doesn’t work yet. But now I also don’t know the value of the item when an update is due. Maybe I should wait with a test until the time comes…

I have now installed an older firmware and the item value is set to “update”.
Instead, the color is generally white and does not change.
I can’t find an error, where could the problem lie?

                      - component: oh-label-item
                        config:
                          style:
                            font-size: 13px
                            margin-bottom: 0px
                            margin-left: 0px
                            margin-top: 5px
                            width: 220px
                            z-index: 1
                            --custom-label-color: '=(items[props.item1].state === "updaten") ? "green" : red"'
                          title: =props.title1
                          item: =props.item1
                          stylesheet: >
                            .item-after div { color: var(--custom-label-color) }

Looks like I missed a quotation mark when quickly typing up the variable expression earlier. red" should, of course, be "red".

now the value is displayed in “red”, but the color does not change with an update.

Should updaten not be update based on what you said above?

That means that we know the expression is being evaluated properly, but your item state just never equals “updaten”. This is most often an issue of the difference between an item state and its displayState. Every item has a state: the technical value that the item currently represents. Often times, that value is not well formatted for visualization or a UI so items can also have rules for formatting their state in a different way. When working with the widgets, the items object allows access to both. items["some_item"].state gives you the actual state and if there is a state formatting rule, items["some_item"].displayState returns that formatted value instead.

In your widget you’ve put props.item1 in an oh-label-item and that by default displays the dispalyState if there is one for the item. So, “updaten” is probably the formatted value of the state (or displayState) and not the actual value of the state. You can either look in your logs to see what the actual value the state is taking is, or just quickly change one of the text fields (for example, title) to items[props.item1].state just see what value is really being passed there.

1 Like

Yes, that’s my fault. If the Item.state OFF/ON is used, everything works as intended. The values “aktuell” and “updaten” are the display status.
In the course of the evening I will reproduce the complete code here again so that other users can also deal with it.

Thank you for the great support!

Hi, here is the complete, fully working code again:

uid: shutter_widget_v9
tags: []
props:
  parameters:
    - description: Title of the card (blank for none)
      label: Title
      name: title
      required: false
      type: TEXT
    - description: The card footer (no footer!!)
      label: Footer
      name: footer
      required: false
      type: TEXT
    - description: Description Info 1 (<u>Suggestion:</u> <b>Firmware</b>)
      label: Info1
      name: title1
      required: true
      type: TEXT
    - description: Description Info 2 (<u>Suggestion:</u> <b>Total kWh</b>)
      label: Info2
      name: title2
      required: true
      type: TEXT
    - description: Description Info 3 (<u>Suggestion:</u> <b>Signal strength</b>)
      label: Info3
      name: title3
      required: true
      type: TEXT
    - description: Description Info 4 (<u>Suggestion:</u> <b>Interne Temperatur</b>)
      label: Info4
      name: title4
      required: true
      type: TEXT
    - description: Description Info 5 (<u>Suggestion:</u> <b>Shutter-Position</b>)
      label: Info5
      name: title5
      required: true
      type: TEXT
    - context: item
      description: Item for info 1 (<u>Example:</u> <b>_Firmwareaktualisierungvorhanden</b>)
      label: Item
      name: item1
      required: true
      type: TEXT
    - context: item
      description: Item for info 2 (<u>Example:</u> <b>_Gesamtverbrauch</b>)
      label: Item
      name: item2
      required: true
      type: TEXT
    - context: item
      description: Item for info 3 (<u>Example:</u> <b>_Signalstarke</b>)
      label: Item
      name: item3
      required: true
      type: TEXT
    - context: item
      description: Item for info 4 (<u>Example:</u> <b>_Gerätetemperatur</b>)
      label: Item
      name: item4
      required: true
      type: TEXT
    - context: item
      description: Item for info 5 (<u>Example:</u> <b>__Steuerung0offen100geschlossen</b>)
      label: Item
      name: item5
      required: true
      type: TEXT
    - context: item
      description: Item for Rollershutter Control (<u>Example:</u> <b>_Steuerung0offen100geschlossen</b>)
      label: Item
      name: control
      required: true
      type: TEXT
    - description: Set background color (blank for none)
      name: background
      required: false
      type: TEXT
    - description: Set text color (blank for none)
      name: color
      required: false
      type: TEXT
      advanced: false
  parameterGroups: []
timestamp: May 4, 2022, 6:18:07 AM
component: f7-card
config:
  left: center
  style:
    background: '=(props.background) ? props.background : ""'
    color: '=(props.color) ? props.color : ""'
    filter: brightness(95%)
    height: 280px
    width: 250px
  title: =props.title
slots:
  default:
    - component: f7-card-content
      slots:
        default:
          - component: f7-row
            config:
              class:
                - display-flex flex-direction-row
                - justify-content-space-evenly
                - align-items-center
            slots:
              default:
                - component: f7-col
                  config:
                    class:
                      - display-flex
                      - flex-direction-column
                      - justify-content-center
                      - align-items-center
                    style:
                      height: calc(100% - 30px)
          - component: oh-rollershutter-card
            config:
              dirIconsStyle: chevron_{dir}_square_fill
              item: =props.control
              stopIconStyle: stop_circle_fill
              style:
                background-color: rgba(246, 158, 81, 0.2)
          - component: f7-col
            slots:
              default:
                - component: oh-list
                  config: {}
                  slots:
                    default:
                      - component: oh-label-item
                        config:
                          item: =props.item1
                          style:
                            --custom-label-color: '=(items[props.item1].state === "OFF") ? "green" : "red"'
                            font-size: 13px
                            margin-bottom: 0px
                            margin-left: 0px
                            margin-top: 5px
                            width: 220px
                            z-index: 1
                          stylesheet: >
                            .item-after div { color: var(--custom-label-color) }                          
                          title: =props.title1
                - component: oh-button
                  config:
                    action: popover
                    fill: true
                    outline: true
                    popoverOpen: =".popover.info-pop-" + props.item1
                    raised: true
                    style:
                      left: 55px
                      position: absolute
                      text-align: center
                      top: 165px
                      color: rgb(00, 00, 00)
                    text: mehr / weniger ...
    - component: f7-popover
      config:
        class: ="info-pop-" + props.item1
        closeByBackdropClick: true
        closeByOutsideClick: true
        closeOnEscape: true
        style:
          color: peru
          background-color: rgb(00, 00, 00)
          height: 155px
          width: 250px
      slots:
        default:
          - component: oh-list
            config:
              simpleList: true
            slots:
              default:
                - component: oh-label-item
                  config:
                    item: =props.item2
                    style:
                      -index: 1
                      font-size: 14px
                      margin-bottom: 0px
                      margin-left: 0px
                      margin-right: 0px
                      margin-top: 5px
                    title: =props.title2
                - component: oh-label-item
                  config:
                    item: =props.item3
                    style:
                      -index: 1
                      font-size: 14px
                      margin-bottom: 0px
                      margin-left: 0px
                      margin-right: 0px
                      margin-top: 5px
                    title: =props.title3
                - component: oh-label-item
                  config:
                    item: =props.item4
                    style:
                      -index: 1
                      font-size: 14px
                      margin-bottom: 0px
                      margin-left: 0px
                      margin-right: 0px
                      margin-top: 5px
                    title: =props.title4
                - component: oh-label-item
                  config:
                    item: =props.item5
                    style:
                      -index: 1
                      font-size: 14px
                      margin-bottom: 0px
                      margin-left: 0px
                      margin-right: 0px
                      margin-top: 5px
                    title: =props.title5

Sorry, but another problem has arisen. I have now created several shutters, all based on the same scheme. Although different items are addressed, popovers always show me the same values. My guess is that the popover is hidden but not closed. What changes need to be made in the code?

I mentioned up above that if you have more than one such popup or popover on the same page with the same identifications things will get confused. What’s going on here is that all of the widgets exist on the same page so there are multiple elements with the class info-pop so each widget is just sending a command to open info-pop opening the first one, which is always the same.

The solution here is to find a way to ensure that the name of the popover class is always unique to that widget. Fortunately you already have something that is a string that is unique to that widget and compatible with the requirements for css class names: props.item1. So, all you have to do is to use an expression to build up the class name for the widget:

    - component: f7-popover
      config:
        class: ="info-pop-" + props.item1

(and don’t forget to change the button action the same way…)

                - component: oh-button
                  config:
                    popoverOpen: =".popover.info-pop-" + props.item1
1 Like

Excellent, without you I would never have got this problem solved. Now it looks like everything is working - great!