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

I’ve got this automation

- alias: HAss update
  initial_state: 'on'
    platform: template
    value_template: "{{ ( ( states.sensor.hass_current.state  ) != ( states.sensor.hass_latest.state ) ) and ( states.sensor.hass_latest.state != 'unavailable' ) }}"
    service: notify.ha_telegram
      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
  value_template: "{{ }}"
  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:

    - platform: version
    - platform: scrape
      name: HA Online Version
      select: ".current-version h1"
      value_template: '{{ value.split(":")[1] }}'

    - alias: HASS Update Available Notification
        platform: state
        entity_id: sensor.ha_online_version
        - condition: template
          value_template: '{{states.sensor.ha_online_version.state != states.sensor.current_version.state }}'
        - service: notify.pushbullet_notify
            message: 'There is an update to Home-Assistant: {{states.sensor.ha_online_version.state}} ('

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.