Issue with creating template sensor from existing Zigbee Temp Sensor

First a bit of background, I have made a DIY climate controller using ESPHome which is taking temperature values from a nearby Sonoff Zigbee Temp and Humidity Sensor. This works flawlessly until I restart HA (for an update, change to the config etc), where the issue is that because the temperature hasn’t changed a new temp value is not sent from the Zigbee sensor and consequently the ESPHome Climate sensor does not pick it up. Eventually the sensor will send a temperature update I just want to make it better.

What I have thought of doing is create a template sensor from this Zigbee sensor so I can always keep a value in HA and not have to wait for the sensor to update, but I am having issues doing so (Template Sensors are a bit of a rabbit hole). I have got this in my config file:

template:
 - sensor:
    - name: "Hallway Temp Template"
      device_class: temperature
      unit_of_measurement: "°C"
      value_template: "{{(states(sensor.hallway_sensor_temperature)}}"

This completes without error but when checking the config prior to a system restart I get this error in the HA Logs

Logger: homeassistant.config
Source: config.py:929 
First occurred: 09:40:55 (6 occurrences) 
Last logged: 10:00:35

Invalid config for [template]: [value_template] is an invalid option for [template]. Check: template->sensor->0->value_template. (See /config/configuration.yaml, line 177).

I dont really know what the invalid option is, granted I have just been using other posts and the somewhat difficult to understand HA help pages for this. Any help would be much appreciated. All I want is the value of the Zigbee sensor added to a template so there is never an occurrence of no known value.

A template sensor will not solve this issue. State-based template sensors do not restore their previous value on restart.

In terms of the actual template, you’ve just got a couple little issues. You have mixed the legacy format and the current format, you have an extra (, and you are missing quote marks around the entity id…

template:
 - sensor:
    - name: "Hallway Temp Template"
      device_class: temperature
      unit_of_measurement: "°C"
      state: "{{ states('sensor.hallway_sensor_temperature') }}"
      availability: "{{ states('sensor.hallway_sensor_temperature') is defined }}"

Thanks, I realised not soon after that I had mixed things up after looking a bit deeper into the error (the first few results were not helpful), it always seems that you get part way to the solution after posting to the forum. I still had an issue with the syntax so your post really helped and the template sensor is now ‘working’.

So delving a bit deeper into the not restoring their previous value on restart, are you able to advise on what I could/should use to make this work? The goal was to to be able to recall the last known value if no new value value has been sent as is reporting as “unknown” in HA. I thought a template sensor would help but your post infers that it doesnt.