Conditional trigger on MQTT payload

Hi - i have been scanning around for some hints on extracting a dict item from a json payload for a trigger.

Use case is to switch on a light for 5mins if motion is detected from a camera
The motion data source is MQTT from KIOS the payload is

{"regionCoordinates":[960,90,1073,413],"numberOfChanges":58,"pathToVideo":"1635183826_5-74409_Backdoor_926-297-1006-468_299_968.mp4","name":"Backdoor","timestamp":"1635183828","microseconds":"6-788969","token":952}

the item i’m looking for is ‘numberOfChanges’ and the trigger should happen if ‘numberOfChanges’ > 1000

the yaml i have in HA is

alias: Turn on front arch light if camera motion detected
description: ''
trigger:
  - platform: mqtt
    topic: kios/drive
    payload: '{{ trigger.payload_json.numberOfChanges > 1000}}'
condition:
  - condition: sun
    before: sunrise
    after: sunset
action:
  - service: switch.turn_on
    target:
      entity_id: switch.esp_d04edd_2
  - delay:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  - service: switch.turn_off
    target:
      entity_id: switch.esp_d04edd_2
mode: single

I’m getting the error in HA

ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'trigger' is undefined when rendering '{{ trigger.payload_json.numberOfChanges > 1000}}'

having looked a a few other examples,i have also tried

'{{ trigger.payload_json['numberOfChanges'] > 1000}}'

i also tried changing the operator to == null , but the same error persists.
I have recently switched from OH to HA. So this is bound to be a noobie question… any help would be much appreciated. Thx.

Remove the payload from your trigger and add it as a condition.

Thanks @francisp - appreciate the pointer.
Revised code is now:

alias: Turn on front arch light if camera motion detected
description: ''
trigger:
  - platform: mqtt
    topic: kios/drive
condition:
  - condition: sun
    after: sunset
    before: sunrise
  - condition: template
    value_template: '{{ trigger.payload_json.numberOfChanges > 1000}}'
action:
  - service: switch.turn_on
    target:
      entity_id: switch.esp_d04edd_2
  - delay:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  - service: switch.turn_off
    target:
      entity_id: switch.esp_d04edd_2
mode: single