Using Scripts 'last triggered' to build sensor

I’m trying to maintain state for my xiaomi ir blaster that turns our air con on and off. I have a script to turn it on and another to turn if off. I want to present this as a switch template in the UI and via home assistant but I’m pulling my hair out as to why my config returns ‘unknown’ for the state. Any pointers please:
- platform: template
sensors:
bedroom_aircon:
friendly_name: ‘Bedroom Aircon’
value_template: >-
{% if is_state_attr(‘script.bedroom_aircon_remote_on’, ‘last_triggered’, null) %}
off
{elif is_state_attr(‘script.bedroom_aircon_remote_off’, ‘last_triggered’, null) %}
off
{% elif as_timestamp(states.script.bedroom_aircon_remote_on.attributes.last_triggered) > as_timestamp(states.script.bedroom_aircon_remote_off.attributes.last_triggered) %}
on
{% else %}
on
{% endif %}
garage_door:
friendly_name: ‘Garage Door’
#entity_id: switch.garage_door_opener
#value_template: ‘{{ states.switch.garage_door_opener.attributes.sensor_state }}’
value_template: >-
{% if states.switch.garage_door_opener.attributes.sensor_state == ‘on’ %}
closed
{% else %}
open
{% endif %}
icon_template: >-
{% if states.switch.garage_door_opener.attributes.sensor_state == ‘on’ %}
mdi:garage
{% else %}
mdi:garage-open
{% endif %}

To get the code formatted correctly for the forum paste the code in
the edit box, leaving a blank line at the start and end, then select
the code and click the </> button in the small menu bar at the top of
the edit box.

YAML is VERY picky over tabs and spaces :stuck_out_tongue: