Using the new action events in Zigbee2MQTT 2.0

Three months ago, someone else asked the same question. It was answered here:


I changed my automations from using legacy sensor entities to the new event entities. It wasn’t difficult; I shared my observations in this post.

1 Like

hi,
I am looking for some help with this xiaomi button. in the states it has the following:

image

I need an automation to toggle a sonoff switch with single press, but I can not make it.

I tried the following but it is not working. I need something in this format if possible (easier for me to understand) . I read at the top post that I shouldn’t use “to: single” but I don’t know ow to adjust the code

  alias: Xiaomi Button Kitchen LED event
  description: 'Toggle kitchen LED using Xiaomi button via event'
  triggers:
    - trigger: state
      entity_id:
        - event.xiaomi_button_action
      to: single
#      attribute: action
  condition: []
  actions:
    - data: {}
      target:
        entity_id: switch.sonoff_10009bd11e
      action: switch.toggle
    - delay:
        seconds: 0.0
    - data: {}
      target:
        entity_id: switch.sonoff_1000a05283
      action: switch.toggle
  mode: single

just add a state condition that looks at the event_type attribute.

1 Like

thanks. I think there will be a more elegant way but the following is working

- id: xiaomi_button_kitchen_led event
  alias: Xiaomi Button Kitchen LED event
  description: 'Toggle kitchen LED using Xiaomi button via event'
  triggers:
    - trigger: state
      entity_id:
        - event.xiaomi_button_action
#      to: single
#      attribute: action
  condition: []
  actions:
      - choose:
          - conditions:
              - "{{trigger.to_state.attributes.event_type == 'single'}}"
            sequence:
                - data: {}
                  target:
                    entity_id: switch.sonoff_10009bd11e
                  action: switch.toggle
                - delay:
                    seconds: 0.05
                - data: {}
                  target:
                    entity_id: switch.sonoff_1000a05283
                  action: switch.toggle
  mode: single

When will be the old method (pre 2.0) get obsolete/deprecated?
I havent upgraded yet from 2.4.1, and i gues i will have to do it sooner or later.

You can upgrade.

If you need the legacy action sensors; it is (for now) still available, just tick Home Assistant legacy action sensors and you will be able to use as before :wink:

1 Like

Ok thank you, will do that.
And do we know when will get obsolete/deprecated that option?

It is under discussion still

Given the feedback and the Node-Red use case, it will not be removed (at least anytime soon)

1 Like

How can I disable a button to switch from command to event mode on three tap?
I’m tearing my hairs out because I do not want that super complicated events mode.

I cannot anymore simply create automations by selecting the device and then choosing of an action that it does.

Instead chosing event I don’t know what to enter at all. it’s way too complicated. It simply should not be possible to change the mode so easily as a three tap. Make it 10 taps or more. Because if you accidentally tap three times when you want to tap 2 times you get stuck in the event mode where nothing works anymore.
So not only would I need to rewrite all automations, I would need to have each automation trigger on both action and event. That’s a crazy mess and makes me want to switch back to ZHA where this never happened.

Oh yeah - clicking the option Home Assistant experimental event entities or whatever inside zigbe2mqtt just gives me an erorr message.

I have tried to create an automation that triggers on change of operation mode from command to event. And then have the action - change back to command. However while the trigger works, the action does nothing. This is seriously messed up right now.

Explanation. I have no clue what I should enter here as event data - I copied in what happens from the log - but that’s just way too complicated. sorry

Now this really should work to clean up the mess, but it doesn’t

You say you want to avoid your device going to event mode, but your automation above does the opposite - it switches your device back to event mode when it goes to command mode.

Basically, change your trigger (When) to event and your action (Then Do) to command.

oh yeah, sorry I got it now. I had changed to inverse because nothing happened. It was not really about the automation.

So in order to have it working I need to enable experimental mode, and enable legacy mode. Only then I can create an automation that will work.
When I had experimental mode off, and legacy on - than tripple tapping would change to event mode - but there was no way to get out of it without tripple tapping again. That’s very counter intuitive.

The really confusing thing is before you activate the experimental mode, you cannot get back out of it except on the device itself.

Also only after activating it - I found events that I can use in automations. Strangely for the button only single click and double click have an according event. The hold action does have no event so it does not work in event mode.

So this is really a bug. If zigbe2mqtt has not enabled the experimental mode - it should not allow any devices to switch to event mode. Because without experimental mode enabled, event mode will fail.

Sorry, you lost me, and the fact that you haven’t even mentioned which device you’re talking about doesn’t help make things any clearer.

Device type
EndDevice
Zigbee Model
TS004F
Zigbee Manufacturer
_TZ3000_ja5osu5g
Description
Smart button
Support status

Supported

IEEE Address
0xa4c13846569613cd
Network address
0x80E8 / 33000
Firmware ID
0122052017
Manufacturer
Loginovo
Model
ZG-101ZL

