hassio-addons / addon-grafana

Grafana - Home Assistant Community Add-ons
https://addons.community
MIT License
223 stars 62 forks source link

Math function does not work #414

Open valimaties opened 3 weeks ago

valimaties commented 3 weeks ago

Problem/Motivation

(Why the issue was filed) image

These are my Gauge controls added in a dashboard. It takes some sensors and display data, for Solar and for consumption. For Solar, in the right part, I have the percentage, which is made by taking the last two queries from the Solar (kWh) Gauge control, where it writes "Injectat" and "Consumat" (which will be translated as "Injected" and "Consummed"). This is the JSON from the second Gauge control (Solar %):

{
  "datasource": {
    "type": "influxdb",
    "uid": "ddj1d8mxd23nkc"
  },
  "description": "",
  "fieldConfig": {
    "defaults": {
      "mappings": [],
      "thresholds": {
        "mode": "absolute",
        "steps": [
          {
            "color": "green",
            "value": null
          }
        ]
      },
      "color": {
        "mode": "thresholds"
      },
      "decimals": 2,
      "fieldMinMax": false
    },
    "overrides": [
      {
        "matcher": {
          "id": "byName",
          "options": "Retea"
        },
        "properties": [
          {
            "id": "unit",
            "value": "percent"
          }
        ]
      },
      {
        "matcher": {
          "id": "byName",
          "options": "Solar"
        },
        "properties": [
          {
            "id": "unit"
          },
          {
            "id": "unit",
            "value": "percent"
          }
        ]
      }
    ]
  },
  "gridPos": {
    "h": 5,
    "w": 6,
    "x": 8,
    "y": 16
  },
  "id": 7,
  "options": {
    "reduceOptions": {
      "values": false,
      "calcs": [
        "lastNotNull"
      ],
      "fields": ""
    },
    "orientation": "auto",
    "showThresholdLabels": false,
    "showThresholdMarkers": true,
    "sizing": "auto",
    "minVizWidth": 75,
    "minVizHeight": 75
  },
  "pluginVersion": "11.0.0",
  "targets": [
    {
      "alias": "Din retea",
      "datasource": {
        "type": "influxdb",
        "uid": "ddj1d8mxd23nkc"
      },
      "groupBy": [
        {
          "params": [
            "$__interval"
          ],
          "type": "time"
        },
        {
          "params": [
            "none"
          ],
          "type": "fill"
        }
      ],
      "hide": true,
      "measurement": "kWh",
      "orderByTime": "ASC",
      "policy": "default",
      "refId": "A",
      "resultFormat": "time_series",
      "select": [
        [
          {
            "params": [
              "value"
            ],
            "type": "field"
          },
          {
            "params": [],
            "type": "last"
          }
        ]
      ],
      "tags": [
        {
          "key": "entity_id::tag",
          "operator": "=",
          "value": "energie_consumata_in_zi_din_retea"
        }
      ]
    },
    {
      "alias": "Din solar",
      "datasource": {
        "type": "influxdb",
        "uid": "ddj1d8mxd23nkc"
      },
      "groupBy": [
        {
          "params": [
            "$__interval"
          ],
          "type": "time"
        },
        {
          "params": [
            "none"
          ],
          "type": "fill"
        }
      ],
      "hide": true,
      "measurement": "kWh",
      "orderByTime": "ASC",
      "policy": "default",
      "refId": "B",
      "resultFormat": "time_series",
      "select": [
        [
          {
            "params": [
              "value"
            ],
            "type": "field"
          },
          {
            "params": [],
            "type": "last"
          }
        ]
      ],
      "tags": [
        {
          "key": "entity_id::tag",
          "operator": "=",
          "value": "energie_consumata_in_zi_din_panouri"
        }
      ]
    },
    {
      "datasource": {
        "name": "Expression",
        "type": "__expr__",
        "uid": "__expr__"
      },
      "expression": "($A / ($A + $B) * 100.00) ",
      "hide": false,
      "refId": "Retea",
      "type": "math"
    },
    {
      "datasource": {
        "name": "Expression",
        "type": "__expr__",
        "uid": "__expr__"
      },
      "expression": "($B / ($A + $B) * 100.00)",
      "hide": false,
      "refId": "Solar",
      "type": "math"
    }
  ],
  "title": "Consum (%)",
  "type": "gauge"
}

However, I've see that even if I have "fill(none)" in my graphic interface, the JSON is displays "fill(null)". (Why?!)

So, in my example, for Solar %, I have 7.41 / 12.83 * 100 = 57.76 , but the Math result is 58.25. The same for the rest of the % values, they are calculate wrong.

Expected behavior

(What you expected to happen)

Actual behavior

(What actually happened) I don't know what is doing, but is not calculates correctly.

Steps to reproduce

(How can someone else make/see it happen)

Proposed changes

(If you have a proposed change, workaround or fix, describe the rationale behind it)

valimaties commented 2 weeks ago

So, no answer, no comment for one week. I'm the only one which uses addon-grafana, or the only one which has this issue? 😒