Using the new action events in Zigbee2MQTT 2.0

This seems like a massive headache to me. I use Node Red, and could previously just select a button action and create a flow with it. No longer it seems.

3 Likes

The Zigbee2MQTT devs seems to know that the new feature needs more work and extended the deprecation period of the old way. Just enable the legacy way again and wait for a better way for Node Red etc.

I’d hope this topic to be a help topic with solutions so if others have more examples of other switches, paste them in follow up messages to this topic. The more working verified examples we have the easier it will be to migrate. And if there are Node Red examples please go ahead. I do not use Node Red so I cannot give any examples.

1 Like

Hi
I have a Philipps 4 button dimmer
Can you explain how to find the event entity for the switch/remote from HA Developer Tools → States
I don’t see any event in this page for my Philipps device

Did you upgrade to Zigbee2MQTT 2.0?

Also restart HA and refresh browser cache may be needed sometimes

yes i did it and still nothing

First lets see if it is supposed to be there

If you go to Integrations → MQTT and find your device. Click on it.

You should see something like this for a 4-button Hue switch

Note that there is an Events window in center column at the top.

You should see an Action device there.

Unfortunately there is no UI in this view that can show attributes. You have to go to developer tools → States (NOT Actions!)

In the top of Filter Entities you can type event. and you should see your remotes

Here are a sniplet of mine

2 Likes

Strange it is not really the same thing

1 Like

Something is wrong. Your screen looks like before Zigbee2MQTT 2.0. It is not picking up the changes.

Look at your setttings in zigbee2mqtt.

If you want events to show up, select “Home Assistant experimental even entities”.
You can also select “Home Assistant legacy action sensors” and all is working as before the upgrade tot zigbee2mqtt 2.0

6 Likes

perfect thank you

I set that already in the December release and assumed it was on by default on a 2.0. It is not experimental any longer.

Hi everyone, since i struggled for an hour or so to find a solution for my Hue Switch and bridge my existing flows in node-red with the new event types, i am sharing the below for reference and hopefully helping someone in the process.

In the past i was getting on my hue dimmer a payload like
“on_press_release” or “off_press_release” etc for each button i was using. This msg was then passed to a switch node and depending on the payload different actions were activated.

On my exploration of the message received from the new events, i realized that i wanted to refer to the msg.data.new_state.attributes.button and msg.data.new_state.attributes.event type which they hold the information i needed for the switch node to work. So, i wrote a small function that gets the msg data from the message and jointed the values to create the old behaviour, while keeping the new changes as is.

// Example: Node-RED Function node
// Assume the incoming msg contains data in msg.data.new_state

const newState = msg.data.new_state;

if (newState && newState.attributes) {
    const buttonValue = newState.attributes.button;
    const eventType = newState.attributes.event_type;

    // If both properties exist, create a combined string.
    if (buttonValue && eventType) {
        msg.payload = `${buttonValue}_${eventType}`;
    } else {
        // If either property is missing, handle it gracefully.
        msg.payload = null;
    }
} else {
    // If msg.data.new_state or .attributes is missing, handle it.
    msg.payload = null;
}

// Return the updated message.
return msg;

For this to work, i use an event node for the device action entity, i pass the event to this function node, and the output to my switch which i handled the different actions.

I hope this will help someone like me to cope with the new changes.

2 Likes

Thanks @KennethLavrsen for the write-up. I tried this out earlier today but instead using the example YAML provided at Event - Home Assistant

In the couple of hours since I set that up I had been seeing a lot of “ghost events” where lights were toggled on without actual button presses. According to the logbook it was due to state of the event.xyz entity changing but without any more detail than that. Is this because I didn’t include a condition for “unavailable”, or maybe the "to: null" part of the trigger?

I’ve since reverted to using mqtt triggers, which so far seem to be working ok and don’t require a lot of code refactoring:

    - trigger: mqtt
      topic: "zigbee2mqtt/Kitchen Xiaomi Cube White/action"
      payload: "tap"

The topic you refer to seems written with ZHA in mind.

This start of the automation

