Mqtt trigger topic from device input selector?

I am trying to create a blueprint for ZEN32 scene controllers via mqtt. I’m aware that there is a blueprint for this already here, but I am trying to do it without individually selecting the scene sensor (similar to this blueprint). I should be able to use the device input selector to get a device_id, and use that id to get an entity_name, which I can then insert into the mqtt trigger topics. However, it’s not working, though I have confirmed via a notification that in the action: portion of the template it is correctly getting an entity_name.

  name: ZEN32 (zwavejs2mqtt)
  description: Zooz ZEN32 via zigbeejs2matt
  domain: automation
      name: Zooz Switch
      description: List of available Zooz ZEN32 switches.
          integration: mqtt
          manufacturer: Zooz
          model: Scene Controller (ZEN32)
          multiple: false

This works perfectly, allows me to select the scene controller, and ultimately gives me a device_id. Omitting a bunch of the irrelevant code, the portion I’m struggling with is:

  device_id: !input zooz_switch
  entity_name: "{{ device_attr( device_id, 'name') }}"
- platform: mqtt
  topic: "{{ 'zwavejs2mqtt/' ~ entity_name ~ '/91/0/scene/005' }}"
  id: mainbutton
- platform: mqtt
  topic: "{{ 'zwavejs2mqtt/' ~ entity_name ~ '/91/0/scene/001' }}"
  id: topleftbutton
- platform: mqtt
  topic: "{{ 'zwavejs2mqtt/' ~ entity_name ~ '/91/0/scene/002' }}"
  id: toprightbutton
- platform: mqtt
  topic: "{{ 'zwavejs2mqtt/' ~ entity_name ~ '/91/0/scene/003' }}"
  id: bottomleftbutton
- platform: mqtt
  topic: "{{ 'zwavejs2mqtt/' ~ entity_name ~ '/91/0/scene/004' }}"
  id: bottomrightbutton
condition: []

However, the triggers don’t work, and I can’t figure out how to get any usable debugging information. I have confirmed that the device_id and entity_name are what I expect by adding a default notification to the blueprint which I can activate by running the automation directly via the UI.

I currently have several of the ZEN32s set up without blueprints, working as expected, but it’s a pain to make any changes. As I purchased about a dozen of them for my house, I’d like to get a working blueprint with as few inputs as possible.

Since I’ve looked at a couple other implementations of the ZEN32 as well as a multitude of other mqtt blueprints, I know there’s probably another way to skin the cat, but I think the blueprint creating a mqtt trigger topic is a worthwhile solution which can be streamlined even more (by using wildcards, which is my next step once I get this working), so I’d like to try to do it this way if it’s possible.

If it’s not possible, can someone explain why? Thanks.

Trigger templates are called limited templates for a reason. You may want to go in the template thread to ask this, you will probably get a template experts opinion on this. But I don’t think you can pull attributes at all (not sure though) and a lot of the template stuff you are doing in the triggers themselves can’t be done as well. (Also variables are not looked at until after the trigger, You could try ‘trigger_variables’ but I still don’t think it will work.)

Things are executed !inputs, (for scripts) fields, (for automations) trigger_variables, (for automations) triggers, variables, conditions, and actions no matter what order you enter them in the automation (or script) dictionary.

I have an example BP using template triggers and templates in triggers successfully, but about all you can do is refer to constants (like entity names and !inputs) and place them in.
Remember the trigger is technically doing stuff before the automation is running, so there is a limited list of things it has available to use.

Best to ask this in the configuration-templates area Topics tagged templates

Thanks for your reply. I did see the warning about ‘limited templates’ but either I misunderstood or the instructions aren’t very clear.

1 Like