Automation - wait for a template

Hi,
I am in a need of assistance with one of my automations:

alias: "givEnergy - 0:30 Charge Battery"
description: 
trigger:
  - platform: time
    at: "00:30:00"
    enabled: true
condition: []
action:
  - wait_template: >
      {{ states.sensor.battery_percent.state | float(0) >=
      states.number.battery_ac_charge_limit.state | float(0) }}
    continue_on_timeout: true
  - service: givenergy_local.set_charge_limit
    data:
      device_id: b1a9b37e8a130cee4fa0bbd9e0f363b8
      power: 2600
    enabled: true
  - service: givenergy_local.set_discharge_limit
    data:
      device_id: b1a9b37e8a130cee4fa0bbd9e0f363b8
      power: 0
    enabled: true
mode: single

In its current form the automation will wait forever until the wait_template is true. However in certain conditions it might be a couple of days until the condition is true.
What I want is for the automation to stop regardless at 7:30.
Any suggestions how to achieve that?
Thanks

How about the following:

  1. Change the mode from single to restart.
  2. Add a trigger_id to the existing trigger.
  3. Add a second trigger similar to the existing one but with a time of 07:30 which is when you want the timeout to occur.
  4. Under actions use either an if or choose to only execute the actions if the triggered_by ID relates to the first action.
  5. This way when the new trigger fires at 07:30 the automation will restart and then do nothing.

Hope that helps.

You need to supply a timeout. You trigger at 0:30 and want to continue at 07:30, so that’s 7 hours:

action:
  - wait_template: >
      {{ states.sensor.battery_percent.state | float(0) >=
      states.number.battery_ac_charge_limit.state | float(0) }}
    continue_on_timeout: true
    timeout: "07:00:00"

Waiting this long is generally not a good idea but I suppose you are unlikely to restart or reload this automation during that time period.

Also, try to use entity_ids rather than device_ids where you can. It’s a lot easier to change entity ids if you ever have to replace a device, You can do it in one place rather than everywhere a device_id is used.

1 Like