Math on two datasets

I have two data sets dataset_1 and dataset_2 both are configured as persistence rrd4j data.
I would like to visualise a value of a different dataset which is a calculated from those values.
For example
y = dataset_1 *2 + dataset_2

Can someone advice me how to do it?

As far as I know you have two options.

  1. Going forward create a new Item to store the result of the calculation.

  2. Use Grafana for charting. The built in MainUI Charting does not support that sort of manipulation as far as I can tell. However, to use Grafana you’ll need to move to an external database like PostgreSQL or InfluxDB.

I though about creating a rule like that … .but surprisingly it doesn’t work :wink:

uid: derived_value_calculation
label: Calculate Derived Value
configuration: {}
triggers:
  - id: "1"
    configuration:
      itemName: dataset_1
    type: core.ItemStateChangeTrigger
  - id: "2"
    configuration:
      itemName: dataset_2
    type: core.ItemStateChangeTrigger
conditions: []
actions:
  - inputs: {}
    id: "3"
    configuration:
      type: application/javascript
      script: >-
        var dataset1Val = itemRegistry.getItem('dataset_1').getState().intValue();
        var dataset2Val = itemRegistry.getItem('dataset_2').getState().intValue();
        var y = dataset1Val * 2 + dataset2Val;
        events.postUpdate('CalculatedValue', y);
    type: script.ScriptAction

“Doesn’t work” covers nearly an infinity. Doesn’t work how? Throws an error? Doesn’t trigger? Comes up with the wrong value?

I have created the CalulatedValue item, but it remains NULL, even if I trigger the rule manually

Logs?

I used read/write variables wrongly
here’s the working one

configuration: {}
triggers:
  - id: "1"
    configuration:
      itemName: Aqua_reader_ph_current
    type: core.ItemStateChangeTrigger
  - id: "2"
    configuration:
      itemName: Aqua_reader_orp_current
    type: core.ItemStateChangeTrigger
conditions: []
actions:
  - inputs: {}
    id: "3"
    configuration:
      type: application/javascript
      script: |
        var ph = items.getItem('Aqua_reader_ph_current').state;
        var orp = items.getItem('Aqua_reader_orp_current').state;
        var rh = (orp + 205) / 30 + 2 * ph;
        items.getItem(`rH_current`).sendCommand(rh);
    type: script.ScriptAction