Any negative number should be zero

Ok, this may be another one of my silly questions.
I'm setting up my pressure transducers, I am using an ads1115 to convert analog to digital, and then sending to esp8266 with I2C bus.
from there query up the message in my node red flows. after a few tweaks and math formula's I have the desired info to display in my gauges.
However, when I have zero psi, sometime the reading puts out a -0.** number.
How would I convert any number that is below zero to just zero.
here is my flow

[{"id":"a65a0e317556cf0b","type":"mqtt in","z":"a34699b03789f7a6","name":"","topic":"tele/tas04/SENSOR","qos":"2","datatype":"json","broker":"31a99116.50a74e","nl":false,"rap":true,"rh":0,"inputs":0,"x":296.0086669921875,"y":863.1128540039062,"wires":[["c7c9c6991b52b664","721fd39e5da13ce8","ba19b1dcf1360792","0a3c36f88f17d3af","f32120c5495d6518"]]},{"id":"c7c9c6991b52b664","type":"debug","z":"a34699b03789f7a6","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":507.5086669921875,"y":862.1128540039062,"wires":[]},{"id":"191bfe030b8ea338","type":"debug","z":"a34699b03789f7a6","name":"sensor1volts","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750.0086669921875,"y":870.1128540039062,"wires":[]},{"id":"721fd39e5da13ce8","type":"change","z":"a34699b03789f7a6","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.ADS1115.A0","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":560.5086669921875,"y":902.6128540039062,"wires":[["e4dc56aec1a3014a"]]},{"id":"f32120c5495d6518","type":"change","z":"a34699b03789f7a6","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.ADS1115.A1","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":570.0086669921875,"y":972.6128540039062,"wires":[["0c29c97451ac86e0"]]},{"id":"0a3c36f88f17d3af","type":"change","z":"a34699b03789f7a6","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.ADS1115.A2","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":560.0086669921875,"y":1042.6128540039062,"wires":[["42125c8bfe939e70"]]},{"id":"ba19b1dcf1360792","type":"change","z":"a34699b03789f7a6","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.ADS1115.A3","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":562.0086669921875,"y":1110.6128540039062,"wires":[["70746f5b2072f82c"]]},{"id":"e4dc56aec1a3014a","type":"function","z":"a34699b03789f7a6","name":"","func":"msg.payload = msg.payload*0.1875/1000\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":740.0086669921875,"y":904.6128540039062,"wires":[["191bfe030b8ea338","78d49e6a641a38be"]]},{"id":"78d49e6a641a38be","type":"function","z":"a34699b03789f7a6","name":"","func":"msg.payload = (msg.payload - 0.5)*30/4\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":942.0086669921875,"y":901.6128540039062,"wires":[["53858aa9b0046f35","09ed183c2dcaa150"]]},{"id":"53858aa9b0046f35","type":"debug","z":"a34699b03789f7a6","name":"sensor1PSI","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":951.5086669921875,"y":864.6128540039062,"wires":[]},{"id":"ba84117ccf35918b","type":"debug","z":"a34699b03789f7a6","name":"sensor2volts","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":749.0086669921875,"y":937.6128540039062,"wires":[]},{"id":"0c29c97451ac86e0","type":"function","z":"a34699b03789f7a6","name":"","func":"msg.payload = msg.payload*0.1875/1000\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":740.0086669921875,"y":972.1128540039062,"wires":[["ba84117ccf35918b","267e129cf6ec496d"]]},{"id":"267e129cf6ec496d","type":"function","z":"a34699b03789f7a6","name":"","func":"msg.payload = (msg.payload - 0.5)*30/4\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":942.0086669921875,"y":973.1128540039062,"wires":[["fc379723ed78ae32","2a194c18ce08b5ec"]]},{"id":"fc379723ed78ae32","type":"debug","z":"a34699b03789f7a6","name":"sensor2PSI","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":950.5086669921875,"y":936.1128540039062,"wires":[]},{"id":"a3772cf8011c3cab","type":"debug","z":"a34699b03789f7a6","name":"sensor3volts","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":751.0086669921875,"y":1006.6128540039062,"wires":[]},{"id":"42125c8bfe939e70","type":"function","z":"a34699b03789f7a6","name":"","func":"msg.payload = msg.payload*0.1875/1000\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":741.0086669921875,"y":1042.1128540039062,"wires":[["a3772cf8011c3cab","ea694e98a16747d9"]]},{"id":"ea694e98a16747d9","type":"function","z":"a34699b03789f7a6","name":"","func":"msg.payload = (msg.payload - 0.5)*30/4\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":941.0086669921875,"y":1043.1128540039062,"wires":[["60d0eb8750c23106","ebdb39734f10d8f9"]]},{"id":"60d0eb8750c23106","type":"debug","z":"a34699b03789f7a6","name":"sensor3PSI","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":952.5086669921875,"y":1007.1128540039062,"wires":[]},{"id":"473e0514a656e60e","type":"debug","z":"a34699b03789f7a6","name":"sensor4volts","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":754.0086669921875,"y":1073.6128540039062,"wires":[]},{"id":"70746f5b2072f82c","type":"function","z":"a34699b03789f7a6","name":"","func":"msg.payload = msg.payload*0.1875/1000\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":742.0086669921875,"y":1110.1128540039062,"wires":[["473e0514a656e60e","de37daa06e0e8d5e"]]},{"id":"de37daa06e0e8d5e","type":"function","z":"a34699b03789f7a6","name":"","func":"msg.payload = (msg.payload - 0.5)*30/4\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":941.0086669921875,"y":1110.1128540039062,"wires":[["dd7525ae30bd2aff","92473a7d3edcc293"]]},{"id":"dd7525ae30bd2aff","type":"debug","z":"a34699b03789f7a6","name":"sensor4PSI","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":953.5086669921875,"y":1074.1128540039062,"wires":[]},{"id":"09ed183c2dcaa150","type":"smooth","z":"a34699b03789f7a6","name":"","property":"payload","action":"mean","count":"10","round":"2","mult":"single","reduce":false,"x":1161.0105285644531,"y":899.9783449172974,"wires":[["1867e0f0a8419c07","08e7b453237355a0"]]},{"id":"1867e0f0a8419c07","type":"debug","z":"a34699b03789f7a6","name":"WestFermenter","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1179.559097290039,"y":860.3672313690186,"wires":[]},{"id":"2a194c18ce08b5ec","type":"smooth","z":"a34699b03789f7a6","name":"","property":"payload","action":"mean","count":"10","round":"2","mult":"single","reduce":false,"x":1164.0086555480957,"y":972.4461622238159,"wires":[["f765f4acb6d54d5d"]]},{"id":"ebdb39734f10d8f9","type":"smooth","z":"a34699b03789f7a6","name":"","property":"payload","action":"mean","count":"10","round":"2","mult":"single","reduce":false,"x":1162.0086975097656,"y":1043.446138381958,"wires":[["6a076f9335fa070d"]]},{"id":"92473a7d3edcc293","type":"smooth","z":"a34699b03789f7a6","name":"","property":"payload","action":"mean","count":"10","round":"2","mult":"single","reduce":false,"x":1159.0086822509766,"y":1110.4461965560913,"wires":[["252bcc67f4f0c2c9"]]},{"id":"f765f4acb6d54d5d","type":"debug","z":"a34699b03789f7a6","name":"CenterFermenter","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1193.0086517333984,"y":934.4461603164673,"wires":[]},{"id":"6a076f9335fa070d","type":"debug","z":"a34699b03789f7a6","name":"EastFermenter","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1182.0086784362793,"y":1004.4461364746094,"wires":[]},{"id":"252bcc67f4f0c2c9","type":"debug","z":"a34699b03789f7a6","name":"Extrainput","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1160.0087356567383,"y":1075.4461936950684,"wires":[]},{"id":"08e7b453237355a0","type":"link out","z":"a34699b03789f7a6","name":"pressuresensor1","mode":"link","links":["9ef4a9cf492199bf"],"x":1356.5643310546875,"y":899.2075058959961,"wires":[]},{"id":"31a99116.50a74e","type":"mqtt-broker","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""}]

