In case of a filament we are not dealing with an equilibrium state, but rather a non-equilibrium steady state - thus, in principle, one should not apply the laws of equilibrium thermodynamics to this case. However,
- to the extent that the 1st law of thermodynamics expresses the energy conservation, we can use the associated langauge to express the energy balance in the filament
- provided that the energy exchange between the filament and its environment is much slower than the relaxation processes within the filament, it can be treated as a system in thermodynamic quasi-equilibrium - i.e., we can describe it in terms of an effective temperature, etc.
The environment of the filament consists principally from the power source/circuit driving the current through it, and the space outside the filament, to which it emits photons. The power source does work on the filament at the rate given by the Joule-Lenz law:
$$
\frac{dW}{dt}=I^2R,
$$
where $I$ is the current through the filament and $R$ is its resistance.
The filament then emits this energy as photons - the quasi-equilibrium assumption mentioned above allows us to treat the radiation emitted by the filement as thermal radiation and describe it by the black-body spectrum, which means that the rate at which the filament emits the radiation is given by Stefan-Boltzmann law:
$$
\frac{dQ}{dt} =-\alpha T^4,$$
where $T$ is the effective temperature of the filament, whereas $\alpha$ is the coefficient that depends on the material and the shape of the filament.
The rate of the internal energy change is then given by
$$
\frac{dU}{dt}=\frac{dQ}{dt} +\frac{dW}{dt}=-\alpha T^4+I^2R.$$
(One could also include heat conductance between the filament and its support, as well as the heat exchange between the filament and the surrounding gas, if it is not in vacuum.)
Initially, when the switch is turned on, the filament is a room temperature and the work done by current goes into heating the filament, increasing its internal energy and temperature. As the temperature of the filament increases, it emits more and more radiation, until it reaches the steady state, where the energy lost via radiation equals to the work done by the current. Formally the steady state is given by condition
$$
\frac{dU}{dt}=0.
$$
However we are not in a state of thermodynamic equilibrium, since there is constant energy flow from the power source to the radiation in the surrounding space. (One could use here a hydrodynamic analogy of water in a pond vs. a steady flow in a river.)
Remarks
- One could put the quasi-equilibrium description even a bit further by assuming that the internal energy is proportional to temperature (which is not granted in non-equilibrium) $U=cT$ and writing and solving the differential equation for the temperature of the filament:
$$
c\frac{dT}{dt}=-\alpha T^4+I^2R.$$
- One could also include the environment feedback. In typical conditions the radiation emitted into the environment is lost, e.g., via absorption by walls and other objects, which are in turn cooled via thermal conduction and convection. We could however imagine a lamp inside a thermally isolated box, which may be also assumed to be in quasi-equilibrium, characterized by temperature $T_e$. We can the write the rate equations for the energy of the filament and that of the box as
$$
c\frac{dT}{dt}=\alpha (T_b^4 - T^4)+I^2R,\\
c_b\frac{dT_b}{dt}=\alpha (T^4 - T_b^4).$$