Blueprint template condition with waiting time or delay

I am trying to ajust a blueprint to charge my car on solar energy. When increasing or decreasing the charger current, i would like to wait for 1 minute. But I just can’t figure out how to do it. I am using variables for the calculation of the available current and available power. I have tried multiple solutions, but just can’t get it to work.
Can someone please help me and let me know how I can make a condition in the below blueprint that checks if the currentAvailableCharging > ChargerCurrent for 30 seconds, or waits/delays 30 seconds befor changing the ems_charger_current value?

The part I am trying to make work is:

- alias: Set Decreasing Charging current
  if:
  - condition: state
    entity_id: !input ems_charger_status
    state: 'charging'
    for: 
        hours: 0
        minutes: 2
        seconds: 00
  - condition: template
    value_template: '{{ currentAvailableCharging < ChargerCurrent }}'
    alias: Below Charging current
#    for: 
#    hours: 0
#    minutes: 1
#    seconds: 00
  then:
  - action: number.set_value
    metadata: {}
    data:
      value: '{{ ChargerCurrentMinOne }}'
    target:
      entity_id: !input ems_charger_current
    alias: Set Decreasing Current
  else: []
  enabled: true

My updated blueprint starting from https://github.com/gsaurer/ha-ems is:

blueprint:
  name: '[EMS] - [Car] - [Charging automation] - [Surplus] - Current-Start-Stop'
  description: This script provides 3 different types of chaging (Default, Trip &
    Surplus) and adopts the settings of the charger settings accordingly. In this
    scenario the go-e Charger was used but the automation can be used for other chargers
    asw well as it is generic.
  domain: automation
  source_url: https://raw.githubusercontent.com/gsaurer/ha-ems/main/blueprints/EMS-Car-Charging-Surplus.yaml
  input:
    ems_enabled:
      name: EMS - Enabled
      description: Switch that defines if the Energy Managment system should be turned
        on. It's the main switch for your EMS systm. If you don't have one create
        a new one directly in the blueprint. Turning it off this will disable this
        automation.
      selector:
        entity:
          domain:
          - input_boolean
          multiple: false
    ems_charging_type:
      name: Charging type
      description: This defines which type of charging should be used - Potential
        values of this entity are (default, surplus, trip, stop). If you don't have
        this entity create it directly in the blueprint and add it to your it to your
        dashboard to select what charging type you want.
      selector:
        entity:
          filter:
          - domain:
            - input_select
          multiple: false
    ems_charger_current:
      name: Charger - Requested current
      description: The current value of the charger
      selector:
        entity:
          filter:
          - domain:
            - number
          multiple: false
    ems_charging_power:
      name: Charger - charging power use
      description: The charging power use of the charger
      selector:
        entity:
          filter:
          - domain:
            - sensor
          multiple: false
    ems_charger_status:
      name: Charger - current status
      description: The current status of the charger
      selector:
        entity:
          filter:
          - domain:
            - sensor
          multiple: false
    ems_charger_forced_state:
      name: Charger - Forced state
      description: Defines the forced on off state of the charger - wether it is off (netural)
        or it is on (should start charging).
      selector:
        entity:
          filter:
          - domain:
            - switch
          multiple: false
    ems_surplus_potential_power_mean:
      name: Surplus - potential power (mean)
      description: Defines the potential power that is available for car charging.
        For that create a helper sensor that calculates the value based on your Perference.
        It is  recommended to leverage the ha-average  integration and create an average
        value (5min) for the current avaialble energy to smooth peaks.
      selector:
        entity:
          domain:
          - sensor
          multiple: false
    ems_grid_potential_power_draw:
      name: Surplus - absorbed power (mean)
      description: Defines the absorbed power that is drawn from the grid.
        For that create a helper sensor that calculates the value based on your Perference.
        It is  recommended to leverage the ha-average  integration and create an average
        value (5min) for the current absorbed energy to smooth peaks.
      selector:
        entity:
          domain:
          - sensor
          multiple: false
    ems_surplus_max_power_from_grid:
      name: Surplus - Max power from grid
      description: Defines how much power should be used from the grid for surplus
        charging at a maximum. Best practice is to set it to ~50 W to smooth the charging
      default: 1000
      selector:
        number:
          min: 0.0
          max: 4000.0
          unit_of_measurement: W
          step: 1.0
          mode: slider
    ems_surplus_min_power_available:
      name: Surplus - Min power available to start
      description: Defines the minimum power that needs to be avaialble to start the
        surplus charging. This depends on your car what is the minimum charging W
        it can use as well as how much you want to charge using the grid. If your
        car can start with 6A set it to 1000 W (start a bit earlier instead of 1380W)
      default: 1000
      selector:
        number:
          min: 0.0
          max: 5600.0
          unit_of_measurement: W
          step: 1.0
          mode: slider
