Access to Zigbee2MQTT base topic or integration context in automations

Title: Access to Zigbee2MQTT base topic or integration context in automations

Body:

Hi everyone! :wave:

I’d like to request a feature related to multi-instance Zigbee2MQTT setups in Home Assistant.

:loudspeaker: The problem

When running multiple Zigbee2MQTT instances (e.g., in separate buildings, zones, or coordinators), devices may have overlapping or similar entity names like:

binary_sensor.kitchen_water_leak
binary_sensor.kitchen_water_leak_2

But these entities belong to different Zigbee2MQTT integrations (with different base MQTT topics), and there’s currently no way in automations to detect or access which base topic a device is tied to.

This makes centralized automations extremely difficult to manage without hardcoding or duplicating logic.

:x: Limitations today

  • There is no way to get the base MQTT topic of a Zigbee2MQTT entity in automations.
  • Accessing the area in templates is technically possible, but only if the entity has been manually assigned to an area — and this doesn’t reflect the actual Zigbee2MQTT instance or topic.
  • There’s no built-in device.zigbee2mqtt_topic, zigbee_instance, or similar metadata.

:white_check_mark: What would help

Allow templates in automations to access:

  • The base MQTT topic an entity is linked to (e.g. zigbee2mqtt_home1, zigbee2mqtt_home2)
  • Or an explicit Zigbee2MQTT instance ID

This metadata could be available via device_attr(), state_attr(), or similar.

:arrows_counterclockwise: Workarounds today

Currently, we are forced to:

  • Encode the Zigbee2MQTT topic in the entity name manually
  • Duplicate automations for each instance
  • Use naming conventions or assign custom attributes outside of HA

None of these scale well for dynamic or large deployments.

:sparkles: Suggested API or template additions

Something like this in templates would be ideal:

{{ device_attr(trigger.entity_id, 'zigbee2mqtt_topic') }}

This would make multi-hub setups much more powerful and allow truly reusable, scalable automations.

Thanks for considering!

Adding an attribute to Zigbee2mqtt entities would be more a feature request for Zigbee2mqtt.

First, vote for your own request.

Why not just use trigger ids?

If you use mqtt triggers, the base mqtt topic is in the trigger.