HACS updates notification help

I’ve been trying to get notifications sent with the name, version whenever an update is available in HACS, but can’t get it working. I’ve used the code from here https://hacs.xyz/docs/basic/automation , which sends the notification ok, but the content of the notification is just the yaml code block. Looking in the log it’s saying ‘trigger’ is undefined.

The end goal will be to get it sending to pushbullet, but that just flat doesn’t send anything at all with that code.

alias: Test HACS notification
  description: ''
  trigger:
  - entity_id: sensor.hacs
    platform: state
  condition:
  - condition: template
    value_template: '{{ states(trigger.entity_id) != ''unknown''}}'
  - condition: template
    value_template: '{{ (states(trigger.entity_id) | float) != 0}}'
  action:
  - data:
      message: >-
          {% for repo in state_attr(trigger.entity_id, 'repositories') %}
            **{{ repo.display_name }}** _{{ repo["installed_version"] }}_ -> _{{ repo["available_version"] }}_
          {% endfor %}
      title: Updates pending in HACS
    service: persistent_notification.create
  mode: single

check your logs, it looks as though you have an indentation issue with this block:

And your action should contain data_template: not data:

Have updated to data_template, but log is still complaining about ‘trigger’

Also copied the code in Notepad++ & all the indentation looks ok as far as I can tell & no Tabs.

your first value template is not right as you’re enclosing in single quotes and also using single quotes for your string.
You’d be better copying off the code than rewriting it:

alias: Test HACS notification
  description: ''
  trigger:
    platform: state
    entity_id: sensor.hacs
  condition:
    - condition: template
      value_template: "{{ states(trigger.entity_id) != 'unknown'}}"
    - condition: template
      value_template: "{{ (states(trigger.entity_id) | float) != 0}}"
  action:
    service: persistent_notification.create
    data_template:
      title: Updates pending in HACS
      message: >-
        {% for repo in state_attr(trigger.entity_id, 'repositories') %}
          **{{ repo.display_name }}** _{{ repo["installed_version"] }}_ -> _{{ repo["available_version"] }}_
        {% endfor %}

What is actually the mode: single for? It’s not a valid option for persistent_notification.create

For pushbullet the action would look like:

    service: notify.NOTIFIER_NAME
    data_template:
      title: Updates pending in HACS
      message: >-
        {% for repo in state_attr(trigger.entity_id, 'repositories') %}
          **{{ repo.display_name }}** _{{ repo["installed_version"] }}_ -> _{{ repo["available_version"] }}_
        {% endfor %}

Obviously replace NOTIFIER_NAME with your pushbullet notifier name…

mode: singe is a new option for automations/scripts. Check the 0.113 release notes.

thank it threw me off because it was at the bottom and felt like it didn’t belong there…

I’ve re-copied the updated code block, but it’s still getting trigger as undefined. I thought it might’ve been the data_template uses “state_attr” where the value_template uses “states”, but that makes no difference either if I change it to match.

Here’s the message from the log
`Test HACS notification: Error executing script. Unexpected error for call_service at pos 1: Error rendering data template: UndefinedError: ‘trigger’ is undefined
While executing automation automation.test_hacs_notification
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/template.py”, line 229, in async_render
return compiled.render(kwargs).strip()
File “/usr/local/lib/python3.8/site-packages/jinja2/environment.py”, line 1090, in render
self.environment.handle_exception()
File “/usr/local/lib/python3.8/site-packages/jinja2/environment.py”, line 832, in handle_exception
reraise(*rewrite_traceback_stack(source=source))
File “/usr/local/lib/python3.8/site-packages/jinja2/_compat.py”, line 28, in reraise
raise value.with_traceback(tb)
File “”, line 1, in top-level template code
File “/usr/local/lib/python3.8/site-packages/jinja2/sandbox.py”, line 407, in getattr
value = getattr(obj, attribute)
jinja2.exceptions.UndefinedError: ‘trigger’ is undefined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/service.py”, line 132, in async_prepare_call_from_config
template.render_complex(config[CONF_SERVICE_DATA_TEMPLATE], variables)
File “/usr/src/homeassistant/homeassistant/helpers/template.py”, line 73, in render_complex
return {key: render_complex(item, variables) for key, item in value.items()}
File “/usr/src/homeassistant/homeassistant/helpers/template.py”, line 73, in
return {key: render_complex(item, variables) for key, item in value.items()}
File “/usr/src/homeassistant/homeassistant/helpers/template.py”, line 75, in render_complex
return value.async_render(variables)
File “/usr/src/homeassistant/homeassistant/helpers/template.py”, line 231, in async_render
raise TemplateError(err)
homeassistant.exceptions.TemplateError: UndefinedError: ‘trigger’ is undefined

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/script.py”, line 193, in _async_step
await getattr(
File “/usr/src/homeassistant/homeassistant/helpers/script.py”, line 354, in _async_call_service_step
domain, service, service_data = async_prepare_call_from_config(
File “/usr/src/homeassistant/homeassistant/helpers/service.py”, line 135, in async_prepare_call_from_config
raise HomeAssistantError(f"Error rendering data template: {ex}") from ex
homeassistant.exceptions.HomeAssistantError: Error rendering data template: UndefinedError: ‘trigger’ is undefined`

Hi, I’m wondering what is benefit of updating the HACS? In my HA, it shows there are updates for HACS and some custom components. I understood that the custom components might get some bugfix/new feature, but what about HACS?

What’s the final (working) version of your script @bgclark?

I do something similar that works pretty well…

alias: System Notification - HACS Persistent Notification
trigger:
  - above: '0'
    entity_id: sensor.hacs
    platform: numeric_state
condition:
  - condition: template
    value_template: '{{ not is_state(''sensor.hacs'', ''unknown'') }}'
action:
  - data:
      message: >-
          {% for repo in state_attr('sensor.hacs', 'repositories') %}
          {{ repo.display_name }}
          Current version  {{ repo["installed_version"] }}
          New Version      {{ repo["available_version"] }}
          {% endfor %}
      title: HACS Update available!
    service: persistent_notification.create
mode: single

image

what I can’t figure out is how to place the three values on different lines like it does in the template editor. I know the message can be at least three lines.

image

{% for repo in state_attr('sensor.hacs', 'repositories') %}
Repository       {{ repo.display_name }}
Current version  {{ repo["installed_version"] }}
New Version      {{ repo["available_version"] }}
{% endfor %}

I also want to embed the repo URL in an actionable link, but thats more of a stretch goal.