Setting a conditional delay

Hello all,

I am new to HA and loving it so far. As I am getting into automation I have a few questions. I have an automation that turns on lights in the house if the front door is opened and after sunset. However I don’t want the lights to turn if they have been turned off in the last five minutes. Is this a possibility to do?

Something like this 90 sec condition but I don’t think you can use the switch itself as its last triggered as it is below. I think you need to put an script in the action part of the automation and use that last triggered as the condition.

automation 1:
  trigger:
    - platform: state
      entity_id: switch.xxxx
  condition:
    condition: template
    value_template: '{% if states.switch.xxx.attributes.last_triggered  %}{{(as_timestamp(now())-as_timestamp(states.switch.xxx.attributes.last_triggered)) > 90 }}{% else %}True{% endif %}'
  action:
    - service: homeassistant.turn_on
1 Like