OH3 Chart - Is it possible recalculate all values of a persistent item on the fly for a oh-time-series by factor?


im searching for a solution to recalculate each Value of a persistent item for oh-time-series by factor?
For Example I have 2 Power Items - SolarPower and GridPower. Each Item has the correct Value, but combined for comparison in a Chart it would make sense to invert GridPower *-1.0 so that both lines/areas would be on the same Side. (Like Offset Amount but in this case a factor/multiplication)

Is there a possibility to do that without creating new calculated persistent Items (redundancy)?
A second Y-Axis inverted is nearly what i want but then the auto scaling feature can’t be used.

- component: oh-time-series
name: SolarfixPower
gridIndex: 0
xAxisIndex: 0
yAxisIndex: 0
type: line
item: SolarfixPower
opacity: 0.2
backgroundColor: auto
- type: min
name: min
- type: max
name: max
- component: oh-time-series
name: GridPower
gridIndex: 0
xAxisIndex: 0
yAxisIndex: 0
type: line
item: GridPower
factor??: -1.0
opacity: 0.2
backgroundColor: auto

Thank you.

XY problem.
Keep values and apply the factor in your application layer (= rule) or representation layer (= UI).

Thank you for your Help, i am not sure if i understand you correctly.

It was not my intention to “really” recalculate the Values of the persitent Item in the Database.
I just want to invert the values on the fly for the Chart (without saving additionally). Isn’t this representation layer (=UI)?

If i create a new Item (application layer) updated by rule, then I have to persist the new item (wich would be basically old item * -1) → redundancy.

I think that’s what you’ll have to do, manipulate the data record to be charted, to work with standard openHAB tools.
It doesn’t cost very much.

But your question is still about an XY problem. You said you want a solution that does not use additional items for that purpose but that’s a solution, too, and there’s nothing wrong with that.

Thank you very much!

Now i added a new Item:
Number SolarfixPowerNegative “Solarfix Power negative [%.2f W]” (gBalcony, gPersistence) [“Power”]

and a new Rule:
rule “NegativeSolarPower”
Item SolarfixPower changed
SolarfixPowerNegative.postUpdate(((SolarfixPower.state as DecimalType).floatValue * -1))

→ Using this new Item for the chart is working for me now.
It just hurts a little to have the redundancy in the Database :wink:

You don’t have to persist both items :wink:

1 Like

Now that’s confusing me.
The new created rule for the SolarfixPowerNegative is triggered by changes of the SolarfixPower item
→ the SolarfixPowerNegative Item has now values for the period I created the rule until now.
If I don’t persist this item and use it in a chart, for example for the period of a month, where would the Values come from?
I can see the Chart for the new SolarfixPowerNegative Item starts at the time I created the rule.
That is what I expected - the rule is not computed for the chart - its just computed when the SolarfixPower item changes. So it has no values for the past, and it will lose the calculated values when I not persist them.

A’m I missing something? Is there another way to create a computed Item witch is calculated on the fly?

Thanks for your efforts.

He means that if you don’t want to chart the non-negated Item, you don’t have to persist that one, as you said it hurts.

Ah okay - now it’s clear.
Finally I’ll save both Values in this case. Positive Power is technically the “correct” Value, and negative Power is used for the special Chart.
Hopefully in a future Day there will be a smarter Way to handle this with the new Charts.

For Openhab 2.5 i made a custom Widget with Charting Components from Highcharts that I used in HabPanel.
Recalculating the Values for the charts as other features like synchronous zooming, panning, cursor for multiple Charts are features that I miss in Openhab 3 charts for now.
Overall of course Openhab 3 is in many Ways better and I’m excited to see the next new features…

Thank You

There’s nothing stopping you continuing to use that with OH3.

Do you have any new information regarding the chart value divide on the fly?

I have to some how /1000 to show in kwh the shelly