Best way to turn on/off a switch from a door sensor

Hi, I have a xiaomi door sensor and a broadlink tc2 switch.

My need is

  • when the door opens send switch command_on signal
  • when the door closes send switch command_off signal
  • after X minute of the door being open send switch command_off signal

Which is the best way to do it? SOme examples?

Thanks

Write three automatons

One for the door opening, one for the door closing and one for the time open for X minutes.

These are pretty basic automatons and I recommend you develop them and post them up. If you have trouble there are lot of people here to help.