Tricky : running an automation only once per value inside the value_template?

I’ve got this automation

- alias: HAss update
  initial_state: 'on'
  trigger:
    platform: template
    value_template: "{{ ( ( states.sensor.hass_current.state  ) != ( states.sensor.hass_latest.state ) ) and ( states.sensor.hass_latest.state != 'unavailable' ) }}"
  action:
    service: notify.ha_telegram
    data_template:
      message: "Home Assistant {{ states.sensor.hass_current.state }} is installed but {{ states.sensor.hass_latest.state }} is now available."

which is using these 2 sensors

- platform: rest
  name: HAss latest
  resource: https://pypi.python.org/pypi/homeassistant/json
  value_template: "{{ value_json.info.version }}"
  scan_interval: 60
- platform: version
  name: HAss current
  scan_interval: 60

So the automation sends me a new message when there’s a new version of HA which I don’t have installed.

The issue is that I get this notification repeated quite often, how is it possible to receive it only once per new version ?

In theory the automation should run only once per value inside the value_template of states.sensor.hass_latest.state

In general you can do this by creating a binary_sensor that is ‘on’ if there is a new version. Then the automation would use a state trigger with that binary_sensor and to: 'on', which would only fire when that sensor changes to ‘on’. The problem might be that at startup that sensor will likely, at least temporarily, be ‘unknown’. I would think it should fire when it goes from ‘unknown’ to ‘on’, just as well as when it goes from ‘off’ to ‘on’, but you might need to do some testing/tweaking.

This is what I use:

  sensor:    
    - platform: version
    - platform: scrape
      resource: https://www.home-assistant.io
      name: HA Online Version
      select: ".current-version h1"
      value_template: '{{ value.split(":")[1] }}'

  automation:
    - alias: HASS Update Available Notification
      trigger:
        platform: state
        entity_id: sensor.ha_online_version
      condition:
        - condition: template
          value_template: '{{states.sensor.ha_online_version.state != states.sensor.current_version.state }}'
      action:
        - service: notify.pushbullet_notify
          data_template:
            message: 'There is an update to Home-Assistant: {{states.sensor.ha_online_version.state}} (https://hub.docker.com/r/homeassistant/home-assistant/builds/)'

You may have to change your details depending on how you installed HA but this works and only ever gives me one notification on a new version change, even if I restart HA.