Update Available sensor not working

I have used the following code to show the current and available versions of Hass as sensors and those work. However, the sensor Update Available which I have commented out only ever shows no. This is even when I go to the Hass panel and advanced tools and it shows I am on an old version.

Apparently, this script was made for the old RPi all-in-one.

How do I need to change the commented out lines to say Yes if there is an update available and No if there isn’t?

# Version and Availability
  - platform: rest
    name: "HASS Current Version"
    resource: https://pypi.python.org/pypi/homeassistant/json
    value_template: '{{ value_json.info.version }}'
    scan_interval: 3600

  - platform: command_line
    name: "HASS Installed version"
    command: "head -5 /config/.HA_VERSION"

# - platform: template
#   sensors:
#     hass_update_available:
#       friendly_name: "Update Available"
#       value_template: >-
#         {%- if states.hass_current_version.state != states.hass_installed_version.state -%}
#            {{ states.hass_current_version.state }}
#         {%- else -%}
#            No
#         {%- endif -%}