Control my Shutters by my Window Sensors

Hi there,
I am very new to this forum, so please excuse any mistakes I do with wrong categories or something else…

Now to my topic/problem:

I have my Roller shutters connected to a shelly 2pm and a window sensor on every associated window that can report the state and a tilt angle.

I want to control my shutters when I open the window like this:

If window changes state to open and shutter is < 10%
     -open shutter to 100% when window is not tilted (tilt angle < 3°)
     -open shutter to 20% when window is tilted (tilt angle >= 3°)

If window changes state to close and shutter was previously opened by this automation
    -close shutter to previous value (or to 0% that doesnt matter)

I cant use two standard automations because I need to save wether shutter was opened by automation or by user, because I dont want the shutter to close, when someone closes a window during the day.

Any ideas how i can use this maybe even as a blueprint so i dont have to rewrite this for every window?

Greets
Mathis