Compare slider with payload value

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

[{"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}]

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

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'

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.

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).

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.

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')

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.

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

That can't happen if the join is configured correctly - as I said the join should be returning an object like image

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.

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.

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

2 Likes

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