Logarithmic Scale Gauges

I was delighted to discover that the Value Format within ui_gauge supports simple math functions. For example,

{{value * 2 | number:0}}

renders a gauge with a value label twice that indicated on the gauge.

This was to be useful to me as it would allow for a logarithmic scale on my gauge. A simple function node with:

msg.payload = Math.log10(msg.payload) - 2

is used to give me a logarithmic scale where 100 watts is displayed at gauge-value zero; 1000 watts at 1; and 10,000 at 2.

My problem is that I need to reverse the operation to display the correct value in the label, and the exponentiation operator

{{(10 ** value) | number}}

does not work in this instance; nor does the Math function set.

Clearly what I am attempting is outside the standard use case, but does anyone have any thoughts how I might get this working before I wander over to uibuilder?

You can pass the label value in a different property of the message. So for example you could pass the label value in msg.label and select that in the label field using {{msg.label}}. The help text for the node does mention this.

Thanks Colin... that put me on the right track (and I have marked it as the solution).

The limitation of the solution is that, as far as I can tell, ANY numerical item used in the 'Format Value' field is assumed to be the value used for the gauge itself. So, I could send the Log10 value that I wanted to chart, but as soon as I used a message fragment to represent the original value, the gauge reverts to that value.

My solution was to use the placeholders differently. As per the attached screenshot, I placed the original numerical value in the Label field, and the text Label in the Format Value field.... works for me :slight_smile:

Thanks again

Can you create an example of what did not work please? Use an inject node to inject the failing message to the gauge. Then Export those nodes and paste them here.

[
    {
        "id": "1145c98bd34aece3",
        "type": "ui_gauge",
        "z": "bdd9abd4c7790716",
        "name": "Test 1: Payload",
        "group": "ad2bb8bd68d2ab2f",
        "order": 0,
        "width": 0,
        "height": 0,
        "gtype": "gage",
        "title": "Test 1",
        "label": "units",
        "format": "{{value}}",
        "min": 0,
        "max": "200",
        "colors": [
            "#00b500",
            "#e6e600",
            "#ca3838"
        ],
        "seg1": "",
        "seg2": "",
        "className": "",
        "x": 780,
        "y": 200,
        "wires": []
    },
    {
        "id": "120596d9cf5e7428",
        "type": "inject",
        "z": "bdd9abd4c7790716",
        "name": "Payload: 50 :: Label: 100 :: Random Name: 150",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "label",
                "v": "100",
                "vt": "str"
            },
            {
                "p": "random_name",
                "v": "150",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "50",
        "payloadType": "num",
        "x": 280,
        "y": 200,
        "wires": [
            [
                "1145c98bd34aece3",
                "21c62ed08f1004ab",
                "bdb5ad3b68cea5be"
            ]
        ]
    },
    {
        "id": "21c62ed08f1004ab",
        "type": "ui_gauge",
        "z": "bdd9abd4c7790716",
        "name": "Test 2 : Label",
        "group": "14f372823d194eab",
        "order": 0,
        "width": 0,
        "height": 0,
        "gtype": "gage",
        "title": "Test 2",
        "label": "units",
        "format": "{{label | number}}",
        "min": 0,
        "max": "200",
        "colors": [
            "#00b500",
            "#e6e600",
            "#ca3838"
        ],
        "seg1": "",
        "seg2": "",
        "className": "",
        "x": 780,
        "y": 260,
        "wires": []
    },
    {
        "id": "bdb5ad3b68cea5be",
        "type": "ui_gauge",
        "z": "bdd9abd4c7790716",
        "name": "Test 3: Random Name",
        "group": "14f372823d194eab",
        "order": 0,
        "width": 0,
        "height": 0,
        "gtype": "gage",
        "title": "Test 3",
        "label": "units",
        "format": "{{random_name | number}}",
        "min": 0,
        "max": "200",
        "colors": [
            "#00b500",
            "#e6e600",
            "#ca3838"
        ],
        "seg1": "",
        "seg2": "",
        "className": "",
        "x": 800,
        "y": 320,
        "wires": []
    },
    {
        "id": "24b7654079dbc2b7",
        "type": "comment",
        "z": "bdd9abd4c7790716",
        "name": "Expect gauge and value both = 50 [True]",
        "info": "",
        "x": 1080,
        "y": 200,
        "wires": []
    },
    {
        "id": "da3d630e3c2415fc",
        "type": "comment",
        "z": "bdd9abd4c7790716",
        "name": "Expect gauge = 50 and value = 100 [False]",
        "info": "",
        "x": 1080,
        "y": 260,
        "wires": []
    },
    {
        "id": "5ef092b5912d3bce",
        "type": "comment",
        "z": "bdd9abd4c7790716",
        "name": "Expect gauge = 50 and value = 150 [False]",
        "info": "",
        "x": 1080,
        "y": 320,
        "wires": []
    },
    {
        "id": "ad2bb8bd68d2ab2f",
        "type": "ui_group",
        "name": "Expect gauge and value both = 50 [True]",
        "tab": "d305e69f6f30c68b",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "14f372823d194eab",
        "type": "ui_group",
        "name": "Expect gauge = 50 and value <> 50 [False]",
        "tab": "d305e69f6f30c68b",
        "order": 2,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "d305e69f6f30c68b",
        "type": "ui_tab",
        "name": "Home",
        "icon": "Test",
        "disabled": false,
        "hidden": false
    }
]

Dashboard...

I misinterpreted what you meant by that. You use the word label. The label in the gauge is the text above the gauge, not inside it. So what you have actually done as the solution is exactly what I thought you meant you were trying to do. I should have read your solution more carefully

In fact what you want to do is to use separate values for the gauge and the text inside the gauge. I don't know of a way to do that.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.