Template sensor calculations when values don't exist

The value is called unavailable not unavialable. It means the sensor’s value isn’t currently available (typically due to loss of communication). A state value of unknown is usually due to the sensor not receiving any value (so it’s current state is unknown).