Auto Entity filter card how do i show any with x minutes

Please can someone help, i have some basic coding but new to home assistant and yaml .
I have created a auto entity card for my dashboard with only shows sensors that are currently occupied or detecting motion . however ive been trying to do this for weeks and gotten nowhere, i would like it so it also shows any which have been on in last 5 minutes and any which currently show motion, i would really love the help , this is current code, thanks

type: entity-filter
entities:
  - entity: binary_sensor.bathroom_sensor_motion
    name: "Bathroom Sensor: Motion"
    secondary_info: last-changed
  - entity: binary_sensor.hallway_sensor_motion
    name: "Hallway Sensor: Motion"
    secondary_info: last-changed
  - entity: binary_sensor.kitchen_ceiling_presence_sensor_occupancy
    name: "Kitchen ceiling : presence "
    secondary_info: last-updated 
  - entity: binary_sensor.office_ceiling_presence_sensor_occupancy
    name: "Office Ceiling: Presence"
    secondary_info: last-changed
conditions:
  - condition: state
    state: "on"

card:
  type: entities
  title: Motion Sensors test
  state_color: true

You need a custom card called Auto Entities. It is very similar to the entities-filter card, just a bit more powerful and flexible. Download and install it from HACS.

Create a legacy group of the sensors you want to track.

Don’t forget to reload your groups from Developer Tools!

group:
  motion_sensors:
      entities:
        - binary_sensor.bathroom_sensor_motion
        - binary_sensor.hallway_sensor_motion
        - binary_sensor.hallway_sensor_motion
        - binary_sensor.kitchen_ceiling_presence_sensor_occupancy
        - binary_sensor.office_ceiling_presence_sensor_occupancy

Using the Auto Entities card with the following template filter will give you a list all the sensors in your motion_sensors group that are either on, or have changed in the last 5 minutes.

type: custom:auto-entities
title: "Active Motion Sensors"
show_empty: true
filter:
  template: >
    {% set recent = expand('group.motion_sensors')
        | selectattr('last_changed', '>', now() - timedelta(minutes=5))
        | map(attribute='entity_id') | list %}

    {% set active = expand('group.motion_sensors')
        | selectattr('state', 'eq', 'on')
        | map(attribute='entity_id') | list %}

    {{ recent + active }}
sort:
  method: last_changed 
  reverse: true
  ignore_case: true
card:
  type: entities

Anybody has a more efficient way to structure that template, lay it on me!

Have not checked the whole code, but the “template” option must be indented.

Yep. Nice catch. Fixed.