Checking if state has been triggered by an automation, how?

Hi,
I have these two basic automations, one to turn light on and one off :

- alias: Turn on bryggers light when there is movement
  trigger:
    platform: state
    entity_id: binary_sensor.motion_office
    to: 'on'
  condition:
    condition: sun
    after: sunset
    after_offset: "-2:30:00"
  action:
    service: light.turn_on
    entity_id: light.bryggers

- alias: Turn off bryggers light 2 minutes after last movement
  trigger:
   platform: state
   entity_id: binary_sensor.motion_office
   to: 'off'
   for:
     minutes: 2
  condition:
    condition: sun
    after: sunset
    after_offset: "-2:30:00"
  action:
    service: light.turn_off
    entity_id: light.bryggers

My question is, is there a way to know if the automation when i turn off the light has been started by a motion e.g the automation before ?

1 Like

states.automation.Turn_on_bryggers_light_when_there_is_movement.attributes.last_triggered

You could also use an input_boolean, that you turn on when you turn it on with the automation, and have a second automation that always turns it off when the light turns off (regardless of why).