Running the script/sequence for a specified time

Hello!
Can you help with one small problem?
I’m using HA + RaspPi1+ IFTTT to control my Xiaomi vacuum through the Google Home.
I’ve created some scripts to clean specific parts of my first floor (kitchen, hall, etc.).
From time to time I’m taking the vacuum to the second floor - after this my map is recreated and when I come back to first floor I need to recreate the map again.
Because my first floor is mainly open I want to create a script (or rather sequence):

1.start cleaning (vacuum.start)
2. stop/pause cleaning after 2 minutes (?)
3. go back to the dock (vacuum.return_to_base)

This will create a sufficient map to perform spot cleaning through Google Home.

Does anybody know how to do 2nd point?
Thx!

I think I found it.
Timers.

I created timer called map.
Action “recreate map” is starting timer and cleaning.

then

in automation, on event timer.finished I turn on another script (pause cleaning, return to base).

I will test it home…

That can work, but you can probably do it a lot easier in a script with a delay. I don’t know the specifics for steps 1 & 3, but it would look something like this:

script:
  recreate_map:
    sequence:
      - service: vacuum.start
        entity_id: vacuum.my_vac
      - delay: 120
      - service: vacuum.return_to_base
        entity_id: vacuum.my_vac

See here for more details about the delay action.

ok - but this delay is trigered just after vacuum started or finished cleaning?

The steps of a script sequence are executed in the order specified. So the first service (vacuum.start) is started, then the delay starts, and after the delay completes, the second service (vacuum.return_to_base) is started. Does that answer your question?

Ok! I thought delay will start after vacumm will finish cleaning.
Thx! I’ll test it!

What determines when the vacuum finishes? And is that when you want to start the delay, or do you want the delay to start once the vacuum has started?

Again, the steps of a sequence happen in, well, sequence. The delay will not start until the service call from the previous step has completed. It depends on the particular service whether or not it completes before or after the call completes. In many cases there is at least some portion of the service (or side effect of the service) that continues in parallel with the script after the call completes. I suspect in this particular case, the call completes almost immediately, whereas the vacuuming (initiated by the service call) continues for some time.

BTW, if you wanted to wait until the vacuuming finished, you could probably do that, too, via a wait_template.

Hope that helps.