Use of Automation state as condition for another Automation

Hi,

Playing around with one of my first automations and wanting to have the execution of one automation dependent on whether another is enabled. Searched for ages on the forum and couldn’t find an answer, and the following doesn’t appear to work:

- id: lights_night_sensor_on
  alias: 'Night light Sensor - 11pm to Dawn'
  trigger:
    platform: state
    entity_id:
      - binary_sensor.wemo_motion_kitchen
      - binary_sensor.wemo_motion_hallway
    from: 'off'
    to: 'on'
  condition:
    condition: or
    conditions:
      - condition: time
        after: '23:10:00'
      - condition: sun
        before: sunrise
  action:
    service: switch.turn_on
    entity_id:
      - switch.wemo_switch_dining
      - switch.wemo_switch_hallway

    - id: lights_night_sensor_2min_off
      alias: 'Night light Sensor - 2mins off'
      hide_entity: True
      trigger:
        platform: state
        entity_id:
          - binary_sensor.wemo_motion_kitchen
          - binary_sensor.wemo_motion_hallway
        from: 'on'
        to: 'off'
        for:
          minutes: 2
      condition:
        - condition: state
          entity_id: automation.lights_night_sensor_on
          state: 'on'
      action:
        service: switch.turn_off
        entity_id:
          - switch.wemo_switch_dining
          - switch.wemo_switch_hallway

The lights turn on with motion detection, and without the automation condition on the light off after 2 mins automation, it fires fine. With the condition set, nothing happens. I only want it to turn the lights off after 2 minutes if the automation to turn them on with the sensor is actually active.

The use of the automation state seems to be false in the automation, even though its enabled.

The whole ‘Night light Sensor - 2mins off’ automation needs to shift four spaces to the left

In addition to what @tom_l pointed out with the spacing issue, I think you have the wrong idea about automations being “on”. An automation that is on doesn’t mean it’s running, it means it’s enabled to run.

So the way you’d want to do it is use an input_boolean. First make one called “input_boolean.night_light”. On your first automation, have an action to turn input_boolean.night_light to turn on.

In your second automation, use a condition that only runs if input_boolean.night_light is on and then add an action at the end to turn the input_boolean off.

Basically, you are just creating a “sensor” that tells your second automation to only run if the first one was triggered before it.

Alternatively, (actually this is way easier) just keep the first Automation And at the end of the action add a delay for 2 minutes and then turn the switches off.

Great thanks, should have thought of the delay; using one automation to turn on and one to turn off seemed excessive.