Node-RED is a "low code" programming tool. Most or all of your script can be done with the basic switch, change, trigger etc nodes.
Or you could translate it into Javascript and use a function node.
I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.