This paper presents a combined experimental and numerical method for analysing energy flows within a spark ignition engine. Engine dynamometer data is combined with physical models of in-cylinder convection and the engine's thermal impedances, allowing closure of the First Law of Thermodynamics over the entire engine system. In contrast to almost all previous works, the coolant and metal temperatures are not assumed constant, but rather are outputs from this approach. This method is therefore expected to be most useful for lean burn engines, whose temperatures should depart most from normal experience.As an example of this method, the effects of normalised air-fuel ratio (λ), compression ratio and combustion chamber geometry are examined using a hydrogen-fueled engine operating from λ = 1.5 to λ = 6. This shows large variations in the in-cylinder wall temperatures and heat transfer with respect to λ. In keeping with our other works, thermal efficiency also appears to be limited by in-cylinder heat transfer on the rich side of optimum λ, and diminishing combustion quality on the lean side.By comparing different compression ratios, this method confirms the widely-reported significance of in-cylinder heat transfer in determining the optimal compression ratio of hydrogen-fueled engines. As part of this, while increased in-cylinder pressures contribute to increased heat transfer at higher compression ratio, the accompanying increased piston surface area was also found to be significant. As a final contribution, potential improvements in piston design are therefore investigated numerically, and suggestions for high efficiency, hydrogen fuelled engine designs are made.