It may be a controversial oppinion but I generally do not these like blueprints that tries to do everything. Only the author understands what it is doing and it is super difficult to modify it unless you are really good at yaml and jinja. It keeps people stupid.
Bobby. It is easy to fix your automation. First step is to just accept that your trigger will only have one thing it triggers for with no to values and no trigger IDs.
The next two steps are.
Find out what your event entity is. It is called event.name_of_device_action
Go to developer tools ā States and find your event entity. Look at the attributes in the right column. You should see event_types listing all the values that event_type can have. Also look for an optional button attribute. There is no list of buttons but if you press your remote buttons one by one you see the names.
Now you have the information you need. All you need now is to update your old automation with the super simple trigger exactly like my examples except for the event entity name.
And in your actions in the choose conditions you replace your conditions by the template conditions adjusting the values with the ones you found in step 2. And Bobās your uncle.
I converted my triggers to use MQTT and it works fine and is simple. But maybe Iām missing something when Iām using this instead of this complicated action events way?
triggers:
- trigger: mqtt
topic: zigbee2mqtt/TuYa button/action
payload: single
id: single
- trigger: mqtt
topic: zigbee2mqtt/TuYa button/action
payload: double
id: double
- trigger: mqtt
topic: zigbee2mqtt/TuYa button/action
payload: hold
id: hold
There are many ways to do things including the old legacy way which we can see on the Zigbee2MQTT github discussion probably will live for a long time, longer than communicated last week. Triggering directly on the MQTT messages is also a way. Iād it can quickly be complex if you have to combine multiple attributes.
The purpose of this forum thread is to share knowledge about how to use the new event triggers
Youāre not missing anything. Youāre using one of several ways to interact with a device via Zigbee2MQTT.
MQTT Device Trigger and State Trigger (using an event entity or the deprecated sensor entity) communicate with the physical device (via Zigbee2MQTT) using concepts unique to Home Assistant (Device Triggers and entities).
These concepts provide additional features such an event entityās history can be recorded and, when triggered, one can compare its previous state to its current state (i.e. previous button event to current one). They also serve as an additional layer of abstraction, meaning that the way you interact with an event entity is the same regardless of which integration (Zigbee2MQTT, ZHA, zwave, etc) represents the physical device.
In contrast, an MQTT Trigger directly references the physical deviceās MQTT topic. Effectively, it bypasses the use of any āmiddlemanā (such as Device Trigger or event/sensor entities) and uses the direct, raw feed from Zigbee2MQTT. It canāt take advantage of the middlemanās additional features but a given application might not need them.
FWIW, in the example you posted, containing one MQTT Trigger per button event, it can be reduced to a single trigger. A choose can separate which button event occurred based on trigger.payload.
The underlying issue is that some devices have pretty idiosyncratic exposes (i.e. some like this Tuya device have additional payload keys that are related to the action but technically separate). The current event implementation does not handle these āextraā data points at all (thatās one of the reasons why it is labelled āexperimentalā). There is an ongoing discussion on how to best handle these things in the future (mostly on a technical level - e.g. will there be a new JSON object in state collecting all the relevant attributes).
I understand, but for the time being, they can use the sensor for that additional information if they want to transition to the event entity. Otherwise they can stay with the legacy sensor entity.
Sure. I just wanted to explain that it was not an oversight, but rather a minimal implementation that was intended to be extended in future iterations (before 2.0.0), but got stuck in an architecture discussion.
For now, personally Iād probably stay with the legacy sensors if I had been using those before on a large scale, and only transition a few of my less complex automations to get the feel for event entities. I hope something happens for the WTH you created, itās really detracting from the ease of use for event entities. Since I was using Hue dimmer switches for testing, I didnāt even notice that the event_type was not updating for repeated presses (because those have separate actions for press, hold, and release, so the attribute always updates during a cycle).
Itās not there.
Depending on how you trigger the automation you get either direction, xor step size.
I also miss the point of having event brightness_step + direction while device sends brightness_step_up or brightness_step_down as actions.
Ok, but which direction did the knob turn?
This is triggered by event *action_step_size - no indication of up/down. Just the number of ticks registered by the knob.
Or am I missing something?
I was missing this: states('sensor.przelacznik_sciemniacz_czarny_1_action_step_size')
Thanks a lot. Iāll try it later, as for now I just moved back to 1.42.
Note the odd way that the hold function requires to AND the event_type and the button. The rest are nice and simple event_types. How did it end up like that?
When you look at the raw MQTT the message are simple button_6_hold. I do not even understand how it ends up like that in HA. It must be a bug. And when you fix it you break things again and people will be grumpy. Can you explain why it is like that? It cannot be intentional?
It is intentional in that the raw action strings are parsed and broken up into the actual action (the event_type) and other attributes (like button). It is not intentional in that of course all actions of a device should be treated consistently.
The reason why things come out weirdly for this specific device is that the initial experimental/poc implementation (for 1.42.0, this is not a new feature in 2.0.0!) has a bunch of regular expressions to try and parse the action payload strings that were designed by looking at zigbee-herdsman-converters/src/devices at master Ā· Koenkk/zigbee-herdsman-converters Ā· GitHub but of course not tested with all of them. It happens that button_<x>_hold matches the regex intended to showcase the features of HA event entities with the Hue dimmer while button_<x>_single does not.
PS: A benefit of short āgenericā event_types is HAās frontend translation could localize them.
I am fine with either. It was the inconsistancy that concerned me. Now I understand the regex discussion I read earlier on the Z2M github. Thanks for taking the time to explain it @mundschenk-at
Sure, but this topic isnāt about continuing to use a deprecated method that will eventually be eliminated.
The event entity was designed to be integration agnostic. Once you learn how to work with it, you can manage button events regardless of the deviceās integration.