Script for Reaction Delayed "no motion detected"

Hi all.

I need some help with this. I’m one of these guys that have a little bit of knowledge, just enough to try and look for code I need and then paste it together. Most of the time it works, but of course, if I need to do troubleshooting my lack becomes apparent.

So I got this piece of script here, to get my lights to switch on and off, if there is motion. But as long as new motion is being detected it stays on, it’ll switch of after no motion detected for x seconds.

I want to use this for other places. But once it’s going to be a lightswitch, another time a zigbee lamp, another time a door that will close and so on.

alias: Bathroom switch on off
description: ""
trigger:
  - type: occupied
    platform: device
    device_id: 5398f8e759e8c73728e3760be72b080b
    entity_id: binary_sensor.signify_netherlands_b_v_sml003_occupancy
    domain: binary_sensor
  - type: not_occupied
    platform: device
    device_id: 5398f8e759e8c73728e3760be72b080b
    entity_id: binary_sensor.signify_netherlands_b_v_sml003_occupancy
    domain: binary_sensor
    for:
      seconds: 10
action:
  - service: light.turn_{{ trigger.to_state.state }}
    target:
      entity_id: light.lightswitch_toilet_eg_light
mode: single

So if I want to use this, I need to know to change these things, correct?
type: occupied: Here I need to know what the stat is I’m looking for. Motion detected, cleared, person detected and so on?

service: light.turn_{{ trigger.to_state.state }}
What do I need to change this to? It says to_state…state… I don’t understand how this script knows what it has to toggle. Where does it say, what the two states are, ON/OFF or 0/1 and so on?
or do I not get how this works?
target:
well here I simply put the entity of the light I want to use.

I just am struggling to get this to work with
=> eufy cam switches to person detected
=> Govee Floodlight on
=> eufy cam switches stopped detecting
=> wait x seconds
=> Govee Floodlight off