Downsides of template re-initialization

Today I learned that when developing template sensors, it’s important to always start with a new sensor name/unique id whenever you do anything to the sensor that might cause it to not initialize properly.

This ensures that as you are developing the sensor you aren’t introducing bugs into the template that you won’t detect until you make a copy of the sensor to use with different underlying sensors. This is because Home Assistant helpfully (or not) re-initializes a template sensor with the old attribute values when you reload the template (using Developer Tools/YAML/Template Entities). This reload of old attribute values can mask issues that you won’t see until you are starting out with a new copy of the sensor, resulting in your newly initialized sensor stuck in an ‘unavailable’ state, despite the old sensor appearing to work completely fine!