Looking for script that turns on a wemo for x interval and then turns of)

I’m trying to get away from two scripts for on and off with a new wemo. It will be controlling a hot water recirculator. I’ve never had anything with a potential sequence of on delay 30 minutes and off. If anyone has an example script for an action followed by a delayed second action I’d appreciate it.

Post what you currently have.

action:
  - service: switch.turn_on
    entity_id: switch.YOUR_WEMO
  - delay: '00:30:00'
  - service: switch.turn_off
    entity_id: switch.YOUR_WEMO

Thank you both for writing and @sparkydave for the example.

This is what I drafted up with the intention of three times it’s on for 30 minutes, and then only to be on so long as one of our two phones is detected at home.

- id: '5000000000005'
  alias: Hot water recirculation
  trigger:
  - platform: time
    at: '07:30:00'
  - platform: time
    at: '09:00:00'
  - platform: time
    at: '18:40:00'
  condition:
  - condition: or
    conditions:
    - condition: device
      device_id: b3537ca6e6de81866dad95f9a3e4bf2c
      domain: device_tracker
      entity_id: device_tracker.pixel_5
      type: is_home
    - condition: device
      device_id: f05b8bb0f7b5f1d39e70ddc602b08f7a
      domain: device_tracker
      entity_id: device_tracker.pixel_5_gaby
      type: is_home
  action:
  - service: switch.turn_on
    entity_id: switch.wemo_9_recirculator
  - delay: '00:30:00'
  - service: switch.turn_off
    entity_id: switch.wemo_9_recirculator 

May have botched the device condition. I’ve seen examples with type “is_not_home” so I just changed to “is_home”.

As long as you are ok with it staying on for that 30 min even if a phone changes to away, because that possibility isn’t currently accounted for in that automation.

Wow mind blown. How do I do that?

One way you could do it is using a wait_for_trigger. The other is using a while loop.

Using the wait_for_trigger

- id: '5000000000005'
  alias: Hot water recirculation
  trigger:
  - platform: time
    at: '07:30:00'
  - platform: time
    at: '09:00:00'
  - platform: time
    at: '18:40:00'
  condition:
  - condition: or
    conditions:
    - condition: device
      device_id: b3537ca6e6de81866dad95f9a3e4bf2c
      domain: device_tracker
      entity_id: device_tracker.pixel_5
      type: is_home
    - condition: device
      device_id: f05b8bb0f7b5f1d39e70ddc602b08f7a
      domain: device_tracker
      entity_id: device_tracker.pixel_5_gaby
      type: is_home
  action:
  - service: switch.turn_on
    entity_id: switch.wemo_9_recirculator
  - wait_for_trigger:
      - platform: state
        entity_id: device_tracker.pixel_5
        to: not_home
      - platform: state
        entity_id: device_tracker.pixel_5_gaby
        to: not_home
    timeout: '00:30:00'
  - service: switch.turn_off
    entity_id: switch.wemo_9_recirculator

This should basically wait for one of the phones to change to not_home but then continue anyway when that fails to occur, so cutting short the timeout if a phone does change to not_home. Give it a test because it’s not actually something I’ve tried before.

Cool, thank you! I’ll play with this over the weekend.