How do packages cascade values through a configuration?

I am trying to make sure I understand something from the packages documentation. It appears to be taking the values in a cascading manner. Like, the yaml you are configuring would take the most importance and it just goes down the list from there. My questions would be best describe with examples.

outdoor-kitchen-shelly-1.yaml

substitutions:
  device_name: outdoor-kitchen-shelly-1
  friendly_name: Outside Kitchen Light

esphome:
  name: $device_name
  platform: ESP8266
  board: esp01_1m

packages:
  common: !include common/.common.yaml

# Device Specific Config
output:
  - platform: gpio
    pin: GPIO4
    id: shelly_1_relay

light:
  - platform: binary
    name: $friendly_name
    output: shelly_1_relay
    id: outsidekitchenlight

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO5
      #mode: INPUT_PULLUP
      #inverted: True
    name: "Outside Rear Garage Switch"
    on_state:
      then:
        - light.toggle: outsidekitchenlight
    internal: true
    id: switchid

./common/.common.yaml

wifi:
  # https://esphome.io/components/wifi
  ssid: !secret ssid1
  password: !secret ssid1_pass

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "${friendly_name}"
    password: !secret wifi_ap_password

captive_portal:

# Enable logging
logger:
  # https://esphome.io/components/logger

# Enable Home Assistant API
api:
  # https://esphome.io/components/api
  encryption:
    key: !secret api_password

ota:
  # https://esphome.io/components/ota
  - platform: esphome
    password: !secret ota_password

# Enable Web server.
web_server:
  port: 80
  auth:
    username: !secret web_username
    password: !secret web_password

# Get the time from Home Assistant to sync the onboard real-time-clock.  
time:
  - platform: homeassistant
    id: ha_time

So, I pull in the common configuration into the individual configs. But, for esp8266 devices, I need wifi to have power_save_mode: HIGH because of this issue. To my understanding, I can change the outdoor-kitchen-shelly-1.yaml to the following:

substitutions:
  device_name: outdoor-kitchen-shelly-1
  friendly_name: Outside Kitchen Light

esphome:
  name: $device_name
  platform: ESP8266
  board: esp01_1m

packages:
  common: !include common/.common.yaml

wifi:
  power_save_mode: HIGH

# Device Specific Config
output:
  - platform: gpio
    pin: GPIO4
    id: shelly_1_relay

light:
  - platform: binary
    name: $friendly_name
    output: shelly_1_relay
    id: outsidekitchenlight

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO5
      #mode: INPUT_PULLUP
      #inverted: True
    name: "Outside Rear Garage Switch"
    on_state:
      then:
        - light.toggle: outsidekitchenlight
    internal: true
    id: switchid

I believe that it would only override that value and not the ssid, password, and ap sections of wifi under the common section. Is that correct? Or would having wifi in the main configuration disable the entire wifi section from .common.yaml?

The next part is that I would possibly like to make it even more simple later. Make a ./common/.shelly1.yaml that would handle most of the configuration for all shelly devices. If I did that and I had the following, and both had the same value for something. Does the first one listed override the second one. Or is it the other way around?

packages:
  common: !include common/.common.yaml
  shelly: !include common/.shelly1.yaml

One final question, Can you have packages in your packages? Can the .shelly1.yaml have a package that pulls in .common.yaml?

A different thing that I’ve found in my searches is that substitutions could be a potential fix for this. This would look like the following:
outdoor-kitchen-shelly-1.yaml

substitutions:
  device_name: outdoor-kitchen-shelly-1
  friendly_name: Outside Kitchen Light

esphome:
  name: $device_name
  platform: ESP8266
  board: esp01_1m

packages:
  common: !include common/.shelly1.yaml

./common/.shelly1.yaml

substitutions:
  wifi-power-save-mode: HIGH

packages:
  common: !include common/.common.yaml

output:
  - platform: gpio
    pin: GPIO4
    id: shelly_1_relay

light:
  - platform: binary
    name: $friendly_name
    output: shelly_1_relay
    id: outsidekitchenlight

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO5
      #mode: INPUT_PULLUP
      #inverted: True
    name: "Outside Rear Garage Switch"
    on_state:
      then:
        - light.toggle: outsidekitchenlight
    internal: true
    id: switchid

./common/.common.yaml

substitutions:
  wifi-power-save-mode: LOW

wifi:
  # https://esphome.io/components/wifi
  ssid: !secret ssid1
  password: !secret ssid1_pass
  power_save_mode: $wifi-power-save-mode

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "${friendly_name}"
    password: !secret wifi_ap_password

captive_portal:

# Enable logging
logger:
  # https://esphome.io/components/logger

# Enable Home Assistant API
api:
  # https://esphome.io/components/api
  encryption:
    key: !secret api_password

ota:
  # https://esphome.io/components/ota
  - platform: esphome
    password: !secret ota_password

