Graphical automation with a start delay and set period using a form

I want my automation to trigger a “wait” until “Start At Time” and then run for “Run For” hours and then turn off. I’ve currently connected a socket I can control in HA so I got that part covered.

Can someone help me get this sorted using the UI?

Please speak to me as I was 3 years old… new to all of this :slight_smile:

My helpers:
image

The trigger can just be the time you want to start it. Should be easy to plug in a start time.
The ‘run for’ can be a timer. You ‘start timer’ when the trigger happens for as many hours yuou want it to run.
Then you have another automation with a trigger that stops the process when the timer has finished.

I’m sure if you wait long enough, someone will write it for you… but this isn’t too difficult that you couldn’t try and post back any issues. Feel free and I or someone will help you correct it. Its a good way to learn.

1 Like

Thanks. I’m trying to get the hang of it so I appreciate your response. I’d rather do it myself but it’s figuring the flow out I’m not getting yet.

So one thing, how do I set “Duration” of timer to be input_number.run_for? I forgot to include the dashboard form I want to use to make it dynamic.

image

So if I was going to do this, i’d use a timer. and I would set the duration of that timer to the hours you set there. Like this:

  - service: timer.start
    data:
      duration: '{{ states(''input_number.run_for'') | float(1) * 60 * 60  }}'
    target:
      entity_id: timer.some_timer_you_create

Btw, it looks like you are creating some sort of manual run timer. I do something very similar for my pool automation. This may help. I don’t bother with a ‘start’ button like you do. I simply trigger off of setting the timer itself (your slider). Then start it. Then clear the duration back to zero.

alias: Pool Runtime Manual Start
description: ''
trigger:
  - platform: state
    entity_id:
      - input_number.pool_manual_runtime
    for:
      hours: 0
      minutes: 0
      seconds: 3
condition:
  - condition: numeric_state
    entity_id: input_number.pool_manual_runtime
    above: '0'
action:
  - service: timer.start
    data:
      duration: '{{ states(''input_number.pool_manual_runtime'') | float(1) * 60 * 60  }}'
    target:
      entity_id: timer.pool_manual_runtime_timer
  - choose:
      - conditions:
          - condition: state
            entity_id: input_select.pool_state
            state: Manual
        sequence: []
    default:
      - service: input_select.select_option
        data:
          option: Manual
        target:
          entity_id: input_select.pool_mode
      - service: homeassistant.turn_on
        data: {}
        target:
          entity_id:
            - switch.pentair_f7_dc_7a_pool
            - switch.pentair_f7_dc_7a_pool_high
  - service: input_number.set_value
    data:
      value: 0
    target:
      entity_id: input_number.pool_manual_runtime
mode: single
alias: Pool Shutoff After Manual Runtime
description: ''
trigger:
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.pool_manual_runtime_timer
  - platform: state
    entity_id: input_number.pool_manual_runtime
    to: '0'
    for:
      hours: 0
      minutes: 0
      seconds: 5
condition:
  - condition: state
    entity_id: input_select.pool_state
    state: Manual
  - condition: state
    entity_id: input_select.pool_mode
    state: Select
  - condition: state
    entity_id: input_boolean.pool_service_mode
    state: 'off'
action:
  - service: input_select.select_option
    target:
      entity_id: input_select.pool_mode
    data:
      option: 'Off'
mode: single

In essence, your flow you’ll have 3 events to trigger off.

  1. the time itself. Your choice.
  2. finishing of the timer.
  3. The push button to activate it

For each of those, you create 1 automation (you can do it in a single automation if you wanted using trigger IDs and ‘choose’. Its again up to you but by example uses 2 automations.

So for #1 if you want to use the time to start it.

trigger:
  - platform: time
    at: '22:22:00'

That flow should start your process, and kick off the countdown timer. The duration of that timer should be the value in your slide (like my example).

For #2,

trigger:
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.pool_manual_runtime_timer

This would capture the timer finish and stop your process.

#3

The other piece of your GUI is the fact that I think you only want this to happen after you hit the ‘button’. If that is the case, you’ll probably want to create another input_boolean’ so you can use that as a condition in your start automation. Basically when you press that button, you’re going to toggle an ‘input_boolean’ to ‘on’ so you know that your process is allowed to start. You’ll need an automation to handle this. Essentially:

trigger:
  - platform: state
    entity_id: button.my_button

That automation should simply toggle that input_boolean to ‘on’. Then your automation from step #1 and #2 should have that input_boolean = on as a condition.

Tremendously helpful to get me started. I think I’m starting to get the hang of it now. I discovered that the developer tools is very helpful.

Look what you helped me create :slight_smile: (wait for it)

1 Like