#Z2M help needed - how do I create a MQTT trigger?

1 messages · Page 1 of 1 (latest)

sturdy hawk
#

Hi all,

I need a brief help from someone more familiar with Zigbe2MQTT.

I have this device with several buttons, and I want to create triggers for my automation. How do I properly transcribe this MQTT messages from MQTT explorer?


{
  "action": "short_press",
  "action_buttons": [
    "k5"
  ],
  "battery": 100,
  "linkquality": 255
}```

This I managed myself and it "works", but I need to take account of which button is pressed (currently it acts for any short_press), so I believe I somehow need to change payload to include both "action" and "action_butons"?

trigger: mqtt
options:
topic: zigbee2mqtt/Wall panel remote/action
payload: short_press


Thanks in advance!
sturdy hawk
celest fulcrum
#

Why not use the abstraction in HA? Way easier and has the advantage that you don't have stuff "hard coded". It gives you 3 option for it.

Device triggers, easiest to select but bit limited in some situation.

Legacy action triggers can still be enabled. Giving you a sensor with the action. They are legacy but at the moment imho the easiest to work with.

Or most future proof way is to go with event triggers. It's officially experimental in Z2M but work fine. Only need to pay attention that you need a separate condition to check the action type as it's not possible to do in the trigger.

sturdy hawk
#

I'm sorry, but what does it mean to "use the abstraction in HA"?
If it's connected to blueprints, I don't want to use this one as it can only handle one function of one button, and with 12 buttons x 3 functions it would create a whole lotta automations. I prefer to have a singe automation, more complicated of course, but with all in.

This is my first Z2M device, I'm usually on ZHA. If this device had ZHA support, I would trigger on raised events, as I do on all my other buttons.

sturdy hawk
#

Actually, thinking more about it, I believe that having trigger like this will definitely reduce the number of triggers, and might also simplify my intended automation! I just might leave it like it is.

However, if someone knows how to modify it, to use both parameters, I would still be interested to know.
Thanks

sturdy hawk
#

Well, I forgot that even if I use trigger like this, I still somehow need to extract the "action_buttons" value so that I could use it later in Choose action, which I also don't really know how to do. :/

sturdy hawk
#

So, I figured it out.
For the trigger, I use only the MQTT topic:
⁨⁨⁨⁨trigger: mqtt options: topic: zigbee2mqtt/Wall panel remote⁩⁩⁩⁩

And then in the logic I need to do 2 template evaluations, first the type of "action" and then the type of "action_buttons". This way it works properly.
⁨⁨condition: template value_template: "{{ trigger.payload_json.action_buttons == [\"k1\"] }}" enabled: true⁩⁩

If there's a more elegant solution, I'm all ears!
Thanks

celest fulcrum
#

The abstraction is that you see it as device and/or entity within HA. Z2M makes them for basically everything

sturdy hawk
celest fulcrum
#

That's indeed the default. But you can just select them as a device trigger.

#

Alternative you can enable legacy action sensors or event entities. First used to be the way and is now superseeded by event entities. Although the HA implementation is still work in progress, they are better then direct MQTT IMHO