Plant Factory for agriculture

Just had a few spare minutes to knock-up a quick (possible) solution using some of the basic nodes.

Please note...
"No FSMs were used or harmed in the making of this flow."

I'm sure there are parts of the flow that can be simplified.
For example, some of the functionality in the function blocks could be combined.

Hope you find this useful.

[{"id":"33da7582.0d26e2","type":"inject","z":"935fc4c0.e49458","name":"","topic":"","payload":"","payloadType":"num","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":150,"y":80,"wires":[["298df848.2f5568"]]},{"id":"298df848.2f5568","type":"change","z":"935fc4c0.e49458","name":"Set initial conditions","rules":[{"t":"set","p":"status","pt":"flow","to":"stopped","tot":"str"},{"t":"set","p":"counter","pt":"flow","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":80,"wires":[[]]},{"id":"b644747a.430e8","type":"inject","z":"935fc4c0.e49458","name":"","topic":"start","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":160,"wires":[["6fe89848.fae838"]]},{"id":"69c6af4c.b03bf","type":"inject","z":"935fc4c0.e49458","name":"Trigger every 3 seconds","topic":"","payload":"1","payloadType":"num","repeat":"3","crontab":"","once":true,"onceDelay":"1","x":210,"y":240,"wires":[["cc76bee1.6f76c"]]},{"id":"cc76bee1.6f76c","type":"function","z":"935fc4c0.e49458","name":"","func":"var status = flow.get(\"status\") || \"stopped\";\n\nif (status == \"run\")\n{\n    var counter = flow.get(\"counter\") || 0;\n    if (counter < 5)\n    {\n        counter = counter + 1;\n        flow.set(\"counter\",counter);\n        return msg;\n    }\n    else\n    {\n        counter = 0;\n        flow.set(\"counter\",counter);\n        flow.set(\"status\",\"stopped\");\n    }\n}\n\n","outputs":1,"noerr":0,"x":410,"y":240,"wires":[["97677c38.0aad5","598b4e34.52e978","ed68e8f7.b2d658","9af74977.f4993"]]},{"id":"97677c38.0aad5","type":"function","z":"935fc4c0.e49458","name":"Decode Valve-A","func":"var counter = flow.get(\"counter\") || 0;\n\nif (counter == 1)\n   {\n    msg.payload = 1;\n    node.status({fill:\"green\",shape:\"dot\",text:\"Valve-A is ON\"});\n   }\n   \nelse\n   {\n    msg.payload = 0;\n    node.status({fill:\"red\",shape:\"dot\",text:\"Valve-A is OFF\"});\n   }\n\nreturn msg;","outputs":1,"noerr":0,"x":600,"y":140,"wires":[["4553c239.9c9ff4"]]},{"id":"598b4e34.52e978","type":"function","z":"935fc4c0.e49458","name":"Decode Valve-B","func":"var counter = flow.get(\"counter\") || 0;\n\nif (counter == 2)\n   {\n    msg.payload = 1;\n    node.status({fill:\"green\",shape:\"dot\",text:\"Valve-B is ON\"});\n   }\n   \nelse\n   {\n    msg.payload = 0;\n    node.status({fill:\"red\",shape:\"dot\",text:\"Valve-B is OFF\"});\n   }\n\nreturn msg;","outputs":1,"noerr":0,"x":600,"y":200,"wires":[["e6d2c777.306ec"]]},{"id":"ed68e8f7.b2d658","type":"function","z":"935fc4c0.e49458","name":"Decode Valve-C","func":"var counter = flow.get(\"counter\") || 0;\n\nif (counter == 3)\n   {\n    msg.payload = 1;\n    node.status({fill:\"green\",shape:\"dot\",text:\"Valve-C is ON\"});\n   }\n   \nelse\n   {\n    msg.payload = 0;\n    node.status({fill:\"red\",shape:\"dot\",text:\"Valve-C is OFF\"});\n   }\n\nreturn msg;","outputs":1,"noerr":0,"x":600,"y":280,"wires":[["bb773c1e.ac3818"]]},{"id":"9af74977.f4993","type":"function","z":"935fc4c0.e49458","name":"Decode Valve-A","func":"var counter = flow.get(\"counter\") || 0;\n\nif (counter == 4)\n   {\n    msg.payload = 1;\n    node.status({fill:\"green\",shape:\"dot\",text:\"Valve-D is ON\"});\n   }\n   \nelse\n   {\n    msg.payload = 0;\n    node.status({fill:\"red\",shape:\"dot\",text:\"Valve-D is OFF\"});\n   }\n\nreturn msg;","outputs":1,"noerr":0,"x":600,"y":340,"wires":[["a1766a9b.789518"]]},{"id":"6fe89848.fae838","type":"change","z":"935fc4c0.e49458","name":"Start the sequence","rules":[{"t":"set","p":"status","pt":"flow","to":"run","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":160,"wires":[[]]},{"id":"7db6094d.069648","type":"comment","z":"935fc4c0.e49458","name":"Testing only - change this to 10-seconds ","info":"","x":240,"y":300,"wires":[]},{"id":"4553c239.9c9ff4","type":"debug","z":"935fc4c0.e49458","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":790,"y":140,"wires":[]},{"id":"e6d2c777.306ec","type":"debug","z":"935fc4c0.e49458","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":790,"y":200,"wires":[]},{"id":"bb773c1e.ac3818","type":"debug","z":"935fc4c0.e49458","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":790,"y":280,"wires":[]},{"id":"a1766a9b.789518","type":"debug","z":"935fc4c0.e49458","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":790,"y":340,"wires":[]},{"id":"61d3256a.2583dc","type":"comment","z":"935fc4c0.e49458","name":"Color scheme: Red = OFF, Green = ON ","info":"","x":670,"y":400,"wires":[]}]