I have 3 date_time inputs in this flow but you can add more or remove some, or whatever you like. You will need to go to helpers and add 3 date_time inputs as 'time only' inputs, and put these on your dashboard. Go into each one of the state_changed blocks in the Node red flow and point the entity_id to the 3 inputs you created. Go into both of the call_service blocks at the far right and set the switch.entityID to the entity ID of the power switch you will be controlling to run your pump.
Now go into the function node and edit the green strings so they have these same entity ID's as you just entered for the state_changed blocks:
Code: Select all
[{"id":"6faa0663.1b2b08","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"5a5292fd.7d7bdc","type":"delay","z":"6faa0663.1b2b08","name":"","pauseType":"delayv","timeout":"0","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1080,"y":280,"wires":[["2e9a3423.86a44c"]]},{"id":"de430bbb.9b20d","type":"api-call-service","z":"6faa0663.1b2b08","name":"","server":"","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.YOUR_PUMP_SWITCH_ENTITY_ID","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1290,"y":200,"wires":[[]]},{"id":"2e9a3423.86a44c","type":"api-call-service","z":"6faa0663.1b2b08","name":"","server":"","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.YOUR_PUMP_SWITCH_ENTITY_ID","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1290,"y":280,"wires":[[]]},{"id":"72f60bde.bf77a4","type":"inject","z":"6faa0663.1b2b08","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"1","crontab":"","once":false,"onceDelay":0.1,"topic":"currentTime","payload":"$substring($now(),11,8)","payloadType":"jsonata","x":110,"y":120,"wires":[["9d1ce8e9.0daed"]]},{"id":"e94a6761.f6d96","type":"server-state-changed","z":"6faa0663.1b2b08","name":"","server":"","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_datetime.YOUR_FERTIGATION_DATETIME1","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":280,"y":300,"wires":[["9d1ce8e9.0daed"]]},{"id":"698a8d9.a61bd74","type":"function","z":"6faa0663.1b2b08","name":"","func":"// SET THIS CONSTANT TO HOWEVER LONG IT TAKES TO PUMP 1 LITER, IN SECONDS\nconst secondsPerLiter = 14; \n\nvar currentTime = msg.payload[\"currentTime\"];\n\n//CHANGE THE STRINGS BELOW IN GREEN TO THE ENTITY IDs OF YOUR INPUT_DATE TIMES \nvar fertTime1 = msg.payload[\"input_datetime.YOUR_FERTIGATION_DATETIME1\"];\nvar fertTime2 = msg.payload[\"input_datetime.YOUR_FERTIGATION_DATETIME2\"];\nvar fertTime3 = msg.payload[\"input_datetime.YOUR_FERTIGATION_DATETIME3\"];\n\n//THIS CONVERTS YOUR 'LITERS' INPUT NUMBER TO PUMP TIME IN MILLISECONDS \nvar fertDuration = (msg.payload[\"input_number.dozaj\"] * secondsPerLiter) *1000;\n\n//THIS RETURNS THE DELAY TIME TO THE VARIABLE DELAY BLOCK\nmsg.delay = fertDuration;\n\n//IF ANY OF YOUR INPUT_DATETIMES MATCH THE CURRENT TIME, TURN ON THE PUMP AND THEN TURN OFF AFTER DELAY EXPIRES\nif(fertTime1 == currentTime || fertTime2 == currentTime || fertTime3 == currentTime)\n {\n return msg;\n }\n \n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":900,"y":220,"wires":[["5a5292fd.7d7bdc","de430bbb.9b20d"]]},{"id":"9d1ce8e9.0daed","type":"join","z":"6faa0663.1b2b08","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"1","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":730,"y":220,"wires":[["4f79b5b5.5b159c","698a8d9.a61bd74"]]},{"id":"6b6110ee.c5c5e8","type":"server-state-changed","z":"6faa0663.1b2b08","name":"","server":"","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_datetime.YOUR_FERTIGATION_DATETIME2","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":280,"y":380,"wires":[["9d1ce8e9.0daed"]]},{"id":"3cdca92.4db64d6","type":"server-state-changed","z":"6faa0663.1b2b08","name":"","server":"","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_datetime.YOUR_FERTIGATION_DATETIME3","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":280,"y":460,"wires":[["9d1ce8e9.0daed"]]},{"id":"4f79b5b5.5b159c","type":"debug","z":"6faa0663.1b2b08","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":910,"y":320,"wires":[]},{"id":"17ee2fe5.c30eb8","type":"server-state-changed","z":"6faa0663.1b2b08","name":"Liters","server":"","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":"Alarm 1"},{"property":"icon","value":"mdi:fire"}],"entityidfilter":"input_number.dozaj","entityidfiltertype":"exact","outputinitially":true,"state_type":"num","haltifstate":"","halt_if_type":"num","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":true,"ignoreCurrentStateUnavailable":true,"x":90,"y":220,"wires":[["9d1ce8e9.0daed"]]},{"id":"62bf8387.dc9904","type":"comment","z":"6faa0663.1b2b08","name":"Send the current time every second","info":"","x":180,"y":80,"wires":[]}]