Zigbee2MQTT Stopped Working 1/5/2025

In the first attempt the yaml is not valid.

You cannot do this

It is either

         - "{{trigger.to_state.attributes.event_type == 'press'}}"`

Or

          - condition: template
            value_template: "{{trigger.to_state.attributes.event_type == 'press}}"

In your second attempt you use the event entity values for your condition. There is a race condition risk that from the trigger happens till you test the condition, the event entity value may have changed. My examples use the trigger.to_stateā€¦ which gets frozen in time at the moment of the trigger. That is the safe way to do it. Not only for this but any trigger.

I want to get the trigger.to_state.attributes.event_type to work. But, Iā€™m still having difficulty getting it into the automation. Can it only be entered using yaml, or can it be done via visual editor?

With your first attempt

Try and replace

  • condition: ā€œ{{trigger.to_state.attributes.event_type == ā€˜singleā€™}}ā€

By short form

- "{{trigger.to_state.attributes.event_type == 'single'}}"

Or by the normal condition syntax for templates

- condition: template
  value_template: "{{trigger.to_state.attributes.event_type == 'single'}}"

I assume this is a single button and that you just want to toggle and that you have verified the type reported is single

There is also a problem with your many enabled true lines. Indentation is wrong. Remove them. They are pointless

If you simply want each single button event to toggle the switchā€™s state, use switch.toggle.

alias: Testing Zigbee2MQTT v2
description: ""
triggers:
  - trigger: state
    entity_id:
      - event.zigbee_smart_button_action
    not_from: unavailable
conditions:
  - condition: template
    value_template: "{{ trigger.to_state.attributes.event_type == 'single' }}"
actions:
  - action: switch.toggle
    target:
      entity_id: switch.generic_smart_plug
mode: single

If the buttonā€™s event name isnā€™t single then simply replace it with the correct word in the Template Condition.

Looking at your automation. I think all you need is this

alias: Testing Zigbee2MQTT
description: ""
triggers:
  - trigger: state
    entity_id: event.zigbee_smart_button_action
    not_from: unavailable
conditions:
  - condition: template
    value_template: "{{trigger.to_state.attributes.event_type == 'single'}}"
actions:
  - action: switch.toggle
    target:
      entity_id: switch.generic_smart_plug
mode: single

The switch.toggle action should just work. No need to check if switch is on or off. And since you only have one button type it can go directy in the condition of the automation instead of if then or a choose in the action

Haha. As I posted this 123 posted exactly the same.

1 Like

Thank you @KennethLavrsen. I believe I have things working correctly now. The if/then was a remnant of a larger script I tried to trim down for simplicity. But, it was just confusing. Here is the full script that toggles 2 different lights on/off using either the single press (light #1) or double press (light #2).

alias: Testing Zigbee2MQTT v2
description: ""
triggers:
  - entity_id:
      - event.zigbee_smart_button_action
    id: Smart button
    trigger: state
    not_from: unavailable
    enabled: true
conditions: []
actions:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{trigger.to_state.attributes.event_type == 'single'}}"
          - condition: state
            entity_id: switch.generic_smart_plug
            state: "on"
            enabled: true
        sequence:
          - action: switch.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: switch.generic_smart_plug
      - conditions:
          - condition: template
            value_template: "{{trigger.to_state.attributes.event_type == 'single'}}"
          - condition: state
            entity_id: switch.generic_smart_plug
            state: "off"
            enabled: true
        sequence:
          - action: switch.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: switch.generic_smart_plug
      - conditions:
          - condition: template
            value_template: "{{trigger.to_state.attributes.event_type == 'double'}}"
          - condition: state
            entity_id: light.office_ceiling_lights
            state: "on"
            enabled: true
        sequence:
          - action: light.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: light.office_ceiling_lights
      - conditions:
          - condition: template
            value_template: "{{trigger.to_state.attributes.event_type == 'double'}}"
          - condition: state
            entity_id: light.office_ceiling_lights
            state: "off"
            enabled: true
        sequence:
          - action: light.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: light.office_ceiling_lights
mode: single

Cool. But note that you can reduce your automation to half the size by skipping checking the state of the switches and just use switch.toggle like both 123 and I posted minutes ago. For lights it it light.toggle

Okay. Yeah, way more concise. Thank you for all your help!

Since this seemed to get lostā€¦ is there somewhere that clearly lists actions that need to be taken before upgrading to v2?

Seems to be a mess of information throughout threads and frankly I donā€™t want to have to troubleshoot yet another failed update in my HA after AlexaMediaPlayer last month, and ESPhome a couple of months before thatā€¦
Iā€™m all working after rollback, but these breaking changes which are not properly telegraphed in the UI are silly