[Widget] Pass persistence service as property to custom widget

Hello folks, been reading here since years and always found the solution in some posts.

To all frequent posters, thank you very much for all the time you spend here to answer questions!

Now to my first question that I haven’t found answered already:
I’m running on 3.4.2 and try to pass the “service” parameter of an “oh-time-series” as parameter in a custom widget.

I tried as “text” property and passed jdbc or rrd4j but it doesnt show a graph at all.
And I tried a BOOLEAN parameter with

service: =(props.UseSql)?'jdbc':'rrd4j'

but doesn’t show a graph neither.
When I enter the service directly e.g. service: jdbc or even service: “jdbc” it works as expected.

Something seems to be wrong with the datatype, but the docs tell me its text:
https://www.openhab.org/docs/ui/components/oh-time-series.html#service

I’m clueless…

Thank you and kind regards,
Jan

I’ve absolutely no experience with timeseries widgets, but I do know that “Sql” is not a valid persistence service and everywhere else I’ve used the service name it requires all lower case.

Did you try =(props.UseSql) ? 'jdbc' : 'rrd4j'?

Damn, thank you for your answer and sorry that was a copy pasta from wrong place…
Yes, I tried with jdbc and rrd4j.
I edit it in my original post.

There are still a few properties for the chart widgets that are not actually processed by the expression parser. It seems that service is one of those.

Unfortunately, that means that your best course of action is to file a feature request in the UI repo to get this changed.

I don’t to a lot with custom code for charts, but as a workaround you can probably have two different time series components, each configured with one of the services and then only display one series or the other depending on the value of the useSql parameter.

Thank you for clarification.

oh-time-series seems to ignore the visible parameter, but it worked as you suggested with the complete oh-chart.

Put 2 oh-charts in my card…

Code here, maybe this helps someone...
uid: SingleGraph
tags: []
props:
  parameters:
    - description: Kurvenname
      label: Kurvenname
      name: Kurvenname
      required: false
      type: TEXT
    - description: Einheit
      label: Einheit
      name: Einheit
      required: false
      type: TEXT
    - context: item
      description: An item to control
      label: Item
      name: item
      required: false
      type: TEXT
    - description: UseSql
      label: UseSql
      name: UseSql
      required: false
      type: BOOLEAN
  parameterGroups: []
timestamp: Apr 17, 2023, 11:40:59 PM
component: f7-card
slots:
  default:
    - component: oh-chart
      config:
        chartType: ""
        period: D
        visible: =(props.UseSql)?false:true
      slots:
        grid:
          - component: oh-chart-grid
            config:
              includeLabels: true
        xAxis:
          - component: oh-time-axis
            config:
              gridIndex: 0
        yAxis:
          - component: oh-value-axis
            config:
              gridIndex: 0
        series:
          - component: oh-time-series
            config:
              name: =props.Kurvenname + " in " + props.Einheit + " (RRD4J)"
              gridIndex: 0
              xAxisIndex: 0
              yAxisIndex: 0
              type: line
              item: =(props.item)
              service: rrd4j
        tooltip:
          - component: oh-chart-tooltip
            config:
              confine: true
              smartFormatter: true
        legend:
          - component: oh-chart-legend
            config:
              bottom: 3
              type: scroll
        dataZoom:
          - component: oh-chart-datazoom
            config:
              type: inside
    - component: oh-chart
      config:
        chartType: ""
        period: D
        visible: =(props.UseSql)?true:false
      slots:
        grid:
          - component: oh-chart-grid
            config:
              includeLabels: true
        xAxis:
          - component: oh-time-axis
            config:
              gridIndex: 0
        yAxis:
          - component: oh-value-axis
            config:
              gridIndex: 0
        series:
          - component: oh-time-series
            config:
              name: =props.Kurvenname + " in " + props.Einheit + " (Sql)"
              gridIndex: 0
              xAxisIndex: 0
              yAxisIndex: 0
              type: line
              item: =(props.item)
              service: jdbc
        tooltip:
          - component: oh-chart-tooltip
            config:
              confine: true
              smartFormatter: true
        legend:
          - component: oh-chart-legend
            config:
              bottom: 3
              type: scroll
        dataZoom:
          - component: oh-chart-datazoom
            config:
              type: inside

@Gehetzter would you mind creating a git issue about service not being processed by the expression parser so it’s not forgotten, I (or someone else) might fix it. Thx.

1 Like

PR was merged so in latest OH 4 snapshots this should work:

service: =props.useInflux ? "influxdb":"rrd4j"