- id: andreas_arrival_lights_pro
  alias: Andreas hjem - udelys (pro)
  description: Tænder udelys ved hjemkomst i mørke/tusmørke og slukker igen efter 10 min
  mode: restart

  trigger:
    - platform: state
      entity_id: person.andreas_schusler_dethlefsen
      from: "not_home"
      to: "home"
      for: "00:00:15"

  condition:
    # Andreas skal have været væk lidt tid
    - condition: state
      entity_id: person.andreas_schusler_dethlefsen
      state: "home"

    # Lux skal være lav
    - condition: numeric_state
      entity_id: sensor.indkorsel_sensor_illuminance
      below: 120

    # Solen skal være lav (backup hvis lux sensor er upålidelig)
    - condition: numeric_state
      entity_id: sun.sun
      attribute: elevation
      below: 4

  action:
    - variables:
        lights:
          - light.indkorsel_2
          - light.extended_color_light_1
          - light.garage

        lights_to_turn_on: >
          {{ lights | select('is_state','off') | list }}

    - choose:
        - conditions: "{{ lights_to_turn_on | length > 0 }}"
          sequence:

            - service: light.turn_on
              target:
                entity_id: "{{ lights_to_turn_on }}"

            - delay: "00:10:00"

            - service: light.turn_off
              target:
                entity_id: "{{ lights_to_turn_on }}"
                
