input_boolean:
  routine_welcome_home:
    name: Coming home · Say welcome
    initial: on
    icon: mdi:account-plus-outline
  coming_home_play_music:
    name: Coming home · Play music
    icon: mdi:music-box-outline

script:
  routine_coming_home:
    alias: Routine · Coming home
    sequence:
      - service: input_select.select_option
        entity_id: input_select.hallway_dashboard_mode
        data:
          option: "Coming Home"

      # Lights
      - service: light.turn_on
        entity_id:
          - light.hallway_entrance
          - light.hallway_main
          - light.browser_kitchen
          - light.browser_hallway
          - light.living_room_ambient
          - light.bedside
        data:
          brightness_pct: 100

      - service: script.routine_coming_home_during_daytime
      - service: script.routine_coming_home_after_sunset

      - service: script.toshiba_ac_on_cool_if_hot

      - service: script.sonos_join_bedroom
      - service: script.shield_screensaver

      - service: script.routine_coming_home_welcome_home
      - service: script.turn_on_all_radiators

      # Cameras
      - service: switch.turn_off
        entity_id: switch.tapo_bedroom
      - service: switch.turn_on
        entity_id: switch.mercury_home_mode

  routine_coming_home_during_daytime:
    alias: Routine · Coming home · During daytime
    sequence:
      - and:
        - condition: sun
          after: sunrise
        - condition: sun
          before: sunset
      - service: script.open_living_room_cover

  routine_coming_home_after_sunset:
    alias: Routine · Coming home · After sunset
    sequence:
      - or:
        - condition: sun
          after: sunset
          after_offset: "-01:00:00"
        - condition: sun
          before: sunrise
      - service: light.turn_on
        entity_id: light.on_after_dark
        data:
          brightness_pct: 100

  routine_coming_home_welcome_home:
    alias: Routine · Coming home · Welcome home
    sequence:
      - condition: state
        entity_id: input_boolean.routine_welcome_home
        state: "on"
      - service: script.say
        data_template:
          partials:
            - !include ../../templates/partials/greeting.yaml
            - !include ../../templates/partials/time.yaml
            # - "Here's the current status:" // TODO: figure out if there will be anything to say?
            - !include ../../templates/partials/window_suggestions.yaml
      - wait_template: "{{ is_state('input_boolean.sarah_talking', 'off') }}"
        timeout: 00:02:00
      - delay: 00:00:01

      - and:
        - condition: time
          before: "23:00:00"
        - condition: time
          after: "09:00:00"
        - condition: state
          entity_id: input_boolean.coming_home_play_music
          state: "on"

      - service: script.say
        data_template:
          message: >-

            {{
              [
                "I'll put some music on.",
                "I'll play some music.",
                "Here's some music."
              ] | random
            }}
      - delay: 00:00:02
      - service: script.music_play
