Behavior of the gauge node

The behavior of the gauge node is a bit strange. I am trying to use the gauge node as shown in the next picture.

afbeelding

Everything goes well, until the value is 0. Then the {{unit}} value doesn't work anymore as expected.

afbeelding

I have tried several options to get the expected behavior, for instance I tried this,

afbeelding

Then I make sure that the value never gets exactly zero. Then it works well as desired, but as you can see, I then get a comma, for values greater then 999. This I also don't like to see.

afbeelding

What is the correct solution for the desired presentation?

What version of Node-red and the dashboard do you have? I have 3.0.2 / 3.3.1
I see {{units}} before any message is sent to the gauge, unlike topic, which is blank.
This seems to be a bug.

But if I send payload 0 the gauge seems to work fine without the number: 0 addition.

The comma formatting comes from the Node-red server's Locale setting. Not sure how easy or desirable it is to change that for Node-red.

@jbudd I have following versions:
afbeelding

As far as I can tell, the topic is working fine. I can understand, when no message is send, that {{unit}}, will appear.

With me sending zero, after I while ??? {{unit}} will appear.

This is not the case, when you don't set the number addition after value.
afbeelding

We seem to have the same versions but the units display works differently.
Does your data come from Influx? Is it the same if you simply use an inject node?

True. The formatting according to locale only happens if you use eg | number: 0
From the gauge help text:

The msg.payload is searched for a numeric value and is formatted in accordance with the defined Value Format, which can then be formatted using Angular filters.

For example : {{value | number:1}}% will round the value to one decimal place and append a % sign.

Hereby an example flow,

