Automatic fish feeder

Hello all,

I need some help I'm new too coding and node red.
I am basically after advice.

So a little about what I want to achieve the fish feeder has = 250 feeds and each time the msg.payload = true de-increment by 1 but also the 250 will need to be reset so when it gets a signal from a UI button it resets the reduced 250 to 250.

Have a look at flow context in the docs.
You use the UI button to change the saved context value to 250, and use the msg.payload to decrement the context value by 1.

Thanks, @Paul-Reed so do I need to make a file store to save the context data?

That depends on how resilient you want things to be. The docs say
"By default, context is stored in memory only"
...which means that you would lose context data if you rebooted your system.
If however you setup a file based store, the context value would be saved to disk, and therefore would survive a reboot.

the latest version of Node-RED let you configure the flow and global contexts to use file or memory storage so you can persist things over a power outage more easily.
(but maybe just get it working first :slight_smile:

Nice post about it here - A guide to understanding 'Persistent Context'

[{"id":"222545a6.ab604a","type":"debug","z":"1b706be0.aa739c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":740,"y":440,"wires":[]},{"id":"9d4a09ee.86667","type":"inject","z":"1b706be0.aa739c","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":300,"y":440,"wires":[["b4090c34.2836a8"]]},{"id":"bd9967b1.9be7f8","type":"inject","z":"1b706be0.aa739c","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":560,"wires":[["2b696141.0d93c6"]]},{"id":"b4090c34.2836a8","type":"function","z":"1b706be0.aa739c","name":"","func":"\nflow.set(\"FishMax\", 250, \"FishFeederMax\");\nflow.set(\"FishResult\", 10, \"FishFeederResult\");\nflow.set(\"reduce\", 1, \"FishFoodReduce\");","outputs":1,"noerr":0,"x":500,"y":440,"wires":[["222545a6.ab604a"]]},{"id":"2b696141.0d93c6","type":"function","z":"1b706be0.aa739c","name":"","func":"var mo = flow.get([\"FishMax\", \"FishResult\", \"reduce\"]);\nvar po = flow.get(\"FishMax\" - \"reduce\");\n\nmsg.payload = mo;\n\nreturn msg;","outputs":1,"noerr":0,"x":500,"y":580,"wires":[["82bf53f7.d78c7"]]},{"id":"82bf53f7.d78c7","type":"debug","z":"1b706be0.aa739c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":720,"y":580,"wires":[]}]

So in my settings.js i have created a context file save, and the fucntion node returns the values i set into the function with flow.set, so slowly getting there now whats the best way to reduce the intial amount

Flow.get ("1") - Flow.get("2") = Flow.set("3")

Don't know why you have 3 flow contexts...
Why not just have one, and decrement it or reset it to 250?

For example;

[{"id":"37a92ccd.38ce44","type":"inject","z":"644f7043.705ed","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":490,"wires":[["b69eeef6.0e0c3"]]},{"id":"b69eeef6.0e0c3","type":"change","z":"644f7043.705ed","name":"Set to 250","rules":[{"t":"set","p":"fishfood","pt":"flow","to":"250","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":490,"wires":[[]]},{"id":"ab6af0b8.9e76f","type":"inject","z":"644f7043.705ed","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":530,"wires":[["6906b630.118378"]]},{"id":"6906b630.118378","type":"function","z":"644f7043.705ed","name":"Decrement by 1","func":"var newValue = (flow.get(\"fishfood\")-1);\nflow.set(\"fishfood\", newValue);\nmsg.payload = newValue;\nreturn msg;","outputs":1,"noerr":0,"x":320,"y":530,"wires":[["482a0e1e.71988"]]},{"id":"482a0e1e.71988","type":"debug","z":"644f7043.705ed","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":520,"y":530,"wires":[]}]

Excellent @Paul-Reed it's all working as I need, I made a file storage as advised by @dceejay and that's all working too thanks for your time.

I'm looking at using a yf-s201 flow meter it uses a pulse output has anyone ever used one or know of any info on how to set up?

1 Like

Hi. I want to use YF-S201 too. I found this one:

Were you able find and use one? If so, can you help me on the following post:

Please don't post the same question in multiple threads. I'm closing this one since it is a year old