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