OH4 chart: change color of item in series based on value of another (persisted) item matching in time

  • Platform information:

    • openHAB version: 4.04
  • Issue
    I have developed an addon for PVPC (Spanish electricity market for small consumers). The add-on publishes, amongst other things, three channels mapped to items:

  • Spanish_Electricity_Market_PVPC_Rate_API_Thing_PVPC_Rate_Now (Number:Energy)

  • Spanish_Electricity_Market_PVPC_Rate_API_Thing_PVPC_Is_Rate_Cheap_Now (Switch ON/OFF)

  • Spanish_Electricity_Market_PVPC_Rate_API_Thing_PVPC_Is_Rate_Below_Average_Now (Switch ON/OFF)

From this data I would like to create a bar graph of the PVPC_Rate_Now whereby the color is green when Is_Rate_Cheap_Now is true (ON), orange when Is_Rate_Below_Average_Now is true and red otherwise. In a first step to differentiate between cheap rates and “other” rates, I came up with:

  label: PVPC Daily Chart
  period: D
    - component: oh-chart-grid
      config: {}
    - component: oh-time-axis
        gridIndex: 0
    - component: oh-value-axis
        gridIndex: 0
        name: Price (KWh)
    - component: oh-time-series
        name: Rate
        gridIndex: 0
        xAxisIndex: 0
        yAxisIndex: 0
        type: bar
        item: Spanish_Electricity_Market_PVPC_Rate_API_Thing_PVPC_Rate_Now
        color: '=
          === "ON" ? "Green" : "Red"'
        on: true

But it does not yield the desired outcome: the color does vary, but is determined by the last/current state of PVPC_Is_Rate_Cheap_Now and not by the corresponding Is_Rate_Cheap_Now value matching with the PVPC_Rate_Now at the given hour. I have tried adding PVPC_Is_Rate_Cheap_Now as a (hidden) series itself, but it also does not help. Somehow I need to refer to the Is_Rate_Cheap_Now which corresponds to the matching (historical) hourly rate, but haven’t found the proper syntax. I also read the Apache Echarts docs but the examples always contain static data. All hints appreciated…

The items.Spanish_Electricity_Market_PVPC_Rate_API_Thing_PVPC_Is_Rate_Cheap_Now.state variable points to most recent state of that item. It is not persisted state of that item at given point of time. While echarts might have corresponding option/decorator function support I think OH charts will miss necessary mapping to do such.

Yes, that is the problem. The question is: how to refer to the corresponding persisted state ? The data is there because I can add Spanish_Electricity_Market_PVPC_Rate_API_Thing_PVPC_Is_Rate_Cheap_Now as a (second) series (and optionally hide it visually). Any other solution that achieves the desired goal is fine…

You can’t refer past state, as I wrote above this is not supported ATM. You can look at feature requests reported for OH mainui or fill new one.

Ah OK, got it. That’s a pity since it’s quite a basic/simple use case. I’ll will file an enhancement request and see if I can code a workaround and post a PR. Maybe some extension function for items like, .historicState(). Any hints of where to start are appreciated.
Enhancement Request