openhab-webui icon indicating copy to clipboard operation
openhab-webui copied to clipboard

charts: ability to refer to (persisted) items matching in time in expressions

Open ewaldc opened this issue 1 year ago • 0 comments

The problem

A simple addon (that I developed) publishes 2 channels mapped to items:

  • PVPC_Rate_Now (Number:Energy)
  • PVPC_Is_Rate_Cheap_Now (Switch ON/OFF proxy for boolean)

It's currently impossible to create a simple chart that displays PVPC_Rate_Now with color 'green' when PVPC_Is_Rate_Cheap_Now is true/ON and color 'red' otherwise:

  series:
    - component: oh-time-series
      config:
        name: Rate
        gridIndex: 0
        xAxisIndex: 0
        yAxisIndex: 0
        type: bar
        item:  PVPC_Rate_Now
        color: '= items.PVPC_Is_Rate_Cheap_Now.state  === "ON" ? "Green" : "Red"'
        on: true

does not yield the desired result, since PVPC_Is_Rate_Cheap_Now refers to its current/last state rather than its matching state in time. See community topic

Your suggestion

Extend expressions to be able to refer to a historical item with matching timestamp for use in charts e.g.

color: '=  items.PVPC_Is_Rate_Cheap_Now.matchingState()=== "ON" ? "Green" : "Red"'

where matchingState picks up the timestamp from the current series timestamp/slot.

Your environment

Openhab 4.04 Linux ARM64

Additional info

Happy to contribute a PR, but would appreciate some guideance on what would be an acceptable approach and where to start. Unless of course there is another way to solve this problem.

ewaldc avatar Dec 29 '23 08:12 ewaldc