- id: badevaerelse_motion_lys
  alias: Badeværelse lys via bevægelse
  mode: restart

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

  action:
    - choose:
        # Arbejdsdag dagtid (06:00–22:00)
        - conditions:
            - condition: state
              entity_id: binary_sensor.arbejdsdag
              state: "on"
            - condition: time
              after: "06:00:00"
              before: "22:00:00"
          sequence:
            - service: scene.turn_on
              target:
                entity_id: scene.badevaerelse_klar

        # Ikke arbejdsdag dagtid (08:00–22:00)
        - conditions:
            - condition: state
              entity_id: binary_sensor.arbejdsdag
              state: "off"
            - condition: time
              after: "08:00:00"
              before: "22:00:00"
          sequence:
            - service: scene.turn_on
              target:
                entity_id: scene.badevaerelse_klar

      # Nat (alle andre tidspunkter)
      default:
        - service: scene.turn_on
          target:
            entity_id: scene.badevaerelse_nat_2_lys

- id: badevaerelse_motion_sluk
  alias: Sluk lys på badeværelse efter bevægelse
  mode: restart

  trigger:
    - platform: state
      entity_id: binary_sensor.badevaerelse_bevaegelse
      to: "off"
      for:
        minutes: 3   # Standard nat-timeout, kan ændres til 10 for dag, osv.

  action:
    - service: light.turn_off
      target:
        area_id: badevaerelse