Sorry, not looked at your flow, but have you tried "if x <0 then x=0"

so that would be in function node I tried in a change node.
to similarity yes.

So it didn't work in a function node? What was the output?

I dont know how to word it in a function node. I tried to use in a change node.

Try this in a function node.

if (msg.payload < 0) {
  msg.payload = 0;
}
return msg;

Thanks @dynamicdave , however no that didn't work.

Without any knowledge of JavaScript or JSONata:

[{"id":"ae220009b2e0cfc4","type":"change","z":"9141c3fbcc7d9e2b","name":"negative to zero","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":180,"wires":[["f934431aaeb702ef"]]},{"id":"6334d0a60e4bd71a","type":"switch","z":"9141c3fbcc7d9e2b","name":"","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"0","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":510,"y":220,"wires":[["ae220009b2e0cfc4"],["f934431aaeb702ef"]]},{"id":"cf4b38fcaaf92f1a","type":"inject","z":"9141c3fbcc7d9e2b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0.1","payloadType":"num","x":270,"y":200,"wires":[["6334d0a60e4bd71a"]]},{"id":"ba8b239218bec70d","type":"inject","z":"9141c3fbcc7d9e2b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"-0.1","payloadType":"num","x":270,"y":280,"wires":[["6334d0a60e4bd71a"]]},{"id":"f934431aaeb702ef","type":"debug","z":"9141c3fbcc7d9e2b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":870,"y":220,"wires":[]},{"id":"a22a5ec0b0a7ca46","type":"inject","z":"9141c3fbcc7d9e2b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":270,"y":240,"wires":[["6334d0a60e4bd71a"]]}]

