What's the relation between temperature and scale factor for arbitrary EoS $-1 < w \le 1$? I'm considering standard FLRW cosmology for a simple perfect fluid of pressure $p = w \, \rho$, with $-1 < w \le 1$.  In the special case of $w =\frac{1}{3}$ (radiation), the temperature is $T \propto a^{-1}$, where $a$ is the cosmological scale factor.  This relation comes from solving the nul-geodesic equation (for photons), or from quantum mechanics which gives $E \propto \lambda^{-1}$ for a photon, and $\rho \propto a^{-4}$ combined with Stefan's law $\rho \propto T^4$.
But then, what is the similar relation for fluids of parameter $w \ne \frac{1}{3}$?
For dust (cold by definition), we have $T \approx 0$.  But what is $T$ for a fluid of any $w$?
 A: The distribution function of particles in phase space for a homogeneous, isotropic universe is denoted as $f(q)$, where $q$ is the magnitude of the momentum. It can be taken to be the Fermi-Dirac or Bose-Einstein distribution, which in natural units read $f(q) = (\exp ( (E - \mu)/T) \pm 1)^{-1}$ respectively, and which depend on the temperature $T$, on the chemical potential $\mu$ and on the energy $E = E(q) = \sqrt{q^2 + m^2}$.
The ultra-relativistic case, $w=1/3$, corresponds to $q \gg m$, so $E \approx q$, while the non-relativistic case $w=0$ corresponds to $q \ll m$, so $E \approx m + q^2 /2m \approx m$.
From this distribution function, we can recover the number density, energy density, entropy density and pressure for that particle species with some integrals - see equations 5 through 8 of Husdal et al (2016).
We can then ask about intermediate values, $0 < w < 1/3$ - I don't believe talking about "temperature" makes a lot of sense for $w<0$ or $w>1/3$, since you couldn't get those EOS from the regular FD/BE distribution formula; at the very least you'd have to determine how the distribution function for particles with those EOS depends on temperature.
Now, a restatement of the fact that the entropy in a comoving volume is conserved is that the quantity $a^3 ( \rho + P) / T$ is a constant - see Kolb and Turner, 1994, equation 3.70.
We can then say that $ T \propto a^{3} (1+w) \rho$; this is the usual $T \propto 1/a$ in the ultra-relativistic case.
The advantage of "getting here" this way is that we can generalize: we can express $\rho = \rho (T)$ and $P = P(T)$ by solving the relevant integrals, and we are left with an equation which relates $T$ and $a$.
I must admit I have not done this computation, so I cannot give a precise result; I believe it will depend on the specifics of the particle species considered because we lose the "scale invariance" inherent to relativistic particles.
Edit: a proof of the relation $T \propto a^3 (1+w) \rho$, based on section 3.4 in Kolb and Turner.
The entropy differential reads
$$   
\text{d}{S}  = \frac{1}{T} (\underbrace{\text{d}{(\rho(T) V)}}_{ \text{d}{E}}  + P(T) \text{d}{V})
  = \frac{1}{T} (V \text{d}{\rho (T)} + (P(T) + \rho(T) ) \text{d}{V})
$$
so its partial derivatives are
$$
  \frac{\partial S}{\partial V} = \frac{1}{T} (\rho (T) + P(T))
  \qquad \text{and} \qquad
  \frac{\partial S}{\partial T} = \frac{V}{T} \frac{\text{d}\rho (T)}{\text{d}T} 
$$
and therefore the second partials being equal can be expressed as
$$
\begin{align}
  \frac{\partial ^2 S}{\partial T \partial V} &= \frac{\partial ^2 S}{\partial V \partial T} \\ 
  \frac{\partial}{\partial T}  \left(\frac{1}{T}(\rho (T) + P(T))\right) 
  &= \frac{\partial}{\partial V} \left(\frac{V}{T} \frac{\partial\rho (T)}{\partial T} \right)   \\
  - \frac{1}{T^2} (\rho + P)
  + \frac{1}{T} \left(\frac{\partial \rho }{\partial T} + \frac{\partial P}{\partial T}\right)
  &= \frac{1}{T} \frac{\partial \rho }{\partial T}   \\
  \frac{\partial P}{\partial T} &= \frac{1}{T} (\rho +P) 
\end{align}
$$
which allows us to verify that
$$
\begin{align}
\frac{\text{d}}{\text{d}t} \left(\frac{a^3}{T} (\rho + P )\right) 
&= \frac{1}{T} \frac{\text{d}}{\text{d}t} (a^3 (\rho + P)) + a^3 (\rho + P) \frac{\text{d}}{\text{d}t} \left( \frac{1}{T}\right)  \\
&= \frac{1}{T} a^3 \dot{P} - a^3 (\rho + P) \frac{\dot{T}}{T^2}  \\
&= \frac{a^3}{T} \frac{\text{d}P}{\text{d}T} \dot{T} - a^3 (\rho + P) \frac{\dot{T}}{T^2}  \\
&= \frac{a^3}{T} \frac{(\rho + P)}{T} \dot{T} - a^3 (\rho + P) \frac{\dot{T}}{T^2} = 0
\,.
\end{align}
$$
