How to stop 2nd action in automation under certain conditions

I have an automation which turns on the light in hallway when the front door opens and after 5 minutes it turn it off. How can I prevent it from turning off when it is me, that comes home?

- id: '1548545104415'
  alias: Prizgi luč v predsobi, ko se odprejo vhodna vrata, če je temno.
  trigger:
  - entity_id: binary_sensor.vhodna_vrata
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - below: '5'
    condition: numeric_state
    entity_id: sensor.predsoba_illuminance
  action:
  - data: {}
    entity_id: light.pred_soba
    service: light.turn_on
  - delay: 00:05:00
  - data: {}
    service: light.turn_off

What is the entity id of the sensor that detects you are home?

I am using bluetooth presence.

What is the entity_id ?

Probably this:
entity_id: person.peter

If that is your entity you can do something like this:

- id: '1548545104415'
  alias: Prizgi luč v predsobi, ko se odprejo vhodna vrata, če je temno.
  trigger:
  - entity_id: binary_sensor.vhodna_vrata
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - below: '5'
    condition: numeric_state
    entity_id: sensor.predsoba_illuminance
  action:
  - data: {}
    entity_id: light.pred_soba
    service: light.turn_on
  - delay: 00:05:00
  - condition:
      entity_id: 'person.peter'
      state: 'not_home'
  - data: {}
    service: light.turn_off

You may need to adjust the state for what it should be but that is close to what you need. There is documentation on this here. The one thing to remember is that any action placed after the condition will not execute. Also this won’t 100% solve the problem because if you are home and someone else opens the door the light will remain on. Since your trigger isn’t your person arriving home it will be difficult to track “who” opened the door and when to turn the light off after 5 mins.

1 Like

Thanks, but there seems to be a problem, I get the following error:
Invalid config for [automation]: [condition] is an invalid option for [automation]. Check: automation->action->2->condition. (See /config/configuration.yaml, line 140). Please check the docs at https://home-assistant.io/components/automation/
As for the other part, it really isn’t a problem since this light is mostly always turned on when I am at home, but thanks for pointing it out.

It was missing the condition type. Try this:

  action:
  - data: {}
    entity_id: light.pred_soba
    service: light.turn_on
  - delay: 00:05:00
  - condition: state
    entity_id: 'person.peter'
    state: 'not_home'
  - data: {}
    service: light.turn_off
1 Like

Thanks, that fixed the error.