- id: kontor_motion_lys
  alias: Kontor lys via bevægelse
  mode: restart

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

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

  action:
    - service: scene.turn_on
      target:
        entity_id: scene.kontor_klar

- id: kontor_motion_sluk_dag
  alias: Sluk kontor lys efter 10 min uden bevægelse
  mode: restart

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

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

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

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

  trigger:
    - platform: state
      entity_id: binary_sensor.kontor_motion_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.kontor_motion_bevaegelse
          to: "on"
      timeout: "00:05:00"
      continue_on_timeout: true
    - condition: state
      entity_id: binary_sensor.kontor_motion_bevaegelse
      state: "off"
    - service: light.turn_off
      target:
        entity_id: light.strip
        