# Enable Web server.
web_server:
  port: 80
  auth:
    username: !secret web_username
    password: !secret web_password

# Get the time from Home Assistant to sync the onboard real-time-clock.  
time:
  - platform: homeassistant
    id: ha_time

My understanding is that this would make the default value LOW since it’s in .common.yaml. Then it would be overwritten by .shelly1.yaml to HIGH.

The issue with this approach is that for most cases, I would like to use the default value, whatever that may be. If I can figure it out like with the first approach it should allow me to use default values EXCEPT when dealing with 8266 devices.

I keep reading and I think I might have found the potential sollution. I believe I would need to use extend. Based on the first two files in the OP here is how I think it is meant to work:
outdoor-kitchen-shelly-1.yaml

substitutions:
  device_name: outdoor-kitchen-shelly-1
  friendly_name: Outside Kitchen Light

esphome:
  name: $device_name
  platform: ESP8266
  board: esp01_1m

packages:
  common: !include common/.common.yaml

wifi:
  - id: !extend wifi_component
    power_save_mode: HIGH

# Device Specific Config
output:
  - platform: gpio
    pin: GPIO4
    id: shelly_1_relay

light:
  - platform: binary
    name: $friendly_name
    output: shelly_1_relay
    id: outsidekitchenlight

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO5
      #mode: INPUT_PULLUP
      #inverted: True
    name: "Outside Rear Garage Switch"
    on_state:
      then:
        - light.toggle: outsidekitchenlight
    internal: true
    id: switchid

./common/.common.yaml

wifi:
  id: wifi_component
  # https://esphome.io/components/wifi
  ssid: !secret ssid1
  password: !secret ssid1_pass

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "${friendly_name}"
    password: !secret wifi_ap_password

captive_portal:

# Enable logging
logger:
  # https://esphome.io/components/logger

# Enable Home Assistant API
api:
  # https://esphome.io/components/api
  encryption:
    key: !secret api_password

ota:
  # https://esphome.io/components/ota
  - platform: esphome
    password: !secret ota_password

# Enable Web server.
web_server:
  port: 80
  auth:
    username: !secret web_username
    password: !secret web_password

# Get the time from Home Assistant to sync the onboard real-time-clock.  
time:
  - platform: homeassistant
    id: ha_time

With this, it should use the wifi details of the .common.yaml but add the power_save_mode: HIGH and I can only do this as needed. Is this correct?

Something that never occurred to me was that I could test all of this by using the validate function. I have been using that to look for “Validation successful”. But, I had never noticed that it literally spits out a the full config file with the packages combined as one. Using this I was able to come up with the following:
outdoor-kitchen-shelly-1.yaml

substitutions:
  device_name: outdoor-kitchen-shelly-1
  friendly_name: Outside Kitchen Light

esphome:
  name: $device_name
  platform: ESP8266
  board: esp01_1m

packages:
  common: !include common/.common.yaml

wifi:
  power_save_mode: HIGH

# Device Specific Config
output:
  - platform: gpio
    pin: GPIO4
    id: shelly_1_relay

light:
  - platform: binary
    name: $friendly_name
    output: shelly_1_relay
    id: outsidekitchenlight

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO5
      #mode: INPUT_PULLUP
      #inverted: True
    name: "Outside Rear Garage Switch"
    on_state:
      then:
        - light.toggle: outsidekitchenlight
    internal: true
    id: switchid

./common/.common.yaml

wifi:
  # https://esphome.io/components/wifi
  ssid: !secret ssid1
  password: !secret ssid1_pass

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "${friendly_name}"
    password: !secret wifi_ap_password

captive_portal:

# Enable logging
logger:
  # https://esphome.io/components/logger

# Enable Home Assistant API
api:
  # https://esphome.io/components/api
  encryption:
    key: !secret api_password

ota:
  # https://esphome.io/components/ota
  - platform: esphome
    password: !secret ota_password

# Enable Web server.
web_server:
  port: 80
  auth:
    username: !secret web_username
    password: !secret web_password

# Get the time from Home Assistant to sync the onboard real-time-clock.  
time:
  - platform: homeassistant
    id: ha_time

When I tried that the output of validate showed the wifi section like the following:

wifi:
  ap:
    ssid: ${friendly_name}
    password: REDACTED
    ap_timeout: 1min
  power_save_mode: HIGH
  domain: .local
  reboot_timeout: 15min
  fast_connect: false
  output_power: 20.0
  passive_scan: false
  enable_on_boot: true
  networks:
  - ssid: REDACTED
    password: REDACTED
    priority: 0.0
  use_address: outdoor-kitchen-shelly-1.local

This fixes my main problem. If someone reads this and can answer my questions on the OP that would still be much appreciated.

I am still curious about what order things get used.
Also, if putting packages inside of packages would work.