Bind Group Propertys to Widget

Hi, is there any option to bind a Group to a Widget. For Example you have a Group of RoomSensor with TempActValue, TempSetValue,… i try to bind the hole group to the widget, and pic the props by name.

Widget

uid: Thermostat-Control_Test
tags: []
props:
  parameters:
    - description: Thermostat to control
      label: Description
      name: Title
      required: false
      type: TEXT
    - context: item
      label: Group item
      name: groupItem
      required: true
      type: TEXT
timestamp: Aug 4, 2021, 8:01:20 AM
component: f7-card
config:
  outline: false
  noBorder: false
  padding: true
  noShadow: false
  style:
    --f7-card-margin-horizontal: 5px
    --f7-card-content-padding-vertical: 0px
    --f7-card-content-padding-horizontal: 16px
    --f7-card-border-radius: 15px
    --f7-card-box-shadow: 0px 5px 10px rgba(0,0,0,0.15)
    --f7-card-header-font-size: 14px
    --f7-card-header-font-weight: 600
slots:
  content:
    - component: oh-label-card
      config:
        noShadow: true
        item: =(props.groupItem.Ist)
        title: =(props.Title)
        icon: f7:thermometer
        actionAnalyzerCoordSystem: time
        vertical: false
    - component: oh-stepper-card
      config:
        noShadow: true
        color-theme: gray
        item: =(props.groupItem.Soll)
        large: false
        autorepeat: true
        fill: false
        noBorder: true
        raised: true
        small: true
        round: true
        step: 0.5

Group
image

Page

config:
  label: Raumtemperaturen
  layoutType: responsive
blocks:
  - component: oh-block
    config: {}
    slots:
      default:
        - component: oh-grid-row
          config: {}
          slots:
            default:
              - component: oh-grid-col
                config: {}
                slots:
                  default:
                    - component: widget:Thermostat-Control_Test
                      config:
                        groupItem: gKitchenRoomSensor
masonry: null
grid: []

Yes, there are several examples on the forums of widgets that do something similar (e.g., here). Your trouble is that props.groupItem is just a string variable. It doesn’t include any information about the item you put into the properties dialog, just a string representing the item name. so when you call

item: =props.groupItem

you are passing the value of that string variable to the widget parser and from that string variable, the internal code fetches the information about the item.

This means 2 things:

  1. props.groupItem.Soll isn’t meaningful. String variables don’t have .Soll property or method. (It also wouldn’t be meaningful even if you were using an group item variable as this is not how you would access the members of a group, but that’s another story.)
  2. In fact, you can collect any items you wish on the basis of a single input (whether or not they are part of the same group) as long as you use a consistent base item name (note: not the same as the human readable item label) and string concatenation.

Weather items, as in the example link above, are a very common use for this sort of naming pattern where you have a base name like home_weather and then all the items of interest have an item name that starts with that, such as home_weather_temperature and home_weather_rainfall. Then your widget can refer to each of these items by adding together (concatenating) the base name which you would input in the properties and the extra identifying piece of the name:

item: =props.weatherItems + "_temperature"

and

item: =props.weatherItems + "_rainfall"

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.