Boot loop when setting media player volume in setup?

Hello
I have encountered a rather weird Issue.
I wanted to include a way to control the volume of my media_player component, so I introduced a template number and have it set the volume of the player. I dont know if this is the recommended way of doing things, but it’s where I ran into the issue.

As soon as I had flashed the ESP, it became unresponsive. Some investigation made me realize that it was stuck in a bootloop. I have no way of confirming this, but it seems to me that the number component is getting initialized quite early in the setup() method. This in turn triggers the on_value automation, which wants to set the volume of the media player. however, I suspect that the media player is not yet set up at that point, which triggers a core panic.

Please tell me if I am doing things all wrong and/or if I should create a GitHub Issue for this.

Hard/software:
Wemos D1mini 32 (from this listing: https://www.aliexpress.com/item/4000880936043.html?spm=a2g0o.order_list.0.0.79db1802oL1pnn)
ESPHome c2022.11.1 trough a Home Assistant Add-On
Home Assistant 2022.11.4
Supervisor 2022.10.2
Operating System 9.3
Frontend 20221108.0 - latest

ESPHome config:

esphome:
  name: nfc-jukebox

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:
  level: VERY_VERBOSE

web_server:

# Enable Home Assistant API
api:
  encryption:
    key: "OwtJLMle/kNf5oi5Nd0Anger7rwB1JwAgRWxmikZ0OM="

ota:
  password: "2f4457cb8f8986c4923f697d9395588e"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Nfc-Jukebox Fallback Hotspot"
    password: "fBzHNljR0wqt"

captive_portal:

spi:
  clk_pin: GPIO23
  mosi_pin: GPIO18
  miso_pin: GPIO33

pn532_spi:
  cs_pin: GPIO26
  update_interval: 1s
  on_tag:
      then:
        - homeassistant.tag_scanned: !lambda |
            if (!tag.has_ndef_message()) {
              return x;
            }
            auto message = tag.get_ndef_message();
            auto records = message->get_records();
            for (auto &record : records) {
              std::string payload = record->get_payload();
              size_t pos = payload.find("https://www.home-assistant.io/tag/");
              if (pos != std::string::npos) {
                return payload.substr(pos + 34);
              }
            }
            return x;

media_player:
  - platform: i2s_audio
    id: player
    name: NFC Jukebox
    dac_type: external
    i2s_lrclk_pin: GPIO32
    i2s_dout_pin: GPIO22
    i2s_bclk_pin: GPIO19
    mode: stereo
    
button:
  - platform: template
    id: radarbutton
    name: Play ATC
    on_press:
      then:
        - media_player.play_media: 'https://www.liveatc.net/play/lszh1_twr.pls'
  
  - platform: template
    id: energybernbutton
    name: Play Energy Bern
    on_press:
      then:
        - media_player.play_media: 'http://broadcast.infomaniak.ch/energybern-high.mp3'
        
  - platform: template
    id: srf3button
    name: Play srf3
    on_press:
      then:
        - media_player.play_media: 'https://stream.srg-ssr.ch/m/drs3/aacp_96'

  - platform: template
    id: grrifbutton
    name: Play grrif
    on_press:
      then:
        - media_player.play_media: 'https://grrif.ice.infomaniak.ch/grrif-128.aac'

  - platform: template
    id: dnbbutton
    name: Play DnB-Radio.com
    on_press:
      then:
        - media_player.play_media: 'https://dnbradio.nl/dnbradio_main.mp3'

  - platform: template
    id: Stop
    name: Stop
    on_press:
      then:
        - media_player.stop
number:
  - platform: template
    name: Jukebox Volume
    icon: "mdi:volume-high"
    min_value: 0
    max_value: 100
    step : 1
    optimistic: true
    restore_value: false
    initial_value: 75
    id: volume
    on_value:
      then:
        - media_player.volume_set: !lambda "return x/100;"

Logger output:
https://pastebin.com/vef6Vd7f

The logs that get generated if I comment out the template number section from the YAML:
https://pastebin.com/z40wY1Qr

yes i know that the SPI and I2S component fail to set up, that is because the ESP was unplugged from the peripherals when I generated the logs.

Please tell me if I can help with further Info.

EDIT
I have taken a look at the autogenerated code. It seems to me that the media player gets initialized and registered on line 350, while the the template number does not get touched until line 539. So my hunch about the uninitialized media player seems very unlikely now.

I don’t have a esphome media_player at present, but are you saying that it doesn’t already have a volume control?

it does have volume control. It is normally exposed over the Home Assistant lovelace dashboard. But I wanted to also expose it over the web interface hosted on the ESP.