How to find the slug for an addon by entity using a Template?

I’m at the going-arond-in-circles point. I want to make this call in an automation to restart an addon:

action: hassio.addon_restart
data:
  addon: "{{ addon_slug }}"

I know how to manually find the slug, but I’m trying to see if I can do it by just knowing an entity_id using a template.

I can get the integration from an entity using device_attr on an entity using the identifier attribute name:

{% set addons = device_attr(
  'sensor.800_series_long_range_gpio_module_status',
  'identifiers')
  |list 
%}

addons = {{ addons }}
integration = {{ (addons|first)[0] }}

Resulting in:

addons = [('zwave_js', '3348931564-1'), ('zwave_js', '3348931564-1-634:4:1553')]
integration = zwave_js

BTW, what does the identifier (e.g. “'3348931564-1-634:4:1553”) represent?

But, I’m stuck trying to get the slug for the hassio.addon_restart call.

I have found a post using sensor.supervisor_updates that shows the slug, but I don’t have that sensor and can’t find docs on it – and it wouldn’t apply if it’s just showing pending updates. So, no use here.

Is hard-coding the slug in my automation the only option?

Thanks.

It’s a Command Line Sensor that references the Supervisor API to get a list of addons.


FWIW, this lists addon slugs.

{{ integration_entities('Supervisor')
  | select('match', 'update')
  | reject('match', 'update\.home_assistant')
  | map('device_attr', 'identifiers')
  | flatten | reject('eq', 'hassio') | list }}

NOTE

To my knowledge, there’s no recorded relationship between an entity_id and an addon (by poking around the registry files in the hidden .storage directory).

For example, I can discover that an entity is part of a device and that device is provided by the MQTT integration and it is part of another device named Zigbee2MQTT Bridge. Now I know, through inference, that the entity is part of the Zigbee2MQTT addon. However, I cannot find any direct linkage between the Zigbee2MQTT Bridge device and the actual Zigbee2MQTT addon.

Thanks for the explanation. Hard-coding the slugs in an automation is simple. I just assumed there must be a way to get there in a template.

Still curious about what those attributes are used for:

[('zwave_js', '3348931564-1'), ('zwave_js', '3348931564-1-634:4:1553')]

My guess is it’s how zwave-js uniquely identifies each device. It’s similar to how Zigbee2MQTT identifies each device (using its unique network address).