automation-code

This is what I have coded so far. In the main() function you can de-comment the other automations and test the code with them.
I am not making any extended testing on the code, so there might be bugs that I have missed. Feel free to test it with more complicated automations. I hope I have copied the code without missing anything important...