Template sensor shows as 'Unavailable'

Could you please format your pasted code correctly?

See point 11 here: How to help us help you - or How to ask a good question