How to use threads in custom components

Hello,

I need to develop a component for my window blinds. They are connected to two relais via i2c. Switching on the first relay closes the blinds, the second one opens them. Now I’m facing 2 problems:

  1. When opening / closing the blinds I need to wait some time (10-15s) and switch the relay off
  2. I need to guess the position by measuring the passed time

How can I achieve this? Is there any type of sleep function I can use to increment / decrement a counter. I guess I need some kind of threading to communicate with my entity (to signal a stop before the blinds are completely open / closed)

Thanks,
Volker