Automation Help - Add a delay before testing conditions

I am using the automation editor integration for writing my automatons. All is going well so far. However, I have now hit a blocker.

I am seeking to trigger an automation, wait 5 minutes before testing the conditions, and then initiate the action based on the conditions being met.

Where do I add the delay/ wait?

Here is the yaml the automation editor has created for me so far:

alias: Heating Night Mode
  description: ''
  trigger:
  - entity_id: binary_sensor.alarm_set_status_2
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - condition: state
    entity_id: person.john
    state: home
  - condition: or
    conditions:
    - condition: state
      entity_id: person.cath
      state: home
  - condition: or
    conditions:
    - condition: state
      entity_id: person.elizabeth
      state: home
  action:
  - data:
      hvac_mode: auto
      temperature: 16
    entity_id: climate.wiser_central_heating_zone
    service: climate.set_temperature
  - data:
      hvac_mode: auto
      temperature: 16
    entity_id: climate.wiser_lounge
    service: climate.set_temperature

I’ve searched the cookbooks and examples but can’t find anything that seems similar - specifically the delay before testing the location condition.

Thanks

John

you could try to replace

  - entity_id: binary_sensor.alarm_set_status_2
    from: 'off'
    platform: state
    to: 'on'

with

  - entity_id: binary_sensor.alarm_set_status_2
    from: 'off'
    platform: state
    to: 'on'
    for:
      minutes: 5
1 Like

by the way if you want to check that John OR Cath OR Elisabeth are home, this is how you should do it:

  condition:
  - condition: or
    conditions:
    - condition: state
      entity_id: person.john
      state: home
    - condition: state
      entity_id: person.cath
      state: home
    - condition: state
      entity_id: person.elizabeth
      state: home

Your current condition check that:

  • John is home OR [nothing]
    AND
  • Cath is home OR [nothing]
    AND
  • Elisabeth is home OR [nothing]

I see, thanks for this, I will test and report back,

Many thanks

John

Thanks, Ive corrected the incorrect use of OR.

To make things easier to test - I’ve set up a dummy automation to test the principle:

- id: '1584530593752'
  alias: AA Test automation of for
  description: ''
  trigger:
  - entity_id: ' switch.lounge_lamp'
    for: 'minutes: 2'
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - condition: state
    entity_id: person.john
    state: home
  action:
  - data: {}
    entity_id: switch.play_room_christmas_lights
    service: switch.turn_on

However, the action is never executed. John is home, and the switch.lounge_lamp has been left on for greater than 2 minutes. switch.play_room_christmas_lights never turns on. If I fire the automation manually then switch.play_room_christmas_lights does turn on.

Anything obviously wrong this time?

Many thanks

John

I think it’s the leading space - spotted my own error:

  - entity_id: ' switch.lounge_lamp'

Will confirm.

for: 'minutes: 2' is also incorrect. Note the format in lolouk44’s post.

for:
  minutes: 2

Alternatively:

for: '00:02:00'

This was the final piece to fix. Thanks for your help.

John

Glad it helped, but one of @lolouk44’s answers should really be marked as the solution since they provided the solution (and because I just restated something they already said).

2 Likes

Done, thanks for pointing that out.

John

1 Like

@truxntrax,
Glad you got it all sorted, note that your entity_id: does not need quoting and this ‘used’ to stop execution but the automation editor now seems to insert random quotes all over the place.
Also the time does need quoting as per Tediore’s post (though again, subject to the vagueuries of the editor).
To assist others searching for similar solutions can you please post your final working solution ?
It just ties everything up in a neat parcel :+1:

1 Like

@Mutt - no problem. To help anyone else who may need to see the complete automation here it is

- id: '1584391345377'
  alias: Heating Night Mode
  description: ''
  trigger:
  - entity_id: binary_sensor.alarm_set_status_2
    for: 00:04:00
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - condition: or
    conditions:
    - condition: state
      entity_id: person.john
      state: home
    - condition: state
      entity_id: person.cath
      state: home
    - condition: state
      entity_id: person.elizabeth
      state: home
  action:
  - data:
      hvac_mode: auto
      temperature: 16
    entity_id: climate.wiser_central_heating_zone
    service: climate.set_temperature
  - data:
      hvac_mode: auto
      temperature: 16
    entity_id: climate.wiser_lounge
    service: climate.set_temperature

Thanks all for assistance. The best automated house just does it’s thing. I am sure there will be some corner cases I will need to iron out, but for now, all is good.

John

1 Like