This device - a simple zigbee tuya button. Only after I enabeld the experimental event mode under z2m settings I was able to solve this.

The default seems to be to toggle on tripple tap from event to command mode. However it’s actually quite hard to press those cheap buttons fast enough to not register the presses as two or three single presses - and sometimes you tripple press instead of double press or vice versa. So without experimental mode enabled - it would switch the button to event mode - which is not enabled in home assistant.

It really should not be possible that a device switches to event mode, when event mode is not enabled. I guess the inverse also has to be checked - do not switch to command mode if the legacy options are not enabled (not sure if that happens too). And the default to switch between action and event mode really should not be possible to happen by accident. It needs to be minimum 5 presses not three. Because 3 happens sometimes if you want to press twice. 4 could happen if a device does not react and you try again a double click. So I find pressing 5 times continously should change the mode.

Nope, you can use device triggers. These other options are so that you can avoid using device triggers. Some people don’t like them.

None of this makes sense here. These entities and turning on those experimental features do not impact device behavior. They are Z2M settings that generate new entities, nothing else. I.e. they only create discovery information for MQTT topics, which HA then generates entities. Both of the entities are read only entities and do not alter device behavior. They only offer a way to look at event stream provided by the device.


If Z2M actually is altering device behavior when you enable those modes, then you should create an issue/support ticket on Z2M’s github page.

I don’t think/or I don’t know if it changes device behaviour - but it changes how z2m interpretes the device. So it really should not be possible to change the mode towards a mode that is not activated in z2m. Because then you click and nothing happens because z2m or home assistant is not ready for it. So I feel there should be some switch that make it possible for each device to restrict it to only event or only command mode and ignores the built in way to switch between modes.

You are confusing device features with z2m features. They are similarly named, but are not the same. You would have had similar issues with z2m 1.x before z2m events existed.

The triple-click event->command mode toggle is a feature of the device itself. Z2M has no control over the behavior when changed via triple-click.

I tossed the buttons I had like this. My work around before tossing was trying to code triggers for both the “command” and “event” mode actions.

It isn’t a z2m issue. It is poor design of the device. It is just too easy to accidentally toggle mode with the triple click.

I can’t speak as to how the device’s command vs event modes interact with z2m 2.x events.

1 Like

You are not making any sense. What do you mean “Mode” if it’s not a mode for the device?

All those experimental buttons do is add entities to HA. Nothing more. Nothing less.

There is no mode.

Can you show a screenshot of what you’re talking about?

EDIT: Maybe @jerrm figured it out?

It never happened to me on ZHA - but constantly on z2M. And yeah the automation does not work for it - because it seems it cannot receive get/set commands.
So in order to set up any automation with those buttons - I have to make sure to first do it in one mode, then switch the mode on the device via tripple click, then go back to the automation and add the triggers for the other mode ( because if I never pressed the button in the mode - then it’s not shown in the automations)

I think actually that it what was possible with ZHA by default - there was no need to press any button in each mode to be able to select it for automations.

Also I think with those buttons with ZHA hold was supported in both modes because I remeber I had to always select first button pressed and button pressed in order to have automations fire correctly wondering why this was needed. However hold with z2m is only supported in event mode not in command mode which really makes it tougher again. This kinda renders any action with such a button which uses hold impossible because you never know in which mode it currently is.

Yeah I have other buttons where the automation works and it can automatically reset to event or automatically reset to command mode via automation which is really needed. So maybe there should be some warning here that due to those complications these buttons are not recommended for z2m. I have not used the old 1.4x - I recently switched from ZHA and the user experience with ZHA for the buttons was way superior/easier.

This is device specific. There is no concept of “modes” in Z2M. This is what doesn’t make sense to anyone helping you. So you keep mentioning modes, but we have no idea what you’re talking about. It sounds like @jerrm actually figured out what you’re saying but you haven’t confirmed that.

You’re thinking of Device triggers which I mentioned a few posts ago, which still work for Z2M with the pre-selectable list you’re talking about.

yes jerm figured out what my problem was. And I guess either accepting to only use single and double click (or on and off as it’s called in command mode for that device) or tossing them is the only possibility.
Hold is only working using ZHA because somehow ZHA for that button can understand hold in both modes and not only in event mode.

I had believed that it’s z2m that creates a virtual difference between event and command mode. I would actually need to try what happens if I tripple click without reception to the zigbee mesh - will it still change or not?

With it being so easy to mess up a double click and click three times and no way for z2m to put the device into either of those modes - those buttons are a bit broken.

But yeah it’s worse if you have not activated the experimental mode in z2m settings - and then you accidentally switch the button to command mode, and home assistant shows absolutely nothing in the log when you press the button. So I thought it lost connection or needs to be relearned. Only switching it to event mode via tripple click in that case made it work again causing even more frustration.