triggers:
  - trigger: state
    entity_id: event.bedroom_switch_action
    to: null
conditions:
  - condition: template
    value_template: "{{trigger.from_state.state != 'unavailable'}}"

comes from the newly added documentation for Zigbee2MQTT so I am sure the extra bits added there are added for a good reason.

Yes, you can also use the old MQTT way. I never tried that so I cannot say if it would be easier or more difficult. There must be a reason the event way was added to Zigbee2MQTT. The old binary_sensor way was always marked as not recommended and to be deprecated so that is why I was avoiding it.

So, just a quick question for confirmation.

In order to prepare for the move to 2.0, is this considered best practice?

  1. In the Zigbee2MQTT settings, I enable ‘Home Assistant experimental event entities’ but keep the ‘Home Assistant legacy triggers’ box ticked still.

  2. Restart Zigbee2MQTT

  3. Change the YAML code from

alias: BTN_07 Double Click 4 Printer
description: ""
mode: single
triggers:
  - entity_id: sensor.xa_btn_07_action
    to: double
    trigger: state
conditions: []
actions:
  - data: {}
    target:
      entity_id: switch.officeplug_6
    action: switch.toggle

to

alias: BTN_07 Double Click 4 Printer
description: ""
mode: single
triggers:
  - trigger: state
    entity_id:
      - event.xa_btn_07_action
    to: double
    attribute: action
conditions: []
actions:
  - data: {}
    target:
      entity_id: switch.officeplug_6
    action: switch.toggle
  1. Test & Ready to go!

  2. Once I’ve done this for all my sensor actions I upgrade to Z2M 2.0 and I’m fine?

Or do I also need to make changes to MQTT topics and/or anything else?

Addition after seeing the last post:

Should I add this condition to all automations as well?

conditions:
  - condition: template
    value_template: "{{trigger.from_state.state != 'unavailable'}}"

I noted when I enabled some entities of a Zigbee2MQTT device that the entire MQTT integration goes off and on on again making 1000+ entities go unavailable for a short moment. It seems to avoid a lot of false triggers of automations to have that extra condition. I can think of many examples where we upgrade Zigbee2MQTT or MQTT server itself where we have a lot of events going to unavailable and back.

1 Like

After zigbee2MQTT 2.0 upgrade it died.

zigbee2MQTT now states it cannot find the network address of smlight.

The smlight integration in Home Assistant is finding it fine.


13)
    at start (/app/index.js:161:5)
[19:21:53] INFO: Preparing to start...
[19:21:53] INFO: Socat not enabled
[19:21:54] INFO: Starting Zigbee2MQTT...
Starting Zigbee2MQTT without watchdog.
[2025-01-04 19:21:55] error: 	z2m: Error while starting zigbee-herdsman
[2025-01-04 19:21:55] error: 	z2m: Failed to start zigbee-herdsman
[2025-01-04 19:21:55] error: 	z2m: Check https://www.zigbee2mqtt.io/guide/installation/20_zigbee2mqtt-fails-to-start_crashes-runtime.html for possible solutions
[2025-01-04 19:21:55] error: 	z2m: Exiting...
[2025-01-04 19:21:55] error: 	z2m: Error: Cannot discover TCP adapters at this time. Specify valid 'adapter' and 'port' in your configuration.
    at findTCPAdapter (/app/node_modules/.pnpm/[email protected]/node_modules/zigbee-herdsman/src/adapter/adapterDiscovery.ts:470:15)
    at discoverAdapter (/app/node_modules/.pnpm/[email protected]/node_modules/zigbee-herdsman/src/adapter/adapterDiscovery.ts:496:26)
    at Function.create (/app/node_modules/.pnpm/[email protected]/node_modules/zigbee-herdsman/src/adapter/adapter.ts:68:54)
    at Controller.start (/app/node_modules/.pnpm/zigbee-herdsman@3

Trying to figure it now.

Specify your adapter in the config

SLZB-06 over Ethernet was working great prior to 2.0
:frowning:

Trying work out the extra config v2.0 needs