Help with a water sensor flow

Hi all,

Could I ask for some advice on my current project flow.. Any help appreciated

This flow gets pulses from a water flow sensor and sends a pulse every litre pumped into a tank from a bore and displays them.

The problem is.. it resets the litres per minute every minute.. I need to keep the last figure at the meter so the meter doesnt go back to zero

I have attached the flow if anybody would like to lend a hand :wink:

[{"id":"f23df1e6.9c42","type":"tab","label":"Pump","disabled":false,"info":""},{"id":"eb9c75a3.d04ce8","type":"ui_led","z":"f23df1e6.9c42","order":7,"group":"38b90348.e0a34c","width":0,"height":0,"label":"Tank Full","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#808080","value":"ON","valueType":"str"},{"color":"#008000","value":"OFF","valueType":"str"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"","x":990,"y":60,"wires":[]},{"id":"3782b1aa.66dece","type":"mqtt out","z":"f23df1e6.9c42","name":"Pump Sonoff","topic":"cmnd/sonoffpump/power","qos":"","retain":"","broker":"df293a6.4c3c8c8","x":1470,"y":160,"wires":[]},{"id":"d4cbfe34.4aebd","type":"change","z":"f23df1e6.9c42","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":100,"wires":[["eb9c75a3.d04ce8","3a854b3e.4cd6c4","fb678276.4d4b1"]]},{"id":"c712f563.520d88","type":"change","z":"f23df1e6.9c42","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":140,"wires":[["eb9c75a3.d04ce8","3a854b3e.4cd6c4","8ef7ed7d.b47f9","fb678276.4d4b1"]]},{"id":"9f5af519.689428","type":"mqtt in","z":"f23df1e6.9c42","name":"","topic":"pumpsensor/INFO1","qos":"2","datatype":"auto","broker":"df293a6.4c3c8c8","x":150,"y":340,"wires":[["8a679f08.aabd","32365ed3.8ea722"]]},{"id":"e5720b7a.8edbf8","type":"mqtt out","z":"f23df1e6.9c42","name":"","topic":"pumpsensor/cmnd/STATUS","qos":"","retain":"","broker":"df293a6.4c3c8c8","x":900,"y":340,"wires":[]},{"id":"eb0f0122.6475d","type":"mqtt in","z":"f23df1e6.9c42","name":"","topic":"pumpsensor/STATUS10","qos":"2","datatype":"auto","broker":"df293a6.4c3c8c8","x":120,"y":120,"wires":[["15d99838.af6f38"]]},{"id":"8a679f08.aabd","type":"change","z":"f23df1e6.9c42","name":"Change to 10","rules":[{"t":"set","p":"payload","pt":"msg","to":"10","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":340,"wires":[["e5720b7a.8edbf8"]]},{"id":"4517a249.b9023c","type":"switch","z":"f23df1e6.9c42","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"OFF","vt":"str"},{"t":"cont","v":"ON","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":430,"y":120,"wires":[["c712f563.520d88"],["d4cbfe34.4aebd"]]},{"id":"fb5a8a68.5a4678","type":"exec","z":"f23df1e6.9c42","command":"tail ","addpay":true,"append":"-n 8","useSpawn":"true","timer":"","oldrc":false,"name":"","x":550,"y":400,"wires":[["69e19668.d32c28"],[],[]]},{"id":"a6a5b432.2ae058","type":"watch","z":"f23df1e6.9c42","name":"","files":"/var/log/pumplog","recursive":"","x":380,"y":400,"wires":[["fb5a8a68.5a4678"]]},{"id":"69e19668.d32c28","type":"ui_template","z":"f23df1e6.9c42","group":"38b90348.e0a34c","name":"Pump Log","order":1,"width":5,"height":4,"format":"<div ng-bind-html=\"msg.payload\"></div>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","x":730,"y":400,"wires":[[]]},{"id":"9898cab0.2085c8","type":"ui_led","z":"f23df1e6.9c42","order":6,"group":"38b90348.e0a34c","width":0,"height":0,"label":"Bore Pump On","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#808080","value":"{\"POWER\":\"OFF\"}","valueType":"str"},{"color":"#008000","value":"{\"POWER\":\"ON\"}","valueType":"str"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"","x":390,"y":520,"wires":[]},{"id":"7d0e3ee.4bbe7c","type":"mqtt in","z":"f23df1e6.9c42","name":"Pump Power status","topic":"stat/sonoffpump/RESULT","qos":"2","datatype":"auto","broker":"df293a6.4c3c8c8","x":150,"y":460,"wires":[["9898cab0.2085c8","b414503a.52694"]]},{"id":"48868bb0.555404","type":"file","z":"f23df1e6.9c42","name":"","filename":"/var/log/pumplog","appendNewline":true,"createDir":false,"overwriteFile":"false","encoding":"ascii","x":980,"y":460,"wires":[[]]},{"id":"16515d6d.9da943","type":"change","z":"f23df1e6.9c42","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"{\"POWER\":\"ON\"}","fromt":"str","to":"PUMP ON<br>","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"{\"POWER\":\"OFF\"}","fromt":"str","to":"PUMP OFF<br>","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":460,"wires":[["632c4383.6f136c"]]},{"id":"b414503a.52694","type":"simpletime","z":"f23df1e6.9c42","name":"","mydate":false,"myymd":false,"myyear":false,"mymonth":false,"mymonthn":false,"mydom":false,"mydoy":false,"myday":false,"myhourpm":false,"myhour":false,"mytime":false,"mytimes":true,"myminute":false,"myminutes":false,"mysecond":false,"mymillis":false,"myepoch":false,"myrawdate":false,"mypm":false,"x":390,"y":460,"wires":[["16515d6d.9da943"]]},{"id":"632c4383.6f136c","type":"function","z":"f23df1e6.9c42","name":"","func":"msg.payload = msg.mytimes +' - ' + msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":750,"y":460,"wires":[["48868bb0.555404"]]},{"id":"32365ed3.8ea722","type":"change","z":"f23df1e6.9c42","name":"Send restart to log","rules":[{"t":"set","p":"payload","pt":"msg","to":"SENSOR RESTART <br>","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":150,"y":400,"wires":[["b414503a.52694"]]},{"id":"83a5a9b.4aac658","type":"file","z":"f23df1e6.9c42","name":"","filename":"/var/log/pumplog","appendNewline":true,"createDir":false,"overwriteFile":"false","encoding":"ascii","x":1580,"y":300,"wires":[[]]},{"id":"4aa8853a.8f9cec","type":"simpletime","z":"f23df1e6.9c42","name":"","mydate":false,"myymd":false,"myyear":false,"mymonth":false,"mymonthn":false,"mydom":false,"mydoy":false,"myday":false,"myhourpm":false,"myhour":false,"mytime":false,"mytimes":true,"myminute":false,"myminutes":false,"mysecond":false,"mymillis":false,"myepoch":false,"myrawdate":false,"mypm":false,"x":1250,"y":300,"wires":[["4a4b3bbd.ee7aa4"]]},{"id":"4a4b3bbd.ee7aa4","type":"function","z":"f23df1e6.9c42","name":"","func":"msg.payload = msg.mytimes +' - ' + msg.payload;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1400,"y":300,"wires":[["83a5a9b.4aac658"]]},{"id":"63bde34a.f25f3c","type":"change","z":"f23df1e6.9c42","name":"Send Tank full to log","rules":[{"t":"set","p":"payload","pt":"msg","to":"TANK FULL <br>","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1020,"y":180,"wires":[["4aa8853a.8f9cec"]]},{"id":"3a854b3e.4cd6c4","type":"ui_switch","z":"f23df1e6.9c42","name":"","label":"Pump on/off","tooltip":"","group":"38b90348.e0a34c","order":8,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"ON","onvalueType":"str","onicon":"","oncolor":"","offvalue":"OFF","offvalueType":"str","officon":"","offcolor":"","x":1010,"y":100,"wires":[["c904cf93.7a157","8bb43828.58bb18"]]},{"id":"9e5ab7aa.494508","type":"inject","z":"f23df1e6.9c42","name":"trigger status 10","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"300","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":300,"wires":[["8a679f08.aabd"]]},{"id":"8ef7ed7d.b47f9","type":"rbe","z":"f23df1e6.9c42","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":180,"wires":[["63bde34a.f25f3c"]]},{"id":"c904cf93.7a157","type":"rbe","z":"f23df1e6.9c42","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"payload","x":1270,"y":140,"wires":[["3782b1aa.66dece","32a31822.21de18","31c0e896.26d978"]]},{"id":"fb678276.4d4b1","type":"ui_led","z":"f23df1e6.9c42","order":1,"group":"961ef9c5.ebcf38","width":4,"height":1,"label":"Water Tank Full","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#56562e","value":"ON","valueType":"str"},{"color":"#85d534","value":"OFF","valueType":"str"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"","x":990,"y":20,"wires":[]},{"id":"15d99838.af6f38","type":"gate","z":"f23df1e6.9c42","name":"","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","statusCmd":"status","persist":true,"x":310,"y":120,"wires":[["4517a249.b9023c"]]},{"id":"76294db.dd2fbb4","type":"ui_switch","z":"f23df1e6.9c42","name":"","label":"Pump Auto","tooltip":"","group":"38b90348.e0a34c","order":9,"width":5,"height":1,"passthru":true,"decouple":"false","topic":"control","topicType":"str","style":"","onvalue":"open","onvalueType":"str","onicon":"","oncolor":"","offvalue":"close","offvalueType":"str","officon":"","offcolor":"","animate":true,"x":270,"y":200,"wires":[["15d99838.af6f38","53a1719d.0cd54","9f227f14.bb6ad"]]},{"id":"fe3d29b.c17fdd8","type":"change","z":"f23df1e6.9c42","name":"Logic disabled","rules":[{"t":"set","p":"payload","pt":"msg","to":"LOGIC DISABLED <br>","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":220,"wires":[["4aa8853a.8f9cec"]]},{"id":"53a1719d.0cd54","type":"switch","z":"f23df1e6.9c42","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"close","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":450,"y":220,"wires":[["fe3d29b.c17fdd8"]]},{"id":"9f227f14.bb6ad","type":"switch","z":"f23df1e6.9c42","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"open","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":450,"y":260,"wires":[["8cc481a7.e16d5"]]},{"id":"8cc481a7.e16d5","type":"change","z":"f23df1e6.9c42","name":"Logic enabled","rules":[{"t":"set","p":"payload","pt":"msg","to":"LOGIC ENABLED <br>","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":260,"wires":[["4aa8853a.8f9cec"]]},{"id":"5af6050.5b117fc","type":"counter","z":"f23df1e6.9c42","inc":"1","name":"","x":1960,"y":60,"wires":[["d760dafa.6fd108","5b1d129b.2a720c"]]},{"id":"d760dafa.6fd108","type":"influxdb out","z":"f23df1e6.9c42","influxdb":"7ea76f2f.35f83","name":"graph litres","measurement":"pumplitres","precision":"","retentionPolicy":"","database":"database","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"organisation","bucket":"bucket","x":2170,"y":120,"wires":[]},{"id":"b06460c1.0e5da","type":"ui_digital_display","z":"f23df1e6.9c42","name":"","group":"38b90348.e0a34c","order":5,"width":3,"height":1,"digits":"4","decimals":"0","x":2180,"y":160,"wires":[]},{"id":"e03adf50.9a4f3","type":"ui_text","z":"f23df1e6.9c42","group":"38b90348.e0a34c","order":4,"width":2,"height":1,"name":"","label":"Delivery Litres:","format":"{{msg.payload}}","layout":"row-left","x":2180,"y":200,"wires":[]},{"id":"67dee9b7.defc48","type":"inject","z":"f23df1e6.9c42","name":"reset daily counter","props":[{"p":"reset","v":"0","vt":"num"}],"repeat":"","crontab":"59 23 * * *","once":false,"onceDelay":0.1,"topic":"","x":1450,"y":20,"wires":[["5af6050.5b117fc"]]},{"id":"5b1d129b.2a720c","type":"ui_digital_display","z":"f23df1e6.9c42","name":"Litres Today","group":"38b90348.e0a34c","order":3,"width":3,"height":1,"digits":"4","decimals":"0","x":2170,"y":40,"wires":[]},{"id":"643316d5.3ff598","type":"ui_text","z":"f23df1e6.9c42","group":"38b90348.e0a34c","order":2,"width":2,"height":1,"name":"","label":"Litres Today:","format":"{{msg.payload}}","layout":"row-left","x":2170,"y":80,"wires":[]},{"id":"32a31822.21de18","type":"switch","z":"f23df1e6.9c42","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"ON","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1250,"y":200,"wires":[["ae2fa80e.6a6368"]]},{"id":"c9ce7f5d.aece","type":"counter","z":"f23df1e6.9c42","inc":"1","name":"","x":1960,"y":140,"wires":[["b06460c1.0e5da","64ee4977.21d618"]]},{"id":"ae2fa80e.6a6368","type":"function","z":"f23df1e6.9c42","name":"","func":"msg.reset = '0'\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1720,"y":180,"wires":[["c9ce7f5d.aece"]]},{"id":"11176998.638a16","type":"inject","z":"f23df1e6.9c42","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"open","payloadType":"str","x":90,"y":200,"wires":[["76294db.dd2fbb4"]]},{"id":"70c45a17.8300f4","type":"function","z":"f23df1e6.9c42","name":"","func":"msg.topic = msg.mytime\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1360,"y":100,"wires":[[]]},{"id":"8bb43828.58bb18","type":"simpletime","z":"f23df1e6.9c42","name":"","mydate":false,"myymd":false,"myyear":false,"mymonth":false,"mymonthn":false,"mydom":false,"mydoy":false,"myday":false,"myhourpm":false,"myhour":false,"mytime":true,"mytimes":false,"myminute":false,"myminutes":false,"mysecond":false,"mymillis":false,"myepoch":false,"myrawdate":false,"mypm":false,"x":1210,"y":60,"wires":[["70c45a17.8300f4"]]},{"id":"64ee4977.21d618","type":"ui_chart","z":"f23df1e6.9c42","name":"","group":"ba313b56.39f528","order":0,"width":0,"height":0,"label":"Pumped Litres","chartType":"bar","legend":"true","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"x":2180,"y":240,"wires":[[]]},{"id":"e88435d4.70a0e8","type":"mqtt in","z":"f23df1e6.9c42","name":"","topic":"/stat/pulse","qos":"2","datatype":"auto","broker":"df293a6.4c3c8c8","x":1720,"y":80,"wires":[["5af6050.5b117fc","c9ce7f5d.aece","fdf71449.0ff1c8"]]},{"id":"786933bd.26d9fc","type":"ui_level","z":"f23df1e6.9c42","group":"38b90348.e0a34c","order":9,"width":0,"height":0,"name":"","label":"Litres per Minute","colorHi":"#e60000","colorWarn":"#ff9900","colorNormal":"#00b33c","colorOff":"#595959","min":0,"max":"20","segWarn":"5","segHigh":"10","unit":"","layout":"sh","channelA":"","channelB":"","decimals":0,"animations":"soft","shape":2,"colorschema":"fixed","textoptions":"default","colorText":"#eeeeee","fontLabel":"","fontValue":"","fontSmall":"","colorFromTheme":true,"textAnimations":true,"hideValue":false,"tickmode":"off","peakmode":false,"property":"payload","peaktime":3000,"x":2310,"y":280,"wires":[]},{"id":"31c0e896.26d978","type":"trigger","z":"f23df1e6.9c42","name":"","op1":"0","op2":"0","op1type":"str","op2type":"str","duration":"-60","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":1790,"y":280,"wires":[["c995075c.38ab08"]]},{"id":"c995075c.38ab08","type":"function","z":"f23df1e6.9c42","name":"","func":"msg.reset = '0'\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1960,"y":280,"wires":[["fdf71449.0ff1c8"]]},{"id":"fdf71449.0ff1c8","type":"counter","z":"f23df1e6.9c42","inc":1,"name":"","x":2100,"y":280,"wires":[["786933bd.26d9fc"]]},{"id":"38b90348.e0a34c","type":"ui_group","name":"Pump Control","tab":"536ed44c.654d5c","order":3,"disp":true,"width":"5","collapse":false},{"id":"df293a6.4c3c8c8","type":"mqtt-broker","name":"Local MQTT","broker":"192.168.2.253","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"961ef9c5.ebcf38","type":"ui_group","name":"Solar","tab":"12e195b2.3de9fa","order":8,"disp":false,"width":"4","collapse":false},{"id":"7ea76f2f.35f83","type":"influxdb","hostname":"127.0.0.1","port":"8086","protocol":"http","database":"pipower","name":"","usetls":false,"tls":"","influxdbVersion":"1.x","url":"http://localhost:8086","rejectUnauthorized":true},{"id":"ba313b56.39f528","type":"ui_group","name":"Pump Chart","tab":"536ed44c.654d5c","order":6,"disp":false,"width":"5","collapse":false},{"id":"536ed44c.654d5c","type":"ui_tab","name":"Pump Status","icon":"fa-tint","order":2,"disabled":false,"hidden":false},{"id":"12e195b2.3de9fa","type":"ui_tab","name":"Cameras","icon":"mi-videogame_asset","order":1,"disabled":false,"hidden":false}]

Which display on the flow you showed the image of is the one that gets reset? Is it the 'resend every 60s' node that is doing it? That appears to reset the counter.

When posting a flow please just mark and export the nodes that are needed to show the problem. Also tell us about any non-standard nodes you are using so we can install them if necessary.

Hi colin,

The Level meter gets reset which is the litres per minute meter at the bottom of the second image.

not any non-standard nodes.. just the web ui nodes

That is probably because you have a Trigger node which triggers the counter reset every 60 seconds, at least I assume that it what happens when you send a message into the counter node. You are using the following non-standard nodes in the flow you posted

image

I don't know exactly what the counter node is but I imagine that sending msg.reset to it resets it.

Oh, I see what you want. You are not asking why it resets, but how to calculate the litres/minute and keep it on the screen. This function will calculate the flow rate using the time between successive pulses. Feed the pulses in and it will output the flow rate in L/min

let lastTime = context.get("lastTime") || 0  // previous time
let now = new Date().getTime()  // current time in msec
if (lastTime > 0) {
    msg.payload = 60000 / (now - lastTime) // flow rate litres/min
} else {
    msg = null  // do nothing first time through
}
context.set("lastTime", now)
return msg;
1 Like

Thanks Colin!

That seems to be working!

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