I agree with RMB, this is very complex to build.
Usually this is how it works: you show the flow(s) you could come up with, and we can help improve and/or share ideas on how to proceed
Homey can calculate “anything” you like.
But how to calculate this, is out of my league