Getting entity_id of pending update device from the update entity

I currently have the following automation which notifies me of a pending firmware upgrade and asks whether I’d like to install any pending updates. I’d like to be able to extract the actual device entity ID, rather than the update domain entity ID, I’d appreciate any help :slight_smile:

  - alias: "Check for Pending Device Firmware Updates"
    id: ha_check_for_pending_firmware_updates
    description: "Send a Telegram message if there are pending updates for devices"
    initial_state: true
    trigger:
      - platform: time_pattern
        hours: "/1"

    condition:
      - condition: template
        value_template: >
          {{ states.update | selectattr('attributes.device_class', 'eq', 'firmware') | selectattr('state', 'eq', 'on') | list | count > 0 }}

    action:
      - action: notify.ohad_telegram
        data:
          message: >-
            {% set updates = states.update | selectattr('attributes.device_class', 'eq', 'firmware') | selectattr('state', 'eq', 'on') | list %}
            {% if updates | count > 0 %}
            There are pending firmware updates for the following devices:
            {% for update in updates %}
              - {{ update.entity_id }} ({{ update.name }}) in area {{ update.attributes.area_id | default('unknown') }}
            {% endfor %}
            Do you want to update now?
            {% else %}
            There are no pending firmware updates at this time.
            {% endif %}
          data:
            inline_keyboard:
              - "Update Now:/trigger_firmware_update, Snooze Updates (EOW):/snooze_firmware_updates"

There is a device_id or an entity_id, no such thing as a device entity ID. Not sure exactly what you want. I would think in a notification you probably want the name of the device that is associated with the update entity?

Play around with these in developer tools → templates and see if you can get what you want:

{% set updates = states.update | selectattr('attributes.device_class', 'eq', 'firmware') | selectattr('state', 'eq', 'on') | list %}
{{ updates | map(attribute='entity_id') | map('device_attr', 'name') | list }} 
{{ updates | map(attribute='entity_id') | map('device_id') | list }} 
1 Like

Thanks, I think this is a good direction, will post back here with my next version