[{"id":"695aa1b525b64598","type":"ui_gauge","z":"7c6ad896ba8a384a","name":"No format","group":"57423d36f7b8b4a1","order":2,"width":4,"height":4,"gtype":"gage","title":"{{topic}}","label":"{{unit}}","format":"{{value}}","min":0,"max":"2000","colors":["#00b33c","#00b33c","#00b33c"],"seg1":"","seg2":"","diff":false,"className":"","x":400,"y":680,"wires":[]},{"id":"b81a0eb36ae1a20e","type":"function","z":"7c6ad896ba8a384a","name":"zero","func":"let val = parseInt(0.01234);\nmsg = {topic: \"no format\", payload: val, unit: \"Watt\"};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":230,"y":680,"wires":[["695aa1b525b64598"]]},{"id":"f252698beb443440","type":"inject","z":"7c6ad896ba8a384a","name":"1 sec","props":[],"repeat":"1","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":90,"y":720,"wires":[["b81a0eb36ae1a20e","6c7ae78586f7b3d8","e570b23fc930d9a2"]]},{"id":"6c7ae78586f7b3d8","type":"function","z":"7c6ad896ba8a384a","name":"zero","func":"let val = 0;\nmsg = { topic: \"+ format\", payload: val, unit: \"Watt\"};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":230,"y":760,"wires":[["73ddc6a4cf3252ec"]]},{"id":"73ddc6a4cf3252ec","type":"ui_gauge","z":"7c6ad896ba8a384a","name":"+ format","group":"57423d36f7b8b4a1","order":11,"width":4,"height":4,"gtype":"gage","title":"{{topic}}","label":"{{unit}}","format":"{{value | number: 0}}","min":0,"max":"2000","colors":["#00b33c","#00b33c","#00b33c"],"seg1":"","seg2":"","diff":false,"className":"","x":400,"y":760,"wires":[]},{"id":"e570b23fc930d9a2","type":"function","z":"7c6ad896ba8a384a","name":"1234","func":"let val = 1234;\nmsg = { topic: \"+ format\", payload: val, unit: \"Watt\"};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":230,"y":800,"wires":[["0fc5d257d4bc41fd"]]},{"id":"bf69885e49afe793","type":"inject","z":"7c6ad896ba8a384a","name":"test","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":150,"y":600,"wires":[["8d85b5bf24ffc667"]]},{"id":"8d85b5bf24ffc667","type":"function","z":"7c6ad896ba8a384a","name":"1234","func":"let val = 1234;\nmsg = {topic: \"no format\", payload: val, unit: \"Watt\"};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":290,"y":600,"wires":[["695aa1b525b64598"]]},{"id":"0fc5d257d4bc41fd","type":"ui_gauge","z":"7c6ad896ba8a384a","name":"+ format","group":"57423d36f7b8b4a1","order":10,"width":4,"height":4,"gtype":"gage","title":"{{topic}}","label":"{{unit}}","format":"{{value | number: 0}}","min":0,"max":"2000","colors":["#00b33c","#00b33c","#00b33c"],"seg1":"","seg2":"","diff":false,"className":"","x":400,"y":800,"wires":[]},{"id":"57423d36f7b8b4a1","type":"ui_group","name":"test","tab":"ad12ad91.ab672","order":1,"disp":true,"width":"8","collapse":false,"className":""},{"id":"ad12ad91.ab672","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

If you restart your flows, you can clearly see the behavior.

The gauge with no format, will show {{units}}, as you inject one time 1234 it will then show Watt (for a while ????).. The gauge with format and value 0, with keep on showing {{unit}}.

The topic will keep on showing always, no problem.

As I said before:

But if I send payload 0 the gauge seems to work fine

@jbudd Have you tried restart flows or refresh the page in your web browser?

If I keep on testing, it seems more or less random, one time it seems ok, next time I see {{unit}}
afbeelding

I agree, when I refresh the browser page, it shows {{unit}}
Sending

{
"payload":0,
"topic":"no format",
"unit":"Watt"
}

does not set the units to "Watt".

I can't explain this behaviour.
A simple flow to reproduce (reload browser is essential after deploy)

[{"id":"695aa1b525b64598","type":"ui_gauge","z":"18302aaec057c898","name":"No format","group":"57423d36f7b8b4a1","order":2,"width":4,"height":4,"gtype":"gage","title":"{{topic}}","label":"{{unit}}","format":"{{value}}","min":0,"max":"2000","colors":["#00b33c","#00b33c","#00b33c"],"seg1":"","seg2":"","diff":false,"className":"","x":620,"y":160,"wires":[]},{"id":"b81a0eb36ae1a20e","type":"function","z":"18302aaec057c898","name":"zero","func":"let val = parseInt(0.01234);\n\nmsg.topic = \"no format\"\nmsg.payload = val\nmsg.unit = \"Watt\"\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":350,"y":200,"wires":[["695aa1b525b64598","4ff77ba00d0b4cf0","8de0e0ad0e807578","8b9965a2473bcd91"]]},{"id":"83a338edf7ecfeb6","type":"ui_button","z":"18302aaec057c898","name":"","group":"57423d36f7b8b4a1","order":2,"width":"3","height":"1","passthru":false,"label":"Send 0","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"","payloadType":"str","topic":"topic","topicType":"msg","x":200,"y":200,"wires":[["b81a0eb36ae1a20e"]]},{"id":"4ff77ba00d0b4cf0","type":"ui_text","z":"18302aaec057c898","group":"57423d36f7b8b4a1","order":0,"width":"3","height":"1","name":"","label":"Topic","format":"{{topic}}","layout":"row-spread","className":"","x":610,"y":200,"wires":[]},{"id":"8de0e0ad0e807578","type":"ui_text","z":"18302aaec057c898","group":"57423d36f7b8b4a1","order":0,"width":"3","height":"1","name":"","label":"Payload","format":"{{payload}}","layout":"row-spread","className":"","x":620,"y":240,"wires":[]},{"id":"8b9965a2473bcd91","type":"ui_text","z":"18302aaec057c898","group":"57423d36f7b8b4a1","order":0,"width":"3","height":"1","name":"","label":"Unit","format":"{{unit}}","layout":"row-spread","className":"","x":610,"y":280,"wires":[]},{"id":"57423d36f7b8b4a1","type":"ui_group","name":"test","tab":"ad12ad91.ab672","order":1,"disp":true,"width":"8","collapse":false,"className":""},{"id":"ad12ad91.ab672","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

@jbudd I am trying to make a universal control to all the gauge nodes, where not only the these parameters but also min max. are send to the node.

By the way, what did I do wrong when sending my flow on this page, it took a lot of space, while yours only takes 1 line space?

When you copy the code, go to the JSON tab and click "Compact" rather than "Formatted".
Should be the default IMHO.

@jbudd Ok, yes, I see that now. :slight_smile:

Here how it seems work when sending msg.payload, msg.topic and msg.unit AND have defined the node like this:
Screenshot 2023-01-23 at 6.54.25 AM
or this:
Screenshot 2023-01-23 at 6.54.44 AM
Note {{value}} and {{payload}} are interchangeable in this situation

  1. if the Value changes, the Label AND the unit will change
  2. if the Value DOES NOT change but the label does, the LABEL will change BUT the unit will not
  3. if the Value AND the Label change, the units will change.
1 Like

Know that you also can have fallback (default value) when using angular filters. So you can make flows a bit simpler by not covering all the corners what it takes to successfully initialize all the components and keep things in sync with server side.

{{unit || "Watt"}}

2 Likes

Waaaaay ahead of you :slight_smile:

Ok, so not default but next version will remember your choice. :+1:

4 Likes

Excellent, thanks for that.

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