Well this works on my version of Node-RED.
Screen Shot 05-13-22 at 07.13 AM

Screen Shot 05-13-22 at 07.14 AM

[{"id":"8276a1d8316d83db","type":"inject","z":"d50b761dea09c168","name":"0","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":190,"y":420,"wires":[["81cf28a4b2cf7853"]]},{"id":"2a116f0bc9c58eef","type":"debug","z":"d50b761dea09c168","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":530,"y":420,"wires":[]},{"id":"81cf28a4b2cf7853","type":"function","z":"d50b761dea09c168","name":"","func":"if (msg.payload < 0) {\n    msg.payload = 0;\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":360,"y":420,"wires":[["2a116f0bc9c58eef"]]},{"id":"46524b8540525c80","type":"inject","z":"d50b761dea09c168","name":"+2","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2","payloadType":"num","x":190,"y":380,"wires":[["81cf28a4b2cf7853"]]},{"id":"9a25d6d10296ecab","type":"inject","z":"d50b761dea09c168","name":"-1","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"-1","payloadType":"num","x":190,"y":460,"wires":[["81cf28a4b2cf7853"]]}]
1 Like

Ah ha! or should I say ah HOtnipi,
I had had tried <= not "<"
thanks!
And yes I try to use the Switch, and change nodes more.
I just did it incorrectly!

Just out of curiosity... in what way didn't it work?

it was still showing a negative number in msg.payload in my debug screen.
maybe i just fat fingered something.

I would be interested to know, if you copy the flow I posted above, whether that works for you?

I honestly don't know what I had done or not done.
But yes it works,
I then copied the node and used directly with my values instead of the inject nodes, and it worked.
but initially when i tried it , it didn't.
And no I haven't had a beer, well I did 6 hours ago.
Thanks,

1 Like

Thanks for letting me know.
I thought (for a moment) I had lost the plot or my touch.

Nope you still have it!
I had just misplaced a couple of my brain cells.
as of now in my flows,
I can turn on water supply (i have float switches to stop at max level)
turn on pumps, monitor all temps in brewhouse and fermenters.
I am controlling my temps of fermenters. Now I can monitor co2 pressure in fermenters. (well i have to wire the rest of them up)
I can use the pressure transducers to calculate my volume in my boil kettle and Hot Liquor Tun,
Next step is to control the co2 supply valve with parameters depending on desired co2 level for carbonating.
I will also be adding Electric Airlock valve. so I can do such remotely.
when I have all my process working correctly , with fail safes.
I plan on learning how to make dashboard work for a Blind person, and or someone with some special needs.
My thoughts anyone should be able to brew beer if they want to. Just need to give them the specialized tools to make it happen.
Cheers.

Here's a picture of the flow working.
I got all the fermenter's wired up today.
I'll be re-wiring the brewhouse next week.

1 Like

I plan on learning how to make dashboard work for a Blind person, and or someone with some special needs.

I'm very interested in how a blind user accessible dashboard will work out.
Presumably it's straightforward to have a text based page
Current stage is Fermenting
West fermenter is 95% full at 37 Farenheit.
Next stage Finings in 36 hours
Etc

But how does one handle interventions/alarms?

I've never used a screen reader, nor one of those talking devices that you buy off a large corporation so they can spy on you more effectively, so I have no idea what current best practice is.

"Ok Sirexa, what's the brewery status?"
"How long till I can start drinking?"

All of Dashboard or just your dashboard?

While I'm not an expert, I may be able to help with some advice. I'm also thinking about accessibility for the new stylesheet and web components that I'm creating for use with (or without) uibuilder.

At least when using Windows or Mac, both have accessibility features that are pretty effective in many cases. But visual and audio accessibility only covers a small part of accessibility in general since you need to think about flexibility in size, colour (color blindness and some brain disorders), fonts (e.g. dyslexic friendly), etc.

Mostly these days, if you write well-formed HTML, any accessibility tools will be able to make sense of it. But fonts, line spacing, size and colour are different matters.

There is a lot of online help. Also worth remembering that, in many countries (certainly the EU and UK), if you make something public, you have a legal responsibility to make it accessible.

I have to say though, looking at the HTML that Dashboard creates, it is quite complex. Though a quick check with Lighthouse suggests a score of 77, not brilliant by any means but better than I'd feared.

I haven't gotten to the planning stages , obviously the most important is to have functional first.
Eye-candy and Ear-candy are the next steps after.
It may be just for the brewing dashboard so a Blind person has aid in brewing.
Obviously they cant do things like clean equipment, however they should be able to create a recipe, and brew a beer. In my honest opinion, blind people have better senses then most, so i think they will blow a non-blind person away when it comes to cooking or beer making.
I have had a customer coming to the taproom for 4 years and didn't have a clue that he was blind. He doesnt know brail either. So this idea is so he can come brew a beer, he liked the idea and said his beer should be called "peekabo", darn near fell out of my barstool!

2 Likes