Pie widget to display power consumption in my house,

Hello All,

I try to make a widget to display power consumption in my house from several individual Power items.
Ideally, I would like to display this power using a pie chart.

I give a first try looking at the exemples from this thread:

And have pretty good results.

The matter I have is that i want to configure the items to be displayed as parameters of the widget.
For this, I defined a parameter “items” on my widget, of type item, with multiple:true

  parameters:
    - context: item
      description: The value to show
      label: Item
      name: item
      required: true
      multiple: true
      type: TEXT

For the first part of the widget, I use an oh-list with oh-repeater to loop on the items:

   - component: oh-list
     slots:
        default:
          - component: oh-repeater
            config:
              for: i
              in: =props.item
              fragment: true
            slots:
              default:
                - component: oh-label-item
                  config:
                    icon: f7:lightbulb
                    title: = loop.i
                    item: = loop.i

But I don’t see how to do the same for the pie-chart inside the oh-data-series component.

My current code with individual items is :

   - component: oh-chart
     slots:
        series:
          - component: oh-data-series
            config:
              height: 250px
              radius:
                - 70%
                - 90%
              label:
                formatter: "{b}: {c} Watt ({d}%)"
                position: outer
                fontSize: 14
                backgroundColor: "#cfcfff"
                borderColor: "#ffffff"
                borderWidth: 2
                borderRadius: 2
              selectMode: single
              type: pie
              min: = 0
              max: = 100
              data: 
                - value: =items.PAct_PCAdrien.state
                  name: PAct_PCAdrien
                - value: =items.PAct_PCMathias.state
                  name: PAct_PCMathias
                - value: =items.PAct_PCBureau.state
                  name: PAct_PCBureau
                - value: =items.PAct_PCSalon.state
                  name: PAct_PCSalon
              axisLine:
                lineStyle:
                  width: 10

I was hopping using an oh-repeater also there, but not sure if it will work, or if my syntax is just broken.
This current code bellow just display nothing :

data:
- component: oh-repeater
config:
for: i
in: =props.item
fragment: true
slots:
default:
- value: = loop.i.state
name: loop.i

Do you have any advice of how to fix this ?

Best regards,
Laurent.

See here for a partial explanation:

It is possible that you can find a similar solution to the one presented in the post above, but 1) your expression will be slightly more complex, as you have an array of objects instead of just an array of strings and 2) I don’t know if expressions will work at all in this particular instance:

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