Motion Sensor + Illuminance Sensor = No switch off if brighness > trigger value

Hi, I am trying to control my lights with a motion sensor. That works fine. But I only want to switch them on if a given threshold of illuminance is reached.
That also works fine. But here is the issue:
The lights don’t switch of if the (in the morning) the measured value goes over the programmed value during the “switch on time”.
The automation works “as coded” but I don’t know how to move the scope of the illuminance value.

alias: Licht Keller Flur LED-Streifen
description: ""
triggers:
  - type: occupied
    device_id: f1602f0a146f616fe84d3837d750c1ff
    entity_id: e9e2b290ec6ff993366ca14903567d2b
    domain: binary_sensor
    trigger: device
    id: motion-detected
  - type: not_occupied
    device_id: f1602f0a146f616fe84d3837d750c1ff
    entity_id: e9e2b290ec6ff993366ca14903567d2b
    domain: binary_sensor
    trigger: device
    id: no-motion-detected
    for:
      hours: 0
      minutes: 2
      seconds: 0
conditions:
  - type: is_illuminance
    condition: device
    device_id: 242de123895a921842968af27c738320
    entity_id: 6bbf1ad7dd1a973dd3823e588b6b2652
    domain: sensor
    below: 500
actions:
  - if:
      - condition: trigger
        id: motion-detected
      - condition: time
        after: "22:00:00"
        before: "07:00:00"
    then:
      - type: turn_on
        device_id: 08f40ebf16ab7c1f92edc1b32a7cb08e
        entity_id: dba6d11c1a313cd6496a480185db031b
        domain: light
        brightness_pct: 1
  - if:
      - condition: trigger
        id: motion-detected
      - condition: time
        after: "07:00:00"
        before: "22:00:00"
    then:
      - type: turn_on
        device_id: 08f40ebf16ab7c1f92edc1b32a7cb08e
        entity_id: dba6d11c1a313cd6496a480185db031b
        domain: light
        brightness_pct: 80
  - if:
      - condition: trigger
        id:
          - no-motion-detected
    then:
      - type: turn_off
        device_id: 08f40ebf16ab7c1f92edc1b32a7cb08e
        entity_id: dba6d11c1a313cd6496a480185db031b
        domain: light
mode: single

I appreciate any help.

Thank,
Matthias

Move your automation illuminance condition to an if statement before you call turn_on. That way you always reach the turn_off call when the occupancy detector turns off.

I use trigger ID’s a lot like this

triggers:
  - entity_id:
      - binary_sensor.shop_presence_sensor_occupancy
    from: "on"
    to: "off"
    for:
      minutes: 2
    trigger: state
    id: "off"
  - entity_id:
      - binary_sensor.shop_presence_sensor_occupancy
    to: "on"
    trigger: state
    id: "on"
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - "on"
          - type: is_occupied
            condition: device
            device_id: e10426e471628b4953658f68571a57d3
            entity_id: 7c34528c5ed09bbddde21f91923b6828
            domain: binary_sensor
          - condition: time
            after: "08:00:00"
            before: "11:00:00"
        sequence:
          - type: turn_on
            device_id: 8adad466b1f3b9748b25a8fb964ecdde
            entity_id: e371e583be733432b6bdf39cdfe4a207
            domain: light
      - conditions:
          - condition: trigger
            id:
              - "off"
        sequence:
          - type: turn_off
            device_id: 8adad466b1f3b9748b25a8fb964ecdde
            entity_id: e371e583be733432b6bdf39cdfe4a207
            domain: light
mode: single

Makes it easy to provide a different set of conditions to each trigger.

Thanks, that was easy. I’m still learning how to wrap logic around other logic in the HA-Configurations.