# Compare slider with payload value

**URL:** <https://discourse.nodered.org/t/compare-slider-with-payload-value/22200>\
**Category:** Dashboard\
**Created:** [24 February 2020 14:50 UTC](https://discourse.nodered.org/t/compare-slider-with-payload-value/22200 "2020-02-24T14:50:08Z")\
**Posts on this page:** 14\
**Page:** 2

<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:** [25 February 2020 08:37 UTC](https://discourse.nodered.org/t/compare-slider-with-payload-value/22200/21 "2020-02-25T08:37:15Z")

</div>

It is working fine for me. I have added some presets, and fixed the change node as you had min and max swapped 🙂

```auto
[{"id":"a366426.c95cac","type":"function","z":"a5b7407a.9066e","name":"Parse Sensor Value","func":"let newStr = msg.payload.slice(6, 10);\nmsg.payload = newStr;\nreturn msg;","outputs":1,"noerr":0,"x":520,"y":440,"wires":[["828880d.264bb8"]]},{"id":"9c7bd19f.8a62f","type":"tcp in","z":"a5b7407a.9066e","name":"","server":"client","host":"192.168.150.210","port":"2001","datamode":"stream","datatype":"utf8","newline":"\\r\\n","topic":"","base64":false,"x":510,"y":360,"wires":[["a366426.c95cac"]]},{"id":"828880d.264bb8","type":"function","z":"a5b7407a.9066e","name":"Conert to Decimal","func":"msg.payload = msg.payload.split(' ').map(function(hex){ return parseInt(hex, 16); });\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":500,"wires":[["6efb34c6.45dc5c"]]},{"id":"6efb34c6.45dc5c","type":"function","z":"a5b7407a.9066e","name":"Multiply by Step","func":"msg.payload = msg.payload*0.0001875 \nreturn msg;","outputs":1,"noerr":0,"x":580,"y":560,"wires":[["7d039638.232f78"]]},{"id":"7d039638.232f78","type":"function","z":"a5b7407a.9066e","name":"Convert to millivolts","func":"msg.payload = msg.payload*1000\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":620,"wires":[["409d116.32fa2f"]]},{"id":"409d116.32fa2f","type":"function","z":"a5b7407a.9066e","name":"Convert to Temperature","func":"let newStr = (10.888 - Math.sqrt(Math.pow(-10.888, 2) +4*0.0035*(1777.3-msg.payload)))/(2*-0.00347) + 30;\nnewStr = Math.round(newStr * 10) / 10.0;\nmsg.payload = newStr;\nmsg.topic = \"temperature\";\nreturn [msg,msg];","outputs":2,"noerr":0,"x":670,"y":680,"wires":[["63b98f6f.60368"],["f916afd5.e2f2d"]]},{"id":"63b98f6f.60368","type":"join","z":"a5b7407a.9066e","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":800,"y":820,"wires":[["84a4707a.64616","93c87945.213938"]]},{"id":"f916afd5.e2f2d","type":"ui_gauge","z":"a5b7407a.9066e","name":"","group":"77c3e805.895688","order":0,"width":0,"height":0,"gtype":"gage","title":"Temperature","label":"Degrees C","format":"{{value}}","min":"-50","max":"150","colors":["#00b500","#e6e600","#ca3838"],"seg1":"15","seg2":"25","x":670,"y":740,"wires":[]},{"id":"e6cac6c5.d8af58","type":"ui_slider","z":"a5b7407a.9066e","name":"Max Temp","label":"Max {{value}}°","tooltip":"","group":"77c3e805.895688","order":1,"width":"0","height":"0","passthru":true,"outs":"all","topic":"max_temp","min":"-50","max":"150","step":"1","x":620,"y":800,"wires":[["63b98f6f.60368"]]},{"id":"7d1b631.13d029c","type":"ui_slider","z":"a5b7407a.9066e","name":"Min Temp","label":"Min {{value}}°","tooltip":"","group":"77c3e805.895688","order":2,"width":0,"height":0,"passthru":true,"outs":"all","topic":"min_temp","min":"-50","max":"150","step":"1","x":620,"y":840,"wires":[["63b98f6f.60368"]]},{"id":"84a4707a.64616","type":"debug","z":"a5b7407a.9066e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":990,"y":780,"wires":[]},{"id":"93c87945.213938","type":"switch","z":"a5b7407a.9066e","name":"","property":"payload.temperature","propertyType":"msg","rules":[{"t":"lte","v":"payload.min_temp","vt":"msg"},{"t":"gte","v":"payload.max_temp","vt":"msg"}],"checkall":"true","repair":false,"outputs":2,"x":790,"y":880,"wires":[["37d1d07e.eb33f","4710646d.3fcf1c"],["3c46c821.7585e8","7682852f.bc881c"]]},{"id":"e0051a75.1a0898","type":"inject","z":"a5b7407a.9066e","name":"","topic":"","payload":"50","payloadType":"num","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":370,"y":800,"wires":[["e6cac6c5.d8af58"]]},{"id":"75547d8d.259134","type":"inject","z":"a5b7407a.9066e","name":"","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":370,"y":840,"wires":[["7d1b631.13d029c"]]},{"id":"37d1d07e.eb33f","type":"debug","z":"a5b7407a.9066e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":990,"y":840,"wires":[]},{"id":"3c46c821.7585e8","type":"debug","z":"a5b7407a.9066e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":990,"y":960,"wires":[]},{"id":"4710646d.3fcf1c","type":"ui_toast","z":"a5b7407a.9066e","position":"top right","displayTime":"3","highlight":"","sendall":true,"outputs":0,"ok":"OK","cancel":"","raw":false,"topic":"","name":"Temp too low","x":1000,"y":880,"wires":[]},{"id":"7682852f.bc881c","type":"ui_toast","z":"a5b7407a.9066e","position":"top right","displayTime":"3","highlight":"","sendall":true,"outputs":0,"ok":"OK","cancel":"","raw":false,"topic":"","name":"Temp too high","x":1000,"y":920,"wires":[]},{"id":"77c3e805.895688","type":"ui_group","z":"","name":"Lab 2","tab":"242b7f06.d53a2","disp":true,"width":"6","collapse":false},{"id":"242b7f06.d53a2","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![jaguar](https://avatars.discourse-cdn.com/v4/letter/j/4af34b/32.png) [@jaguar](https://discourse.nodered.org/u/jaguar)\
**Post date:** [25 February 2020 09:04 UTC](https://discourse.nodered.org/t/compare-slider-with-payload-value/22200/22 "2020-02-25T09:04:38Z")

</div>

Thanks dceejay, much appreciated.

Very close but the injects will cause issues as they set the thresholds initially meaning an end user would always have to adjust the sliders at least once evey time the flow starts. But, yes, I agree there is no probably no way around that (no option to just read a slider value).

There's something wrong with the pop up messages, see below

![Message](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/a/ea597bc2feb6326dd74f3f2f59c1b51dbe194743.jpeg)

---

<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:** [25 February 2020 09:13 UTC](https://discourse.nodered.org/t/compare-slider-with-payload-value/22200/23 "2020-02-25T09:13:55Z")

</div>

The notification display the topic (as title) and payload. The payload is currently an object (that we joined together) - and not just a number. You need to add a change node to move the msg.payload.temparature to msg.payload.

If you need to save the min and max over restarts then you need to find out about persistable context - a good write up here - [A guide to understanding 'Persistent Context'](https://discourse.nodered.org/t/a-guide-to-understanding-persistent-context/4115)

---

<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:** [25 February 2020 09:16 UTC](https://discourse.nodered.org/t/compare-slider-with-payload-value/22200/24 "2020-02-25T09:16:44Z")

</div>

Or if you are using MQTT (or plan to) then send them to a Retained topic in MQTT so they will automatically be picked up on restart.

---

<div class="post-metadata">

**Author:** ![jaguar](https://avatars.discourse-cdn.com/v4/letter/j/4af34b/32.png) [@jaguar](https://discourse.nodered.org/u/jaguar)\
**Post date:** [25 February 2020 09:25 UTC](https://discourse.nodered.org/t/compare-slider-with-payload-value/22200/25 "2020-02-25T09:25:31Z")

</div>

Thanks again, but the pop up notifications should be 'Temp too high', 'Temp to low'. I did attemt to change the msg.payload to text but the notification node ignored the change. Perhaps notifications are not the way to go (a shame because the pop up banner concept is ideal).

---

<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:** [25 February 2020 09:39 UTC](https://discourse.nodered.org/t/compare-slider-with-payload-value/22200/26 "2020-02-25T09:39:09Z")

</div>

It's only showing what you are sending it... add a debug node in parallel to it set to show complete message and you will see the parts it is showing (topic and payload)... Us a change node to change them.

---

<div class="post-metadata">

**Author:** ![jaguar](https://avatars.discourse-cdn.com/v4/letter/j/4af34b/32.png) [@jaguar](https://discourse.nodered.org/u/jaguar)\
**Post date:** [25 February 2020 09:47 UTC](https://discourse.nodered.org/t/compare-slider-with-payload-value/22200/27 "2020-02-25T09:47:28Z")

</div>

The issue is that the switch node just outputs the temperature, I need somethinkg like - if the temperature is higher than max-temp then trigger output 1 (and pop message 'Temp too high'), if the temperature is lower than min\_temp then trigger outout 2 (and pop message 'Temp too low')

 ![Switch](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/1/31f4e59eaad4a2c56a79321307f60150cc4de2a8.jpeg)

---

<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:** [25 February 2020 10:14 UTC](https://discourse.nodered.org/t/compare-slider-with-payload-value/22200/28 "2020-02-25T10:14:34Z")

</div>

ell apart from min and max being the wrong way round that is what you have...  
currently you have less than min being output 1 - but no mater...  
then you say " (and pop.." - the and. means you want to change the message - so need a change node. The debug you show is NOT from after the join or switch so is irrelevant at this point - we are past that now.

---

<div class="post-metadata">

**Author:** ![jaguar](https://avatars.discourse-cdn.com/v4/letter/j/4af34b/32.png) [@jaguar](https://discourse.nodered.org/u/jaguar)\
**Post date:** [25 February 2020 10:25 UTC](https://discourse.nodered.org/t/compare-slider-with-payload-value/22200/29 "2020-02-25T10:25:08Z")

</div>

The debug is after the switch, hence my confusion (and with many other aspects of node-red)

 ![Debug](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/f/efcc4cfadc9e3c4046ecc565fded36f95a008030.jpeg)

---

<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:** [25 February 2020 10:34 UTC](https://discourse.nodered.org/t/compare-slider-with-payload-value/22200/30 "2020-02-25T10:34:31Z")

</div>

That can't happen if the join is configured correctly - as I said the join should be returning an object like ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/5/756e5cbc3c345cda399f83ed9fac5f2119b29eea.png)

---

<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:** [25 February 2020 10:37 UTC](https://discourse.nodered.org/t/compare-slider-with-payload-value/22200/31 "2020-02-25T10:37:24Z")

</div>

Are you sure that the debug output you show is from that debug node? Give all your debug nodes names and then you can more easily see where the message comes from.

---

<div class="post-metadata">

**Author:** ![jaguar](https://avatars.discourse-cdn.com/v4/letter/j/4af34b/32.png) [@jaguar](https://discourse.nodered.org/u/jaguar)\
**Post date:** [25 February 2020 10:55 UTC](https://discourse.nodered.org/t/compare-slider-with-payload-value/22200/32 "2020-02-25T10:55:40Z")

</div>

Apologies, I will have to come back to this at a later date as I am out of time for this opportunity.

I am no developer (as I'm sure most people can tell) and thought node-red may offer an easier route to produce a relatively simple monitoring application, apparently not.

Thanks for all your help.

---

<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:** [25 February 2020 12:21 UTC](https://discourse.nodered.org/t/compare-slider-with-payload-value/22200/33 "2020-02-25T12:21:33Z")

</div>

> [@jaguar](#):
>
> hought node-red may offer an easier route

It does, but it still takes a bit of time to grasp the basics.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [26 March 2020 12:21 UTC](https://discourse.nodered.org/t/compare-slider-with-payload-value/22200/34 "2020-03-26T12:21:42Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/compare-slider-with-payload-value/22200.md?page=1)
