You can find a basic explanation op the building blocks here in an earlier post of mine:
I did some further fine-tuning and added additional sensors, but I hope it gives you the basic idea.
One thing to note is that I had to split the flow in multiple canvasses. Putting them in one canvas caused it to get very slow / freeze.