Enhance working automation

First of all. This solution works, but i want to review it and enhance it a little bit.
There is a small problem, that i would like te resolve as well.

The animation that i use now:

alias: Sensor Gangpad On Off
description: ""
trigger:
  - platform: state
    entity_id:
      - switch.switch_tuinverlichting_sensor
    to:
      - "on"
      - "off"
condition: []
action:
  - service: light.turn_{{ trigger.to_state.state }}
    target:
      entity_id: light.dimmer_gangpad
  - service: >-
      {% if is_state('input_boolean.TuinVerlichtingForceOn', 'off') %}
      light.turn_{{ trigger.to_state.state }}  {% else %} light.turn_on {% endif %} 
    target:
      entity_id: switch.switch_tuinverlichting
mode: restart
  • This automation triggers garden lights with a PIR sensor
  • The switch is only turned of if Input_boolean is in state off

This code works, but cannot be maintained by the visual editor.
Is that posible?

Als i have one small issue.
Somehow the PIR sensor triggers the light.dimmer_gangpad on-command when it’s dark enough.
But it does not receive a off-trigger.
So i would like to set a maximum on-state to switch.switch_tuinverlichting_sensor.
If the switch is ‘on’ for more then 5 minutes, turn it ‘off’

Im not sure how to achieve this, without messing up how it works now.
Any ideas?

Do you mean automation? (Instead of animation)

Sorry, yes that is what i mean.