Configuring Ikea Vallhorn working with Tradfri light

Hi!
I am just starting with Home Assistant and as a first step I try to set up an Ikea Vallhorn motion sensor and an Ikea Tradfri light bulb. I got both of them paired and set up two automations, one turning the light on and one turning it off. What I do not understand is how to set the duration the light stays on. I see the following settings:
The light has a on/off transition time which currently is set to 5 (unit of measure not disclosed).
The motion sensor has an activation time set to 32 seconds.
The on-automation (done with a blueprint) has a wait time of 95 seconds.

What actually happens is that the light goes on, stays on for roughly 20 seconds and then turns off.

I have see a similar question here:
https://community.home-assistant.io/t/help-needed-vallhorn-motion-sensor-and-tradfri-light-setup-issue-zigbee/816036/5

Yes, I am using the occupancy attribute.

I have also seen this post:
https://community.home-assistant.io/t/ikea-vallhorn-set-off-delay-and-dark-only-mode-with-zha-toolkit/815490/6
which makes me worry how much flexibility concerning the configuration is possible.

How do I set the time for which the lamp will stay on after the last detected motion?

Thank you for your help!!

motion and occupancy/presence are different timings.

motion generally stops quickly, occupancy (on the vallhorn) is either of the 2 defined delays from last loss of motion.

here is how I have my vallhorn/lights automated; I don’t use separate off/on, but I suppose could be split up similarly.

  • detect occupancy
  • turn on desired lights
  • wait for occupancy cleared for however long desired
  • turn off lights
alias: Laundry Motion Lights
description: ""
triggers:
  - type: occupied
    device_id: 2950bf4de6ef6e49a19308883e09ea4d
    entity_id: 31c89a0b6a3a91ffffb05dffe68b5cf7
    domain: binary_sensor
    trigger: device
conditions: []
actions:
  - action: light.turn_on
    metadata: {}
    data:
      brightness_pct: 100
    target:
      area_id:
        - laundry
  - action: light.turn_on
    metadata: {}
    data:
      brightness_pct: 100
      transition: 10
    target:
      device_id: 7405804a94ef5e412dcafe5647ada2ea
  - action: switch.turn_on
    metadata: {}
    data: {}
    target:
      area_id: laundry
  - wait_for_trigger:
      - type: not_occupied
        device_id: 2950bf4de6ef6e49a19308883e09ea4d
        entity_id: 31c89a0b6a3a91ffffb05dffe68b5cf7
        domain: binary_sensor
        trigger: device
        for:
          hours: 0
          minutes: 4
          seconds: 0
      - type: not_occupied
        device_id: 31b4a852a01d0918f4c722efab915b53
        entity_id: 580234a06249db27247c2c882ea284b7
        domain: binary_sensor
        trigger: device
        for:
          hours: 0
          minutes: 0
          seconds: 30
        enabled: false
    timeout:
      hours: 0
      minutes: 30
      seconds: 0
      milliseconds: 0
    continue_on_timeout: true
  - action: switch.turn_off
    metadata: {}
    data: {}
    target:
      area_id: laundry
  - action: light.turn_off
    metadata: {}
    data:
      transition: 30
    target:
      area_id:
        - laundry
  - action: light.turn_off
    metadata: {}
    data:
      transition: 60
    target:
      device_id: 7405804a94ef5e412dcafe5647ada2ea
mode: restart

Thank you for providing your setup! The questions I have are:

In the “wait for trigger” section you have a “for: 4 minutes”. What does that do exactly? Does it wait for four minutes and then checks if occupancy has been cleared? Or does it wait for 4 minutes after occupancy has been cleared and then turns the light off?
In the same section you have a “timeout:” set to “minutes: 30”. What does that to? Does it turn off the lamp latest after 30 minutes of not receiving a “type: not_occupied” event?
And in the third section for “light.turn_off” you have data:transition: 60. What does that do?

the 4 minutes is after the occupancy clears so basically the light stays on for the combination for the innate occupancy delay clearing and the 4 minute wait delay.

the 30 second entry is for a disabled occupancy check on a near by motion sensor (hallway outside laundry) so it can be ignored.

occupancy > light on > however long occupancy is maintained > occupancy cleared for 4 minutes > turn off lights

the timeout is an option in ‘wait for trigger’ function, so that if for some reason the occupancy never clears, the ‘wait for’ section will continue and shut off the lights. its an optional failsafe for triggers that may run indefinitely.

the light off transition fades out the lights over 60 seconds, so if for some reason one is standing still in the laundry for ~4 minutes, the light will start dimming instead of just going instantly dark.

hope that helps