How to setup aqara motion sensor to work better

hi ive got an automation to turn on the kitchen lights with an aqara zigbee motion sensor when it detects motion after sunset, all works good except the delay action seems to delay detection too, so after the light being on for 10 minutes it turns off even though somones walking about in front of the sensor.

Idealy id like it to continue to detect and reset the delay time to keep the light on longer, at present it detects and only stays on for 10 minutes ? any help much appreciated thanks

alias: martins ----- Kitchen lights motion activated after Sunset
description: martins automations
trigger:

  • type: motion
    platform: device
    device_id: 5ac12d4623e53be95a826b0a254d9027
    entity_id: binary_sensor.lumi_lumi_sensor_motion_aq2_iaszone
    domain: binary_sensor
    condition:
  • condition: sun
    after: sunset
    after_offset: “-01:00:00”
  • condition: or
    conditions:
    • condition: sun
      before: sunrise
    • condition: sun
      after: sunset
      after_offset: “-01:00:00”
      action:
  • type: turn_on
    device_id: 72dae107f1feb7b86ec2930033090646
    entity_id: light.shelly1_kitchen_lights
    domain: light
  • delay:
    hours: 0
    minutes: 10
    seconds: 0
    milliseconds: 0
  • type: turn_off
    device_id: 72dae107f1feb7b86ec2930033090646
    entity_id: light.shelly1_kitchen_lights
    domain: light
    mode: restart

A quick fix for this could be to set the mode for the automation to ‘restart’.

hi thanks but its already on restart ?

I’ve a similar automation for my media-player, which starts playing if motion is dedected and stops playing after 3 Minutes, if no motion is dedected. Action part of my automation is as follows:

  action:
  - service: media_player.turn_on
    target:
      entity_id: media_player.bad
  - wait_for_trigger:
    - platform: state
      entity_id: binary_sensor.motion_sensor
      to: 'off'
      for:
        hours: 0
        minutes: 3
        seconds: 0
  - service: media_player.turn_off
    target:
      entity_id: media_player.bad
  mode: restart

It works well for me. Maybe it helps you, too.