# Gauge - Dynamic min and max

**URL:** https://discourse.nodered.org/t/gauge-dynamic-min-and-max/12132
**Category:** Dashboard
**Created:** [12 June 2019 16:13 UTC](https://discourse.nodered.org/t/gauge-dynamic-min-and-max/12132 "2019-06-12T16:13:56Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Mario](https://avatars.discourse-cdn.com/v4/letter/m/8e7dd6/32.png) [@Mario](https://discourse.nodered.org/u/Mario)
#### Post date: [12 June 2019 16:13 UTC](https://discourse.nodered.org/t/gauge-dynamic-min-and-max/12132/1 "2019-06-12T16:13:56Z")

</div>

Sorry if this is a duplicate entry.

I have a connection to a plc. From a data block I get a min and a max value for a variable. I would now like to pass this to a gauge. Unfortunately, I have not found anything suitable. the values are in the following format:

Min : msg.payload : number  
85

---

<div class="post-metadata">

### Author: ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)
#### Post date: [12 June 2019 16:18 UTC](https://discourse.nodered.org/t/gauge-dynamic-min-and-max/12132/2 "2019-06-12T16:18:59Z")

</div>

Here's the one 😉

> [@How to make variable limits](https://discourse.nodered.org/t/how-to-make-variable-limits/2363):
>
> Hi everyone, i'm trying to make that the gauge varies the max limit (with something like a message property), is this possible?

---

<div class="post-metadata">

### Author: ![Mario](https://avatars.discourse-cdn.com/v4/letter/m/8e7dd6/32.png) [@Mario](https://discourse.nodered.org/u/Mario)
#### Post date: [12 July 2019 07:50 UTC](https://discourse.nodered.org/t/gauge-dynamic-min-and-max/12132/3 "2019-07-12T07:50:12Z")

</div>

Hallo,

that's the second step. At the beginning I would like to summarize the min, max and data value from 3 different variables so that I can pass it as in the example to the gauge. what is necessary for this?

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [12 July 2019 08:04 UTC](https://discourse.nodered.org/t/gauge-dynamic-min-and-max/12132/4 "2019-07-12T08:04:00Z")

</div>

What have you tried?

---

<div class="post-metadata">

### Author: ![Mario](https://avatars.discourse-cdn.com/v4/letter/m/8e7dd6/32.png) [@Mario](https://discourse.nodered.org/u/Mario)
#### Post date: [12 July 2019 09:00 UTC](https://discourse.nodered.org/t/gauge-dynamic-min-and-max/12132/5 "2019-07-12T09:00:29Z")

</div>

I have 3 individual variables which I would like to summarize and then, as in the linked example, to pass the gauge.

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [12 July 2019 09:18 UTC](https://discourse.nodered.org/t/gauge-dynamic-min-and-max/12132/6 "2019-07-12T09:18:40Z")

</div>

That’s restating the question, not explaining what you have tried. It’s easier to suggest things for you to try if you show what you have done. For example it makes it easier to see where the three variables are.

---

<div class="post-metadata">

### Author: ![Mario](https://avatars.discourse-cdn.com/v4/letter/m/8e7dd6/32.png) [@Mario](https://discourse.nodered.org/u/Mario)
#### Post date: [12 July 2019 10:18 UTC](https://discourse.nodered.org/t/gauge-dynamic-min-and-max/12132/7 "2019-07-12T10:18:40Z")

</div>

I would like, as it can be seen in the picture, to summarize 3 values from variables in order to transfer them to the gauge. However, I lack the knowledge of how I could do that. What you see on the picture does not work that way. I just put it together for viewing.

 ![Dynamic%20Gauge](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/7be9d93ec1f71c766575922fa35b2782d10e2503.jpeg)

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [12 July 2019 10:20 UTC](https://discourse.nodered.org/t/gauge-dynamic-min-and-max/12132/8 "2019-07-12T10:20:34Z")

</div>

So add some debug nodes so you can see the data and add one after the join node as well.  
Give them all the debug nodes names so you can see which one is which. Post a screenshot of the debug window here...

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [12 July 2019 10:29 UTC](https://discourse.nodered.org/t/gauge-dynamic-min-and-max/12132/9 "2019-07-12T10:29:29Z")

</div>

Are you trying to show all three values in the same gauge at the same time?

---

<div class="post-metadata">

### Author: ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)
#### Post date: [12 July 2019 10:32 UTC](https://discourse.nodered.org/t/gauge-dynamic-min-and-max/12132/10 "2019-07-12T10:32:32Z")

</div>

Here's my test setup.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/88c7d31d9a7401cd21507eb9e3a0a00ccf81d454.png)

This is what I put in the first function node...

> var max = 50;  
> var min = 20;  
> var data = 30;  
> msg = {payload:data,ui\_control:{min:min,max:max},topic:"Soil"};  
> return msg;

The second function node is the same but with different values for max, min and data.

Hope this works for you.

---

<div class="post-metadata">

### Author: ![Mario](https://avatars.discourse-cdn.com/v4/letter/m/8e7dd6/32.png) [@Mario](https://discourse.nodered.org/u/Mario)
#### Post date: [12 July 2019 11:02 UTC](https://discourse.nodered.org/t/gauge-dynamic-min-and-max/12132/11 "2019-07-12T11:02:19Z")

</div>

Yes, min max and value in the same gauge.

The reason for this is that I do not need a static min and max but a dynamic because the article, which I indicate, changes from time to time.

---

<div class="post-metadata">

### Author: ![Mario](https://avatars.discourse-cdn.com/v4/letter/m/8e7dd6/32.png) [@Mario](https://discourse.nodered.org/u/Mario)
#### Post date: [12 July 2019 11:04 UTC](https://discourse.nodered.org/t/gauge-dynamic-min-and-max/12132/12 "2019-07-12T11:04:56Z")

</div>

That's exactly what I need 75%.

Just the min and max are not static but have to be loaded from a variable.

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [12 July 2019 11:14 UTC](https://discourse.nodered.org/t/gauge-dynamic-min-and-max/12132/13 "2019-07-12T11:14:04Z")

</div>

so look at those debug nodes you should have added by now, and change the variables in the example to be the path to the specific data item

---

<div class="post-metadata">

### Author: ![Mario](https://avatars.discourse-cdn.com/v4/letter/m/8e7dd6/32.png) [@Mario](https://discourse.nodered.org/u/Mario)
#### Post date: [12 July 2019 11:54 UTC](https://discourse.nodered.org/t/gauge-dynamic-min-and-max/12132/14 "2019-07-12T11:54:01Z")

</div>

maybe my written english is so bad ...

i have been trying for several posts to ask which control i need to use to summarize the 3 values. I can not debug anything to show you. but it is e.g. for min = 10 then, for max = 30 and for value = 22 in it.

---

<div class="post-metadata">

### Author: ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)
#### Post date: [12 July 2019 12:04 UTC](https://discourse.nodered.org/t/gauge-dynamic-min-and-max/12132/15 "2019-07-12T12:04:15Z")

</div>

As we still don't know how your values look like and when they arrive, are they coming in at same time, do they come in all together all the time, and stuff like this, then it is kind of complicated to give you strong advise.

For me it seems to be simple case where you just manage incoming data from known source to be stored into flow context and then for gauge just read all variables from flow context.

```auto
var max = flow.get('gaugeMin') || 0;
var min = flow.get('gaugeMax') || 100;
var data = // some numeric data from source 
msg = {payload:data,ui_control:{min:min,max:max},topic:"Soil"};
return msg;

```

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [12 July 2019 12:06 UTC](https://discourse.nodered.org/t/gauge-dynamic-min-and-max/12132/16 "2019-07-12T12:06:51Z")

</div>

But this doesn’t match what you showed in your screenshot earlier.  
Where you have three separate inputs that you are joining using a Join node.  
which is why seeing your flow and the data makes it so much easier to suggest a solution

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [12 July 2019 12:14 UTC](https://discourse.nodered.org/t/gauge-dynamic-min-and-max/12132/17 "2019-07-12T12:14:20Z")

</div>

So where do the min and max come from ... - are they ever reset ? or does the min just keep getting lower and the max higher (based on the incoming data).

Here is a simple example using three sliders and no context.

```auto
[{"id":"f03f3202.91e12","type":"ui_gauge","z":"adc578f5.614308","name":"","group":"cc1b923d.14259","order":1,"width":0,"height":0,"gtype":"gage","title":"gauge","label":"units","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":530,"y":1280,"wires":[]},{"id":"f541a866.024408","type":"function","z":"adc578f5.614308","name":"","func":"\nmsg = {ui_control:{min:msg.payload}};\nreturn msg;\n","outputs":1,"noerr":0,"x":350,"y":1340,"wires":[["f03f3202.91e12"]]},{"id":"4f5ad74c.0c4a18","type":"ui_slider","z":"adc578f5.614308","name":"","label":"data slider","tooltip":"","group":"cc1b923d.14259","order":2,"width":0,"height":0,"passthru":true,"outs":"all","topic":"","min":0,"max":"100","step":1,"x":170,"y":1280,"wires":[["f03f3202.91e12"]]},{"id":"d9ae1c43.b5801","type":"ui_slider","z":"adc578f5.614308","name":"","label":"Min slider","tooltip":"","group":"cc1b923d.14259","order":2,"width":0,"height":0,"passthru":true,"outs":"all","topic":"min","min":0,"max":"40","step":1,"x":160,"y":1340,"wires":[["f541a866.024408"]]},{"id":"6b9aabc0.ddb044","type":"ui_slider","z":"adc578f5.614308","name":"","label":"Max slider","tooltip":"","group":"cc1b923d.14259","order":2,"width":0,"height":0,"passthru":true,"outs":"all","topic":"max","min":"60","max":"100","step":1,"x":170,"y":1380,"wires":[["2a4eb1e2.a022ae"]]},{"id":"2a4eb1e2.a022ae","type":"function","z":"adc578f5.614308","name":"","func":"\nmsg = {ui_control:{max:msg.payload}};\nreturn msg;\n","outputs":1,"noerr":0,"x":350,"y":1380,"wires":[["f03f3202.91e12"]]},{"id":"cc1b923d.14259","type":"ui_group","z":"","name":"Default","tab":"28f4e723.1c8a68","disp":true,"width":"6","collapse":false},{"id":"28f4e723.1c8a68","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

### Author: ![Andres](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andres/32/112_2.png) [@Andres](https://discourse.nodered.org/u/Andres)
#### Post date: [12 July 2019 12:47 UTC](https://discourse.nodered.org/t/gauge-dynamic-min-and-max/12132/18 "2019-07-12T12:47:02Z")

</div>

Si hablás español y crees que te podés expresar mejor en este idioma hay gente en este foro que también lo habla.

For what i've understanded from your question the answer from @hotNipi is the most accurate, you'll receive the three values and you need to store them in context data, the join module will be a headache. When you have all the data you'll generate the joined message and then send it to the gauge node.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [12 July 2019 13:12 UTC](https://discourse.nodered.org/t/gauge-dynamic-min-and-max/12132/19 "2019-07-12T13:12:34Z")

</div>

Well the solution I just posted avoids the join and context entirely so is the minimal implementation and reduces flicker on the gauge during repeated updates...

---

<div class="post-metadata">

### Author: ![Andres](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andres/32/112_2.png) [@Andres](https://discourse.nodered.org/u/Andres)
#### Post date: [12 July 2019 13:15 UTC](https://discourse.nodered.org/t/gauge-dynamic-min-and-max/12132/20 "2019-07-12T13:15:47Z")

</div>

i just run your code, in my opinion that's the best solution, i've learned a thing today. Thanks!

[Next page](https://discourse.nodered.org/t/gauge-dynamic-min-and-max/12132.md?page=2)
