Light Automation not stable. Please help

I am using 3 Philips Hue outside lights which turn on at sun set at 30% with a warm color and turn of at midnight. I also have 2 Philips Hue outside motion sensors (one at the side of the house and one at the rear. They don’s see each other). I made an automation where the lights, when detected motion during 22:00 and 08:00 turn on to 100% bright white. After 5 sec of no motion they return to previous state using temporary scene. So before midnight that would be 30% warm color and after midnight they should go out.
The problem I have is that this seems to be working but every other day or so I wake up and the outside lights are on 100% white. When I check the camera’s I can see they have been on for several hours. So they don’t return to there formar state.
I am using an intel nuc with home assistant installed
I am pretty new to this and tried trouble shooting this in traces and stuff but can’t seem to find it.
Can anyone help me check the code or with some advise ?
These are the two automations.

alias: Lights outside sfeer
description: ""
trigger:
  - platform: state
    entity_id:
      - sun.sun
    to: below_horizon
    id: Sunset
  - platform: time
    at: "23:59:00"
    id: Time to turn off
condition: []
action:
  - if:
      - condition: trigger
        id:
          - Sunset
    then:
      - service: light.turn_on
        target:
          entity_id: light.outside_lights
        data:
          brightness_pct: 30
          rgb_color:
            - 255
            - 198
            - 119
    else:
      - service: light.turn_off
        target:
          entity_id: light.outside_lights
        data: {}
mode: single
alias: >-
  Outside lights temporarely to 100% when motion detected then set to previous
  state
description: ""
trigger:
  - type: occupied
    platform: device
    device_id: 6cd2d64dd26610218454dd48429a6650
    entity_id: 8274c92b4f63355155b175e6d83b2192
    domain: binary_sensor
    id: Motion detected side
  - type: occupied
    platform: device
    device_id: 61a51105ed7a16d7d2d33dd440ae9bd4
    entity_id: f87eb4fc08b0f6efd80fbfa06ed40c22
    domain: binary_sensor
    id: Motion detected rear
  - type: not_occupied
    platform: device
    device_id: 6cd2d64dd26610218454dd48429a6650
    entity_id: 8274c92b4f63355155b175e6d83b2192
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 5
  - type: not_occupied
    platform: device
    device_id: 61a51105ed7a16d7d2d33dd440ae9bd4
    entity_id: f87eb4fc08b0f6efd80fbfa06ed40c22
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 5
condition:
  - condition: time
    after: "22:00:00"
    before: "08:00:00"
action:
  - if:
      - condition: trigger
        id:
          - Motion detected side
          - Motion detected rear
    then:
      - service: scene.create
        data:
          scene_id: before
          snapshot_entities:
            - light.light_hue_outside_1_light
            - light.light_hue_outside_2_light
            - light.light_hue_outside_3_light
      - service: light.turn_on
        data:
          color_name: white
          brightness_pct: 100
        target:
          entity_id:
            - light.light_hue_outside_1_light
            - light.light_hue_outside_2_light
            - light.light_hue_outside_3_light
    else:
      - service: scene.turn_on
        target:
          entity_id: scene.before
        data: {}
mode: single

From a quick glance: whenever there is another motion within the 5 seconds it will create a before scene based on the 100% white lights.
You will need to use a helper or something else to not trigger the scene.create when the motion is still active. Otherwise it will override the stored value with the 100% white value.

Ah thx. That sounds very logical.
I just tested this by changing the condition time for the current time and limit only to the side sensor (my wife is in busy in the graden behind the house). But when I walk outside for 30 sec the lights turn on and stay on but when I enter the house so no motion is detected they turn off. Why is it working now??

alias: >-
  Outside lights temporarely to 100% when motion detected then set to previous
  state
description: ""
trigger:
  - type: occupied
    platform: device
    device_id: 6cd2d64dd26610218454dd48429a6650
    entity_id: 8274c92b4f63355155b175e6d83b2192
    domain: binary_sensor
    id: Motion detected side
  - type: occupied
    platform: device
    device_id: 61a51105ed7a16d7d2d33dd440ae9bd4
    entity_id: f87eb4fc08b0f6efd80fbfa06ed40c22
    domain: binary_sensor
    id: Motion detected rear
  - type: not_occupied
    platform: device
    device_id: 6cd2d64dd26610218454dd48429a6650
    entity_id: 8274c92b4f63355155b175e6d83b2192
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 5
  - type: not_occupied
    platform: device
    device_id: 61a51105ed7a16d7d2d33dd440ae9bd4
    entity_id: f87eb4fc08b0f6efd80fbfa06ed40c22
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 5
condition:
  - condition: time
    after: "12:00:00"
    before: "08:00:00"
action:
  - if:
      - condition: trigger
        id:
          - Motion detected side
    then:
      - service: scene.create
        data:
          scene_id: before
          snapshot_entities:
            - light.light_hue_outside_1_light
            - light.light_hue_outside_2_light
            - light.light_hue_outside_3_light
      - service: light.turn_on
        data:
          color_name: white
          brightness_pct: 100
        target:
          entity_id:
            - light.light_hue_outside_1_light
            - light.light_hue_outside_2_light
            - light.light_hue_outside_3_light
    else:
      - service: scene.turn_on
        target:
          entity_id: scene.before
        data: {}
mode: single

Very strange.
I had my dogs outside when typing my response and now the lights do stay on even when no motion detected!
spooky stuff

Maybe because I did not disable the rear motion sensor triggers. I just did. try again.

Yes. now it is Turing of again when no motion detected.
Can you help me with the code you suggested? I have been looking at the helpers but no clue which one to take or set it up.
Maybe adding this code will make it more stable.