Widget with sum of a multiple:true Property

Hi,
i’ve tried to develop a new widget for my photovoltaic installation. I want to sum up the actual power of all strings. I saw that is possible to create a widget property with multiple: true, so i tried to define the property this way and sum up all the selected items in the widget with .map, but it will not work.
Is that possible?
Here is my try to get access to all items through map:

uid: Test
tags: []
props:
  parameters:
    - context: item
      label: Current Power
      name: power_item
      required: false
      type: TEXT
      multiple: true
  parameterGroups: []
timestamp: Jul 12, 2022, 7:31:19 AM
component: f7-card
config:
  style:
    background-color: white
    border-radius: var(--f7-card-expandable-border-radius)
    box-shadow: 5px 5px 10px 1px rgba(0,0,0,0.1)
    height: 120px
    margin-left: 5px
    margin-right: 5px
    noShadow: false
    padding: 0px
slots:
  content:
    - component: f7-block
      config:
        style:
          bottom: -40px
          display: flex
          flex-direction: row
          left: 12px
          position: absolute
      slots:
        default:
          - component: f7-icon
            config:
              f7: drop
              size: 18
              visible: "=props.power_item ? true : false"
          - component: Label
            config:
              style:
                font-size: 12px
                margin-left: 5px
                margin-top: 0px
              text: "=Arrays.stream(props.power_item.map[x | items[x]]).sum()"
              visible: "=props.power_item ? true : false"

I don’t want to create multiple properties and sum them up, because that would not be dynamic enough.

I think you’re going to have to do this by creating an item that contains the summed value and then just displaying that item state. The widget code does not support full JavaScript and some of the more advanced syntax, such as the function in a map method is not supported.

A group that uses the sum aggregate function would be the best way to do this as that is built-in already and would be fully dynamic.

That means, the only usage of the multiple flag for properties is the oh-repeater? That is a real pity. Would be nice to do such things without an extra item :wink:
If i create an extra item, i also have to create a rule to update the item anytime one of the summand get an update or is there another option to keep it up to date?

but of course, thanks for your reply!

See my comment above about just using a group. The group aggregation functions are made exactly for this kind of thing and no rule is required the aggregate group state will be automatically updated.

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