variables:
  ems_charging_type: !input ems_charging_type
  ems_charger_status: !input ems_charger_status
  ems_charging_power: !input ems_charging_power
  ems_charger_current: !input ems_charger_current
  ems_surplus_potential_power_mean: !input ems_surplus_potential_power_mean
  ems_grid_potential_power_draw: !input ems_grid_potential_power_draw
  ems_surplus_max_power_from_grid: !input ems_surplus_max_power_from_grid
  ems_surplus_min_power_available: !input ems_surplus_min_power_available
triggers:
- trigger: time_pattern
  seconds: /25
conditions:
- condition: state
  entity_id: !input ems_enabled
  state: 'on'
- condition: state
  entity_id: !input ems_charging_type
  state: surplus
- not:
    - condition: state
      entity_id: !input ems_charger_status
      state: 'no_ev_connected'
actions:
- variables:
    minCurrentToCharge: '{{ 6 }}'
    maxCurrentToCharge: '{{ 10 }}'
    powerAvailable: '{{ states(ems_surplus_potential_power_mean) | int(0) - states(ems_grid_potential_power_draw) | int(0) + ems_surplus_max_power_from_grid
      | int(0) }}'
    powerChargingNow: '{{ states(ems_charging_power) | int(0) }}'
    powerAbsorbed: '{{ states(ems_grid_potential_power_draw) | int(0) }}'
    ChargerCurrent: '{{ states(ems_charger_current) | int(0) }}'
    ChargerCurrentPlusOne: '{{ states(ems_charger_current) | int(0) + 1 }}'
    ChargerCurrentMinOne: '{{ states(ems_charger_current) | int(0) - 1 }}'
    powerAvailableCharging: '{{ states(ems_surplus_potential_power_mean) | int(0) + states(ems_charging_power) | int(0) - states(ems_grid_potential_power_draw) | int(0) + ems_surplus_max_power_from_grid
      | int(0) }}'
    minPowerToCharge: '{{ ems_surplus_min_power_available }}'
    currentAvailable: '{{ [[ (powerAvailable) // 690, minCurrentToCharge] | max, maxCurrentToCharge]
      | min }}'
    currentAvailableCharging: '{{ [[ (powerAvailableCharging) // 690, minCurrentToCharge] | max, maxCurrentToCharge]
      | min }}'
- alias: Set increasing Charging current
  if:
  - condition: state
    entity_id: !input ems_charger_status
    state: 'charging'
    for: 
        hours: 0
        minutes: 2
        seconds: 00
  - condition: template
#  - condition: numeric_state
#  - condition: '{{ currentAvailableCharging > ChargerCurrent }}'
    value_template: '{{ currentAvailableCharging > ChargerCurrent }}'
#    entity_id: currentAvailableCharging
#    above: ChargerCurrent
    alias: Above Charging current
#    for: 
#    hours: 0
#    minutes: 1
#    seconds: 00
  then:
  - action: number.set_value
    metadata: {}
    data:
      value: '{{ ChargerCurrentPlusOne }}'
    target:
      entity_id: !input ems_charger_current
    alias: Set increasing Current
  else: []
  enabled: true
