How to create a timeline chart for window sensors?

So far, the best answer I have found for this question is

However, it seems to be non-trival to design such a chart. I will see how far I can get and share the code once/if I succeed.