Automation, new version notification

Can someone please tell me why below automation does not work?
It’s for getting a notification when there’s a new HA version available.
Found the script as a workaround for the broken binary_sensor.updater
Instead it uses sensor.latest_version and sensor.current_version and compares the two.
I trigger the automation every 2 hours but I get a notification every time, even if current and latest is the same!
For instance right now it says something like:
“Update available, you are running 0.114.0, the latest version is 0.114.0”
So I guess something is wrong in value_template when the script compares the two sensor values.
Or is it simply some syntax issue?
Here’s the script:

- id: update_available
  alias: Update Available
  initial_state: true
  trigger:
  - platform: state
    entity_id: sensor.latest_version
  condition:
    condition: template
    value_template: '{{ states(''sensor.latest_version'') != states(''sensor.current_version'') }}'
  action:
  - service: notify.pushbullet
    data_template:
      title: '*Information*'
      message: "An update for Home Assistant is available. You are running {{states('sensor.current_version') }}, the latest version is {{ states('sensor.latest_version') }}."

Any help appreciated!

you trigger this specific automation above? Then you should put the condition under action like:
(and it it’s also quotation marks instead of double apostrophe i think)

 action:
  - condition: template
    value_template: '{{ states("sensor.latest_version") != states("sensor.current_version") }}'
  - service: notify.pushbullet
    data_template:
      title: '*Information*'
      message: "An update for Home Assistant is available. You are running {{states('sensor.current_version') }}, the latest version is {{ states('sensor.latest_version') }}."

*when an automation is triggered manually or within a script/other automation, only the action part run. Condition only applies when triggered with own automation trigger
Learnd something new, this can be done:

Edit:
I just tried to implement this for me and think it could be done with one automation,
with trigger time_pattern it should run every two hours.
Also not necessary, all it needs is @tom_l code:

Why? The trigger you have shown will trigger when needed.

And How? Maually triggering?

If so, you can leave the condition where it is. As you can choose to run the conditions when triggering an automation manually from the developer tools now:

Or you can do it florian’s way if you want to trigger from the more info pop-up box.

box

1 Like

Thank you Florian and Tom for your input!
@Tom, it was actually your code that I copied! Just using Pushbullet instead.
I didn’t realize it would trigger automatically so I set up a 2 hour trigger in Node Red (where I usually do all my automations but couldn’t get this working there).
It’s working now I think, not getting notifications any longer, moved condition to under action.
Regarding the quotation marks and apostrophe, using quotationmarks now but in Tom’s original script there was single apostrophe and that seemed to work?

Yep every time this sensor or it’s attributes change:

  trigger:
  - platform: state
    entity_id: sensor.latest_version

Not sure what you are referring to here but I make mistakes regularly. I just had a look at my code:

- id: update_available
  alias: 'Update Available'
  initial_state: true
  trigger:
    platform: state
    entity_id: sensor.latest_version
  condition:
    condition: template
    value_template: "{{ states('sensor.latest_version') != states('sensor.installed_version') }}"
  action:
  - service: notify.telegram_system
    data_template:
      title: '*Information*'
      message: "An update for Home Assistant is available. You are running {{states('sensor.installed_version') }}, the latest version is {{ states('sensor.latest_version') }}."

It is working and has the advantage of not bugging your CPU every 2 hours. Time pattern triggers are rarely the optimal solution.

didn’t know that either, Thanks!
I should read the docs more attentive, it’s mentioned in the first sentence :sweat_smile:

I really should change it to a template trigger so it only triggers on a state change. This would also stop repeated notifications if I have not updated yet and the attributes change. No need for the condition then either.

Done.

- id: update_available
  alias: 'Update Available'
  initial_state: true
  trigger:
    platform: template
    value_template: "{{ states('sensor.latest_version') != states('sensor.installed_version') }}"
  action:
    service: notify.telegram_system
    data_template:
      title: '*Information*'
      message: "An update for Home Assistant is available. You are running {{states('sensor.installed_version') }}, the latest version is {{ states('sensor.latest_version') }}."

Also I read last night that there’s a fix for the binary update sensor that has been merged. So you should be able to go back to using that soon.

1 Like

Great, thanks!
Also good news regarding the binary update sensor.

1 Like