# Gauge value toggles between zero and value

**URL:** <https://discourse.nodered.org/t/gauge-value-toggles-between-zero-and-value/65219>\
**Category:** Share Your Nodes\
**Created:** [17 July 2022 14:37 UTC](https://discourse.nodered.org/t/gauge-value-toggles-between-zero-and-value/65219 "2022-07-17T14:37:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alfschuster](https://avatars.discourse-cdn.com/v4/letter/a/9de053/32.png) [@alfschuster](https://discourse.nodered.org/u/alfschuster)\
**Post date:** [17 July 2022 14:37 UTC](https://discourse.nodered.org/t/gauge-value-toggles-between-zero-and-value/65219/1 "2022-07-17T14:37:14Z")

</div>

High,  
my problem is following:  
Sending several JSON data packages from my ESP32 to my node-red  
frontend following happens:

Within the third package I sent UV-level values and decode  
it with a function node:

var ESP\_ADCha1 = { payload: msg.payload.adcval1 };  
var ESP\_UVSens = { payload: msg.payload.UV\_Sensor };  
var ESP\_5V = { payload: msg.payload.ESP\_5Volt };  
return [ESP\_ADCha1, ESP\_UVSens, ESP\_5V];

I visualize the above data by means of three gauges.  
This works fine.

In order to 'amplify' the UV-sensor data by factor 2  
I simply multiplied the origin data value with 2, see example:

var ESP\_ADCha1 = { payload: msg.payload.adcval1 };  
var ESP\_UVSens = { payload: msg.payload.UV\_Sensor \* 2 };  
var ESP\_5V = { payload: msg.payload.ESP\_5Volt };  
return [ESP\_ADCha1, ESP\_UVSens, ESP\_5V];

Visualizing the output on the gauge I see that the gauge  
toggles between 0 and the multiplied value. I expected  
a constant output.  
What must I do?

Of course I could adapt the value inside the ESP32 but I prefer to  
manipolate it inside node-red.  
Thanks, Alf

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 July 2022 16:23 UTC](https://discourse.nodered.org/t/gauge-value-toggles-between-zero-and-value/65219/2 "2022-07-17T16:23:10Z")

</div>

Is it possible that `msg.payload.UV_Sensor` is a string rather than a number (feed the message into a debug node to check. That would prevent the `*2` from working. Though I would not expect it to toggle, unless the incoming value is not consistent.

Add a debug node configured to show `msg.payload.UV_Sensor` and check that the values are consistent and are numbers.

---

<div class="post-metadata">

**Author:** ![alfschuster](https://avatars.discourse-cdn.com/v4/letter/a/9de053/32.png) [@alfschuster](https://discourse.nodered.org/u/alfschuster)\
**Post date:** [17 July 2022 17:02 UTC](https://discourse.nodered.org/t/gauge-value-toggles-between-zero-and-value/65219/3 "2022-07-17T17:02:02Z")

</div>

Hi Colin,  
to me it is a value, because the function multiplies the origin value without problems, I checked that..  
It seems, that as soon as the other data packages are received (packages 1,2,4) the UV-sensor values from data package 3 are not available and the gauge shows zero...  
NOT doing the multiplication, leaving the payload as it comes from the ESP32, the display is consistant and shows the origin value.  
Alf

---

<div class="post-metadata">

**Author:** ![alfschuster](https://avatars.discourse-cdn.com/v4/letter/a/9de053/32.png) [@alfschuster](https://discourse.nodered.org/u/alfschuster)\
**Post date:** [17 July 2022 17:05 UTC](https://discourse.nodered.org/t/gauge-value-toggles-between-zero-and-value/65219/4 "2022-07-17T17:05:38Z")

</div>

Uploading: wg. node-red problem\_1.jpg...  
here's a sreenshot...

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [17 July 2022 17:24 UTC](https://discourse.nodered.org/t/gauge-value-toggles-between-zero-and-value/65219/5 "2022-07-17T17:24:22Z")

</div>

You will need to check that the value is set, i would try something like this, I leave the original object as is then pass the object through a switch node, checking that the property key of payload exists.

```auto
[{"id":"7cb49ed1.f23d58","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"($random()*1 )> 0.2 ?\t{\"adcval1\":1,\"UV_Sensor\":2.2,\"ESP_5Volt\":3} :\t{\"adcval1\":1,\"ESP_5Volt\":3}","payloadType":"jsonata","x":270,"y":840,"wires":[["91d4624e.05c058","353dd9db.a0d64e"]]},{"id":"91d4624e.05c058","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":510,"y":780,"wires":[]},{"id":"353dd9db.a0d64e","type":"switch","z":"bf9e1e33.030598","name":"","property":"payload","propertyType":"msg","rules":[{"t":"hask","v":"UV_Sensor","vt":"str"},{"t":"hask","v":"ESP_5Volt","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":440,"y":840,"wires":[["394a1d81.04daca"],["8e911d52.4f08e8"]]},{"id":"394a1d81.04daca","type":"function","z":"bf9e1e33.030598","name":"","func":"msg.payload.UV_Sensor *= 2;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":590,"y":820,"wires":[["cf18ded0.86cc18","91d4624e.05c058"]]},{"id":"8e911d52.4f08e8","type":"ui_gauge","z":"bf9e1e33.030598","name":"","group":"8b5cde76.edd58","order":2,"width":0,"height":0,"gtype":"gage","title":"esp","label":"units","format":"{{msg.payload.ESP_5Volt | number }}","min":0,"max":10,"colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","className":"","x":750,"y":840,"wires":[]},{"id":"cf18ded0.86cc18","type":"ui_gauge","z":"bf9e1e33.030598","name":"","group":"8b5cde76.edd58","order":2,"width":0,"height":0,"gtype":"gage","title":"uv","label":"units","format":"{{msg.payload.UV_Sensor | number }}","min":0,"max":10,"colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","className":"","x":750,"y":800,"wires":[]},{"id":"8b5cde76.edd58","type":"ui_group","name":"default","tab":"8f03e639.85956","order":1,"disp":false,"width":"12","collapse":false},{"id":"8f03e639.85956","type":"ui_tab","name":"Home","icon":"dashboard","order":2,"disabled":false,"hidden":false}]

```

The inject produces an object that randomly is missing the sensor key.  
[edit] added correct function.
