Zigbee2Mqtt buttons doesn't reports first press on automations as action

I have TS0042 button added from Zigbee2Mqtt.
When I restart my NAS where is the HA with Zigbee2Mqtt and use the button first time I see in the entity that HA have got the action. I see it here (it changes action to 1_single):

Image

But in my automation “1_single” actions is not triggered. It is triggered when I press it again. Why?

I have made workaround that monitor state change and it worked but for next times I get 2 triggers invoked and it won’t work if the state of the button was “1_single” already. It look like this:

Image
First press - “When Event type of Przyciski łazienka Action changes to 1_single” is triggered
Next presses - both are triggered

Logs from first button press:

2025-04-04 13:01:16.439 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.przyciski_lazienka_battery, old_state=<state sensor.przyciski_lazienka_battery=unknown; state_class=measurement, unit_of_measurement=%, device_class=battery, friendly_name=Przyciski łazienka Bateria @ 2025-04-04T13:01:02.927690+02:00>, new_state=<state sensor.przyciski_lazienka_battery=98; state_class=measurement, unit_of_measurement=%, device_class=battery, friendly_name=Przyciski łazienka Bateria @ 2025-04-04T13:01:16.439508+02:00>>
2025-04-04 13:01:16.444 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=event.przyciski_lazienka_action, old_state=<state event.przyciski_lazienka_action=2025-04-04T10:33:19.081+00:00; event_types=['1_single', '1_double', 'hold', '2_single', '2_double'], event_type=2_single, icon=mdi:gesture-double-tap, friendly_name=Przyciski łazienka Action @ 2025-04-04T13:01:02.925220+02:00>, new_state=<state event.przyciski_lazienka_action=2025-04-04T11:01:16.439+00:00; event_types=['1_single', '1_double', 'hold', '2_single', '2_double'], event_type=1_single, icon=mdi:gesture-double-tap, friendly_name=Przyciski łazienka Action @ 2025-04-04T13:01:16.443382+02:00>>
2025-04-04 13:01:16.489 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: device_automation 0x187a3efffe3bafb7 action_1_single from external application Zigbee2MQTT, version: 2.2.0, support URL: https://www.zigbee2mqtt.io

Second press:

2025-04-04 13:08:08.956 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=event.przyciski_lazienka_action, old_state=<state event.przyciski_lazienka_action=2025-04-04T11:01:16.439+00:00; event_types=['1_single', '1_double', 'hold', '2_single', '2_double'], event_type=1_single, icon=mdi:gesture-double-tap, friendly_name=Przyciski łazienka Action @ 2025-04-04T13:01:16.443382+02:00>, new_state=<state event.przyciski_lazienka_action=2025-04-04T11:08:08.955+00:00; event_types=['1_single', '1_double', 'hold', '2_single', '2_double'], event_type=1_single, icon=mdi:gesture-double-tap, friendly_name=Przyciski łazienka Action @ 2025-04-04T13:08:08.955922+02:00>>
2025-04-04 13:08:08.956 DEBUG (MainThread) [homeassistant.components.automation.wlacz_radio_w_lazience] Automation trigger 'None' triggered by mqtt topic zigbee2mqtt/Przyciski łazienka/action

Zigbee2Mqtt version: 2.2.0

Post your automation (as formatted YAML).

alias: Włącz radio w łazience
description: ""
triggers:
  - trigger: state
    entity_id:
      - event.przyciski_lazienka_action
    id: RADIO_NS
    to: 1_double
    attribute: event_type
  - trigger: state
    entity_id:
      - event.przyciski_lazienka_action
    to: 2_double
    id: LOCAL_RANDOM
    attribute: event_type
  - trigger: state
    entity_id:
      - event.przyciski_lazienka_action
    to: hold
    id: 1_HOLD
    attribute: event_type
  - domain: mqtt
    device_id: fdc205a748e340201822f6c1ecee2b23
    type: action
    subtype: 1_single
    trigger: device
    id: RADIO_ON
  - trigger: state
    entity_id:
      - event.przyciski_lazienka_action
    to: 1_single
    attribute: event_type
    id: RADIO_ON
    enabled: true
  - domain: mqtt
    device_id: fdc205a748e340201822f6c1ecee2b23
    type: action
    subtype: 2_single
    trigger: device
    id: RADIO_OFF
conditions: []
actions:
  - if:
      - condition: trigger
        id:
          - RADIO_NS
    then:
      - action: media_player.play_media
        target:
          entity_id: media_player.lazienka
        data:
          media_content_id: library://radio/8
          media_content_type: music
        metadata:
          title: Móje Radio Nowy Swiat
          thumbnail: null
          media_class: music
          children_media_class: null
          navigateIds:
            - {}
            - media_content_type: music_assistant
              media_content_id: radio
  - if:
      - condition: trigger
        id:
          - RADIO_OFF
    then:
      - metadata: {}
        data: {}
        action: media_player.media_stop
        target:
          entity_id: media_player.lazienka_2
  - if:
      - condition: trigger
        id:
          - RADIO_ON
    then:
      - action: media_player.play_media
        target:
          entity_id: media_player.lazienka
        data:
          media_content_id: library://radio/7
          media_content_type: music
        metadata:
          title: Moje 357
          thumbnail: null
          media_class: music
          children_media_class: null
          navigateIds:
            - {}
            - media_content_type: music_assistant
              media_content_id: radio
  - if:
      - condition: trigger
        id:
          - LOCAL_RANDOM
    then:
      - action: music_assistant.play_media
        metadata: {}
        data:
          enqueue: play
          media_id: 4
          media_type: playlist
        target:
          device_id: ac157e69a4f1edfe8e286d25175daaaa
  - if:
      - condition: trigger
        id:
          - 1_HOLD
    then:
      - action: media_player.play_media
        target:
          entity_id: media_player.lazienka
        data:
          media_content_id: library://radio/9
          media_content_type: music
        metadata:
          title: Moje nme1
          thumbnail: null
          media_class: music
          children_media_class: null
          navigateIds:
            - {}
            - media_content_type: music_assistant
              media_content_id: radio
mode: single

When using an event entity, if you want to detect two consecutive identical button events you have to make the State Trigger detect all button events and then use a choose to determine which button event occurred.

In other words, instead of doing this:

  - trigger: state
    entity_id:
      - event.przyciski_lazienka_action
    id: RADIO_NS
    to: 1_double
    attribute: event_type

You must do this:

  - trigger: state
    entity_id:
      - event.przyciski_lazienka_action
    not_from: unavailable 

Then use a choose in the automation’s actions to determine which button event occurred.


actions:
  - variables:
      event: "{{ trigger.to_state.attributes.event_type }}"
  - choose:
      - conditions: "{{ event == 'on' }}"
        sequence:
           ... etc ...
      - conditions: "{{ event == 'off' }}"
        sequence:
           ... etc ...
      - conditions: "{{ event == '1_double' }}"
        sequence:
           ... etc ...

I posted an example here and you find a detailed explanation with more examples here.

If you’re interested, I posted my observations on the process of converting one of my automations to detect consecutive identical button events in this post:

Thank you. My problem actually is with event “type: action”. Will your solution work when I press button second time (the state will not change)?

Edit: It works. I still wonder why “type: action” is not triggered first time still.

Glad to hear it worked for you.

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which indicates to others that the topic has been solved. This helps other users find answers to similar questions.

I have created blueprint with your solution: https://community.home-assistant.io/t/zigbee-button/883162