Made a zigbe2mqtt device selector, need help

Hey, Maybe someone can help me with this one…

I added a sensor to my configuration:

mqtt:
  sensor:
    - name: "Zigbee2MQTT Devices"
      state_topic: "zigbee2mqtt/bridge/devices"
      value_template: >
        {% set devices = value_json | map(attribute='friendly_name') | list %}
        {{ devices | join(', ') }}

This manages to get me a comma seperated list of the device friendly_names for zigbee2mqtt.

  • i.e “Coordinator, Motion1, Cube, Vibration1, FourPad”

I then have an automation such that everytime sensor.zigbee2mqtt_devices updates, the values are written to an input_select.zigbee_devices_selector helper.

Now, I managed to make a dropdown selector that lists everything in input_select.zigbe_devices.

topic:
  name: topic
    selector:
      state:
        entity_id: input_select.zigbee_device_selector

So, the issue I am having is this:

  • I need to make the trigger topic be zigbee2mqtt/!topic topic2, but home assistant wont parse the !topic part of that line.
trigger:
  - platform: mqtt
    topic: zigbee2mqtt/{{!input topic}}

So, the issue I am having is this:

  • I need to make the trigger topic be zigbee2mqtt/!input topic, but home assistant wont parse the !input part of that line.
    i.e. I need to concatenate "zigbee2mqtt/" + !inputtopic

Any ideas you might have would be extremely helpful.
Thanks!

You can’t use inputs directly in templates like that. First you need to assign the value to a YAML variable, then use that variable in the template. Since this is for use in the trigger, you need to assign it under the trigger_variables key:

trigger_variables:
  topic: !input topic

trigger:
  - platform: mqtt
    topic: zigbee2mqtt/{{topic}}

However, there are a few issues with your setup… one major one being that it all hinges on storing an expanding string of names in a state. States are limited to 255 characters, so
the device names held by the MQTT sensor will overrun the available space at some point and then it will return unknown as its state.

What is the actual goal here?

1 Like

When writing a blueprint for z2m devices (such as the aqara cube), the trigger event is some event in zigbee2mqtt/cube in my case.
For me personally, it is simple to just manually set the trigger topic by hand.
And I could even just make the input a text field and have a user input the topic name.

But I’m trying to make a blueprint where the user does not have to go investigate and find the topic for their device. I want it to just be a dropdown where they can choose it from a list.

But, as far as I can tell, there isn’t a simple way of doing this.
This method isn’t done by any means either. I still want to find a better way.

Maybe map z2m topics as devices? Idk. I’m still new to the more nuanced side of HA.

Thank you so much for the help!

the topic is the same as the devices configured name in Z2M. You dont need to find the topic specifically.

1 Like

Very true. I guess I would just prefer a dropdown selector rather than manually entering it.
When I set mine up the first time using a blueprint by @Sir_Goodenough I misspelled “zigbee” and forgot to capitalize the device name. A very simple and stupid mistake, sure. But If I’m going to write blueprints that I’d like to actually share, I guess I’d like to make them as dead-simple as I can.

I don’t mind putting in the extra work once to make it as easy for the next person.
But, I do acknowledge that I am prone to “going too far” and that this may be futile.

1 Like

You know you can certainly do the cube with entities or devices. I chose to use MQTT topics because Z2M has several ‘choices’ that change the addressing, legacy addressing (I think 2 kinds) and suggested addressing. People were mix-matched on all types, and I decided that using MQTT and topics everybody had the same. I also use an MQTT discovery to provide the missing last side information for the cube functions that inexplicably don’t have it. So with different design choices you would not need to look up and store the topics.
If you look in my git repo, there is a deprecated version of the Z2M cube blueprint that does not use MQTT at all.
That’s just a little background if you are interested or want to use some of the code from the one I no longer use.

Oh, cool!
I actually used your blueprint and another one built for zha as inspiration and wrote my own version.
I even included rotate-per-side options and enable/disable for flip90/flip180/flip_any/flip_specific/tap/slide/shake/rotate.

When I finish it, I can share it and tag you so you can take a look at it if you like.
It was yours that made me want to get into the blueprinting at all and enabled me to write one for the tuya/moes 4-gang buttons.

1 Like