- id: forgang_motion_lys
  alias: Forgang lys via bevægelse
  mode: restart

  trigger:
    - platform: state
      entity_id: binary_sensor.forgang_bevaegelse
      to: "on"

  condition:
    - condition: numeric_state
      entity_id: sensor.forgang_sensor_illuminance
      below: 60

  action:
    - choose:
        - conditions:
            - condition: time
              after: "06:00:00"
              before: "23:59:00"
          sequence:
            - service: scene.turn_on
              target:
                entity_id: scene.forgang_bright
      default:
        - service: scene.turn_on
          target:
            entity_id: scene.forgang_dimmed

- id: forgang_motion_sluk_dag
  alias: Sluk forgang lys efter 10 min uden bevægelse
  mode: restart

  trigger:
    - platform: state
      entity_id: binary_sensor.forgang_bevaegelse
      to: "off"

  condition:
    - condition: time
      after: "06:00:00"
      before: "23:59:00"

  action:
    - wait_for_trigger:
        - platform: state
          entity_id: binary_sensor.forgang_bevaegelse
          to: "on"
      timeout: "00:10:00"
      continue_on_timeout: true
    - condition: state
      entity_id: binary_sensor.forgang_bevaegelse
      state: "off"
    - service: light.turn_off
      target:
        entity_id: light.forgang

- id: forgang_motion_sluk_nat
  alias: Sluk forgang lys efter 5 min uden bevægelse om natten
  mode: restart

  trigger:
    - platform: state
      entity_id: binary_sensor.forgang_bevaegelse
      to: "off"

  condition:
    - condition: or
      conditions:
        - condition: time
          before: "06:00:00"
        - condition: time
          after: "23:59:00"

  action:
    - wait_for_trigger:
        - platform: state
          entity_id: binary_sensor.forgang_bevaegelse
          to: "on"
      timeout: "00:05:00"
      continue_on_timeout: true
    - condition: state
      entity_id: binary_sensor.forgang_bevaegelse
      state: "off"
    - service: light.turn_off
      target:
        entity_id: light.forgang
