Switches sometimes don't trigger automation (after sleep?)

I have a few different IKEA multi button switches that I use in an automation to re-map their default behaviours. The issue I run into is the first button click after a period of inactivity does not trigger the automation. The subsequent button clicks all work as they should (though the same issue happens if i then pick up my second IKEA switch). Intuitively this seems like the device is in a sleep state where the first press to wake it up is simply lost somewhere.

My setup uses a Sonoff Zigbee dongle with Zigbee2MQTT. Here’s the Z2M log of two subsequent button presses. They both seem to have registered here, but only the second one actually reached the automation to create a trace and run the action. I can not see that the first press reached any further.

>> First press:
info 2025-03-27 10:37:28z2m:mqtt: MQTT publish: topic 'zigbee2mqtt/Switch_1', payload '{"action":"off","battery":100,"identify":null,"linkquality":83,"update":{"installed_version":33816593,"latest_version":33816598,"state":"available"}}'
info 2025-03-27 10:37:28z2m:mqtt: MQTT publish: topic 'homeassistant/device_automation/0x040d84fffebb1a9b/action_off/config', payload '{"automation_type":"trigger","device":{"hw_version":1,"identifiers":["zigbee2mqtt_0x040d84fffebb1a9b"],"manufacturer":"IKEA","model":"STYRBAR remote control","model_id":"E2001/E2002","name":"Switch_1","sw_version":"2.4.11","via_device":"zigbee2mqtt_bridge_0x00124b0025e1db42"},"origin":{"name":"Zigbee2MQTT","sw":"2.1.3","url":"https://www.zigbee2mqtt.io"},"payload":"off","subtype":"off","topic":"zigbee2mqtt/Switch_1/action","type":"action"}'
info 2025-03-27 10:37:28z2m:mqtt: MQTT publish: topic 'zigbee2mqtt/Switch_1/action', payload 'off'

>> Second press:
info 2025-03-27 10:37:59z2m:mqtt: MQTT publish: topic 'zigbee2mqtt/Switch_1', payload '{"action":"off","battery":100,"identify":null,"linkquality":83,"update":{"installed_version":33816593,"latest_version":33816598,"state":"available"}}'
info 2025-03-27 10:37:59z2m:mqtt: MQTT publish: topic 'zigbee2mqtt/Switch_1/action', payload 'off'
info 2025-03-27 10:37:59z2m:mqtt: MQTT publish: topic 'zigbee2mqtt/Kitchen_Light', payload '{"brightness":254,"effect":null,"identify":null,"linkquality":61,"power_on_behavior":null,"state":"ON","update":{"installed_version":587753009,"latest_version":587753009,"state":"idle"}}'

My automation triggers are set up in the following way (I’m not too confident about these cause I’m new to HA):

triggers:
  - domain: mqtt
    device_id: b7cf4f5c9a25b561c16798289ee99d45
    type: action
    subtype: "on"
    discovery_id: 0x040d84fffebb1a9b action_on
    id: UP
    trigger: device
  - domain: mqtt
    device_id: b7cf4f5c9a25b561c16798289ee99d45
    type: action
    subtype: "off"
    discovery_id: 0x040d84fffebb1a9b action_off
    id: DOWN
    trigger: device
  ...etc

Could there be something unique about the first “wake up” event that doesn’t match up with how my triggers are set up? They seem similar enough in the Z2M log but I’m still not sure.

https://community.home-assistant.io/t/mqtt-messages-ignored-sometimes/869807

Thank you, switching to MQTT triggers did indeed solve the issue. Perhaps this should’ve been an obvious configuration, but I’ve ran into numerous posts with this question and none of them had this solution in the thread. Hopefully this one is helpful to those who are experiencing the issue at least.