Convert automation to node red flow

I have the following automation, it’s my last on. How can I get this into node red:

- alias: Set next run time                                                                                                             
  trigger:                                                                                                                             
  - platform: state                                                                                                                    
    entity_id:                                                                                                                         
    - input_boolean.cycle1_enable                                                                                                      
    - input_boolean.cycle2_enable                                                                                                      
    to: 'on'                                                                                                                           
  - platform: state                                                                                                                    
    entity_id:                                                                                                                         
    - input_select.cycle1_schedule_time                                                                                                
    - input_select.cycle2_schedule_time                                                                                                
  action:                                                                                                                              
  - service: input_datetime.set_datetime                                                                                               
    data_template:                                                                                                                     
      entity_id: "{% if trigger.entity_id == 'input_boolean.cycle1_enable' or\n  \                                                     
        \    trigger.entity_id == 'input_select.cycle1_schedule_time' %}\n  input_datetime.cycle1_next_run_time\n\                     
        {% else %}\n  input_datetime.cycle2_next_run_time\n{% endif %}\n"                                                              
      date: "{% if trigger.entity_id == 'input_boolean.cycle1_enable' or\n      trigger.entity_id\                                     
        \ == 'input_select.cycle1_schedule_time' %}\n  {% set time = states('input_select.cycle1_schedule_time')\                      
        \ %}\n{% else %}\n  {% set time = states('input_select.cycle2_schedule_time')\                                                 
        \ %}\n{% endif %} {% if now().strftime('%H:%M') < time %}\n  {{ as_timestamp(now())\                                           
        \ | timestamp_custom(\"%Y-%m-%d\") }}\n{% else %}\n  {{ (as_timestamp(now())\                                                  
        \ + 24 * 3600 ) | timestamp_custom(\"%Y-%m-%d\") }}\n{% endif %}\n"                                                            
      time: "{% if trigger.entity_id == 'input_boolean.cycle1_enable' or\n      trigger.entity_id\                                     
        \ == 'input_select.cycle1_schedule_time' %}\n  {{ states('input_select.cycle1_schedule_time')\                                 
        \ }}\n{% else %}\n  {{ states('input_select.cycle2_schedule_time') }}\n{%\                                                     
        \ endif %}\n"                                                                                                                  
  id: f87180f9951240c2b5bd33128bdf3f2e        

I have tried to use the service set_input_date but I get API invalid.

Help appreciated.

Can you post here your flow. The api error might be from override input or just bad syntax.

The set_input_date is working for me after I made sure the format in HA was correctly shown as well. As @subzero79 mentioned , please share your flow so we can check why set_input_date is failing.

A side note:
I migrated all my automation from HA to NR but I never did a 1:1 convert as there were too many limitations and workarounds in HA. I always designed my new flow based on the NR capabilities which simplified most of my HA-automations and even improved several features.

I don’t have access to NR at this, time will see if I still have the flow or removed it out of frustration.

@xx_Nexus_xx I might try to go with you side note when I’m home.

[{"id":"caf56f16.79084","type":"server-state-changed","z":"1c872b73.2d7725","name":"Cycle1 Enabled?","server":"430f1b05.702794","entityidfilter":"input_boolean.cycle1_enable","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is_not","outputs":2,"output_only_on_state_change":true,"x":120,"y":760,"wires":[["ecb05c8c.e04f7"],[]]},{"id":"40eef15.0b1b51","type":"server-state-changed","z":"1c872b73.2d7725","name":"Cycle1 Schedule Time Changed","server":"430f1b05.702794","entityidfilter":"input_select.cycle1_schedule_time","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":170,"y":820,"wires":[["edf2f8be.4f9438"]]},{"id":"ecb05c8c.e04f7","type":"api-current-state","z":"1c872b73.2d7725","name":"Get Cycle1 Time","server":"430f1b05.702794","outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_select.cycle1_schedule_time","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":330,"y":740,"wires":[["edf2f8be.4f9438"]]},{"id":"420c649a.e40dbc","type":"api-call-service","z":"1c872b73.2d7725","name":"Set Cycle1 Schedule Time","server":"430f1b05.702794","service_domain":"input_datetime","service":"set_datetime","data":"{\"entity_id\":\"input_datetime.cycle1_next_run_time\"}","render_data":false,"mergecontext":"","output_location":"payload","output_location_type":"msg","x":1060,"y":760,"wires":[[]]},{"id":"bc51bf28.11553","type":"moment","z":"1c872b73.2d7725","name":"Next Day","topic":"","input":"","inputType":"date","inTz":"Europe/Brussels","adjAmount":"1","adjType":"days","adjDir":"add","format":"YYYY-MM-DD","locale":"C","output":"payload.data.date","outputType":"msg","outTz":"Europe/Brussels","x":800,"y":760,"wires":[["420c649a.e40dbc"]]},{"id":"19b290b2.cf7daf","type":"moment","z":"1c872b73.2d7725","name":"Current Day","topic":"","input":"","inputType":"date","inTz":"Europe/Brussels","adjAmount":"0","adjType":"days","adjDir":"add","format":"YYYY-MM-DD","locale":"C","output":"payload.data.date","outputType":"msg","outTz":"Europe/Brussels","x":810,"y":800,"wires":[[]]},{"id":"edf2f8be.4f9438","type":"function","z":"1c872b73.2d7725","name":"Check Time?","func":"\nmsg.payload = { \"data\": {\"time\": msg.payload} };\n\nif (Date.parse('01/01/2011 '+ msg.payload) >= Date.parse('01/01/2011 ' + new Date().getTime())){\n return [msg, null]; \n}else{\n return [null, msg]; \n}","outputs":2,"noerr":0,"x":570,"y":760,"wires":[["bc51bf28.11553"],["19b290b2.cf7daf"]]},{"id":"430f1b05.702794","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":false,"rejectUnauthorizedCerts":true}]

What I have so far.

The Check time function isn’t working as it should.

All the middle nodes could have been done in a single function node but I tried to keep it true to what you originally had.

[{"id":"3e7ac14f.8c67de","type":"trigger-state","z":"fb2720c8.ee24e","name":"Cycle Booleans","server":"ef067c6f.620e6","entityid":"input_boolean.cycle1_enable,input_boolean.cycle2_enable","entityidfiltertype":"substring","debugenabled":false,"constraints":[{"id":"5sz8mo68nlo","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"},{"id":"hhdwjcf6u3h","targetType":"this_entity","targetValue":"","propertyType":"previous_state","propertyValue":"old_state.state","comparatorType":"is_not","comparatorValueDatatype":"str","comparatorValue":"on"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":176,"y":464,"wires":[["2da55921.c61956"],[]]},{"id":"83a619ff.cd3fd8","type":"server-state-changed","z":"fb2720c8.ee24e","name":"Cycle Select Change","server":"ef067c6f.620e6","entityidfilter":"input_select.cycle1_schedule_time,input_select.cycle2_schedule_time","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":196,"y":512,"wires":[["2da55921.c61956"]]},{"id":"2da55921.c61956","type":"function","z":"fb2720c8.ee24e","name":"Get Cycle Id","func":"cycleId = /cycle([12])_/.exec(msg.topic)[1];\ndatetimeId = `input_datetime.cycle${cycleId}_next_run_time`;\n\nmsg.datetimeId = datetimeId;\nmsg.payload = {\n    entity_id: `input_select.cycle${cycleId}_schedule_time`\n}\nreturn msg;\n\n","outputs":1,"noerr":0,"x":422,"y":464,"wires":[["afdae404.040cb8"]]},{"id":"afdae404.040cb8","type":"api-current-state","z":"fb2720c8.ee24e","name":"","server":"ef067c6f.620e6","outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"","state_type":"str","state_location":"hours","override_payload":"msg","entity_location":"","override_data":"none","x":608,"y":464,"wires":[["746741ec.bd147"]]},{"id":"746741ec.bd147","type":"function","z":"fb2720c8.ee24e","name":"Check Time?","func":"const [hour, minutes] = msg.hours.split(\":\");\nconst d = new Date().setHours(hour,minutes);\n\nif (Date.now() >= d) return [null, msg];\n\nreturn [msg, null] ;\n","outputs":2,"noerr":0,"x":790,"y":464,"wires":[["4ecdc71e.b59008"],["5a6fe504.49ea6c"]]},{"id":"5a6fe504.49ea6c","type":"moment","z":"fb2720c8.ee24e","name":"Next Day","topic":"","input":"","inputType":"date","inTz":"Europe/Brussels","adjAmount":"1","adjType":"days","adjDir":"add","format":"YYYY-MM-DD","locale":"C","output":"payload","outputType":"msg","outTz":"Europe/Brussels","x":956,"y":512,"wires":[["2df7e4ec.efa45c"]]},{"id":"4ecdc71e.b59008","type":"moment","z":"fb2720c8.ee24e","name":"Current Day","topic":"","input":"","inputType":"date","inTz":"Europe/Brussels","adjAmount":"0","adjType":"days","adjDir":"add","format":"YYYY-MM-DD","locale":"C","output":"payload","outputType":"msg","outTz":"Europe/Brussels","x":966,"y":464,"wires":[["2df7e4ec.efa45c"]]},{"id":"2df7e4ec.efa45c","type":"api-call-service","z":"fb2720c8.ee24e","name":"Set Schedule Time","server":"ef067c6f.620e6","service_domain":"input_datetime","service":"set_datetime","data":"{\"entity_id\":\"{{datetimeId}}\",\"date\":\"{{payload}}\",\"time\":\"{{hours}}\"}","mergecontext":"","output_location":"payload","output_location_type":"msg","x":1178,"y":464,"wires":[[]]}]

edit:
not fully tested but should be close

Thanks @Kermit!

How do you mean all the middle nodes can be in one? I have tried it previously but it went from 27/02/2019 -> 01/03/2019 when I added one day.

[{"id":"e4dea4fb.852b88","type":"trigger-state","z":"fb2720c8.ee24e","name":"Cycle Booleans","server":"ef067c6f.620e6","entityid":"input_boolean.cycle1_enable,input_boolean.cycle2_enable","entityidfiltertype":"substring","debugenabled":false,"constraints":[{"id":"5sz8mo68nlo","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"},{"id":"hhdwjcf6u3h","targetType":"this_entity","targetValue":"","propertyType":"previous_state","propertyValue":"old_state.state","comparatorType":"is_not","comparatorValueDatatype":"str","comparatorValue":"on"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":144,"y":272,"wires":[["caeda3.297b426"],[]]},{"id":"350102a4.87d08e","type":"server-state-changed","z":"fb2720c8.ee24e","name":"Cycle Select Change","server":"ef067c6f.620e6","entityidfilter":"input_select.cycle1_schedule_time,input_select.cycle2_schedule_time","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":164,"y":320,"wires":[["caeda3.297b426"]]},{"id":"caeda3.297b426","type":"function","z":"fb2720c8.ee24e","name":"do stuff","func":"const gHomeAssistant = global.get('homeassistant').homeAssistant;\n\nconst cycleId = /cycle([12])_/.exec(msg.topic)[1];\n\nmsg.datetimeId = `input_datetime.cycle${cycleId}_next_run_time`;\nmsg.hours = gHomeAssistant.states[`input_select.cycle${cycleId}_schedule_time`].state;\n\nconst [hour, minutes] = msg.hours.split(\":\");\nlet d = new Date().setHours(hour,minutes)\n\nif (Date.now() >= d) {\n    d += 864E5;\n}\nconst f = new Date(d);\nmsg.payload = `${f.getFullYear()}-${f.getMonth()+1}-${f.getDate()}`;\n\nreturn msg;","outputs":1,"noerr":0,"x":380,"y":272,"wires":[["7c62da93.d5fc04"]]},{"id":"7c62da93.d5fc04","type":"api-call-service","z":"fb2720c8.ee24e","name":"Set Schedule Time","server":"ef067c6f.620e6","service_domain":"input_datetime","service":"set_datetime","data":"{\"entity_id\":\"{{datetimeId}}\",\"date\":\"{{payload}}\",\"time\":\"{{hours}}\"}","mergecontext":"","output_location":"payload","output_location_type":"msg","x":570,"y":272,"wires":[[]]}]

Thanks!

Learned a lot with the latest reply!