- alias: Set Decreasing Charging current
  if:
  - condition: state
    entity_id: !input ems_charger_status
    state: 'charging'
    for: 
        hours: 0
        minutes: 2
        seconds: 00
  - condition: template
    value_template: '{{ currentAvailableCharging < ChargerCurrent }}'
    alias: Below Charging current
#    for: 
#    hours: 0
#    minutes: 1
#    seconds: 00
  then:
  - action: number.set_value
    metadata: {}
    data:
      value: '{{ ChargerCurrentMinOne }}'
    target:
      entity_id: !input ems_charger_current
    alias: Set Decreasing Current
  else: []
  enabled: true
- alias: Set minimum charging current
  if:
  - not:
    - condition: state
      entity_id: !input ems_charger_status
      state: 'charging'
      for: 
          hours: 0
          minutes: 2
          seconds: 00
  then:  
  - action: number.set_value
    metadata: {}
    data:
      value: '{{ minCurrentToCharge }}'
    target:
      entity_id: !input ems_charger_current
    alias: Set Minimum Current
  else: []
  enabled: true
- alias: Stop charging below minPowerToCharge
  if:
  - condition: template
    value_template: '{{ powerAvailableCharging < minPowerToCharge }}'
    alias: Below minPowerToCharge
  then:
  - action: switch.turn_off
    metadata: {}
    target:
      entity_id: !input ems_charger_forced_state
    alias: Stop Charging
  else: []
  enabled: true
- alias: Start charging above minPowerToCharge
  if:
  - condition: template
    value_template: '{{ powerAvailable > minPowerToCharge }}'
    alias: Above minPowerToCharge
  - not:
    - condition: state
      entity_id: !input ems_charger_status
      state: 'charging'
      alias: Not charging
  then:
  - action: switch.turn_on
    metadata: {}
    target:
      entity_id: !input ems_charger_forced_state
    alias: Start first charging
  - action: number.set_value
    metadata: {}
    data:
        value: '{{ minCurrentToCharge }}'
    target:
        entity_id: !input ems_charger_current
    alias: Set Current at Start
  else:
   if:
   - condition: template
     value_template: '{{ powerAvailable > minPowerToCharge }}'
     alias: Above minPowerToCharge
   then:
   - action: switch.turn_on
     metadata: {}
     target:
       entity_id: !input ems_charger_forced_state
     alias: Start charging
   else: []
  enabled: true
mode: single

These variables you created as !inputs and then as variables don’t have states, They are variables…
So this where you try to change them into variables another time:

are meaningless. They will show as 0 using the default in the integer conversion attempt.

Thank you for your reply.
When I trace the automation the variables all work well:

minCurrentToCharge: 6
maxCurrentToCharge: 10
powerAvailable: 722
powerChargingNow: 4123
powerAbsorbed: 0
ChargerCurrent: 6
ChargerCurrentPlusOne: 7
ChargerCurrentMinOne: 5
powerAvailableCharging: 4845
minPowerToCharge: 4140
currentAvailable: 6
currentAvailableCharging: 7

The issue with the automation is that it changes the current to fast. I woul like to wait a bit before (or after) changing the current for the average supplied or absorbed power (in total for the house) to follow. If there is no waiting time, the automation changes the current again when it runs the next time, before the average consumed power has changed enough.
But I need the average of the power consumption, otherwise the charger current would change everytime a could comes past or when i make a coffee :slight_smile:

I found the sollution:

 - alias: Set increasing Charging current
    if:
      - condition: state
        entity_id: sensor.peblar_ev_charger_status
        state: charging
        for:
          hours: 0
          minutes: 2
          seconds: 0
      - condition: template
        value_template: "{{ currentAvailableCharging > ChargerCurrent }}"
        alias: Above Charging current
    then:
      - delay:
          hours: 0
          minutes: 0
          seconds: 30
          milliseconds: 0
      - action: number.set_value
        metadata: {}
        data:
          value: "{{ ChargerCurrentPlusOne }}"
        target:
          entity_id: number.peblar_ev_charger_laadlimiet
        alias: Set increasing Current
    else: []
    enabled: true