Using the new action events in Zigbee2MQTT 2.0

So it seems that for me, the migration from legacy actions (needed to enable legacy after 2.0 update to make them work) to new actions just means changing sensor. to event. in the automations. Or am i missing something?

I could do with a little help please. I use Aqara sensors and with the update to v2.0 have lost the sensor for illuminance that I use in NodeRed ie sensor.aqara_hall_illuminance_lux.

I’ve enabled both the legacy options in Zigbee settings, and tried changing sensor.aqara_hall_illuminance_lux to event.aqara_hall_illuminance_lux but neither options work for me, and event.aqara_hall_illuminance_lux doesn’t exist.

Having read through the threads about this update I’ve been unable to find a fix, can anyone point me in the right direction?

PS For now I’ve gone back to v1.42 and enabled experimental entities, this should be the same as v2.0 I think but also keep things working for me whilst I prepare to update?

This is a separate breaking change in version 2.0, nothing to do with legacy options.

The linked discussion on GitHub should give you the necessary solutions if you try the update again.

The new event entities are only created for what you would consider stateless information. Pressing a button on a switch that bounces back is the classic example. Pressing a button that have “on” printed on it it does not leave the remote control in an on state. It just send a momentary message that is called “on”. You can press it multiple times and use it to toggle something on and off or you can increase the sound. Anything. These are events of transmitting the press, or the release, or the long hold etc of a button. This is what events are for.

Illumination is a sensor and it has a state which is a value with a unit lux. They are still good old sensors in Zigbee2MQTT. However 2.0 has a breaking change where the illuminance sensors were renamed so all your old sensors are gone and replaced by new. And to make matters worse they are by default disabled. You have to enable them first in Home Assistance. This takes 30 seconds from you enable them till they show up and another minute or two before the sensor sends a new value so be patient.

3 Likes

You can also stay on v2

  • Enable experimental to keep the event
  • Enable legacy to keep the action per v1
1 Like

I’v converted a automation for my ikea E1743 and E1744 from legacy to event based triggers. All works except the toggle trigger in the E1744. You can switch it off but can not switch it on, because then the event-state does not change (toggle → toggle). You can get it working bij dimming down and then press toggle. So i’m looking for a way to change or clear the state after a toggle. Does anybody has a sollution?

p.s.
Problem Solved
The problem was solved by @mekaneck on discord. I had to remove

    attribute: event_type

in the trigger. All working now!

id: "1736018140368"
alias: kitchentable remote events
description: ""
variables:
  command: "{{ trigger.to_state.attributes.event_type }}"
triggers:
  - trigger: state
    entity_id: event.kitchentable_remote_action
    attribute: event_type
conditions:
  - condition: template
    value_template: "{{ command != ''}}"
actions:
  - choose:
      - conditions:
          - "{{ command == 'on' }}"
        sequence:
          - data:
              transition: 1
            target:
              entity_id: light.kitchentable
            action: light.turn_on
      - conditions:
          - "{{ command == 'off' }}"
        sequence:
          - data:
              transition: 1
            target:
              entity_id: light.kitchentable
            action: light.turn_off
      - conditions:
          - "{{ command == 'toggle' }}"
        sequence:
          - data:
              transition: 1
            target:
              entity_id: light.kitchentable
            action: light.toggle
      - conditions:
          - "{{ command == 'brightness_move_up' }}"
        sequence:
          - repeat:
              count: "20"
              sequence:
                - data:
                    transition: 0.5
                    brightness_step_pct: 5
                  target:
                    entity_id: light.kitchentable
                  action: light.turn_on
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 0
                    milliseconds: 500
      - conditions:
          - "{{ command == 'brightness_move_down' }}"
        sequence:
          - repeat:
              count: "20"
              sequence:
                - data:
                    transition: 0.5
                    brightness_step_pct: -5
                  target:
                    entity_id: light.kitchentable
                  action: light.turn_on
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 0
                    milliseconds: 500
mode: restart
max_exceeded: silent
1 Like

I am the same. So pleased I only have 2 buttons to sort out, but still… I get that things have to be updated from time to time, but I think the HASS and Z2M teams need to come up with a much better way of creating an update route which is not just “it’s in the change notes” and you only find it after things stop working.

I have re-read all the 2.0 breaking changes notes and the only mention is in a section marked " Only breaking when legacy is enabled :" which is not true. I did not have any legacy settings enabled, but all my action based buttons.

The most frustrating part is I thought I had done everything “right”. I am not using NodeRed, my automation is using a blueprint, I had not customised any part, yet still an update requires me to enable a “legacy” setting to keep things working.

If I don’t enable the legacy option I cannot see any way of keeping the buttons functional. Have I missed something?

3 Likes

Each entity will probably have a couple of hidden entities. One, or both, will be sensor.xxx_illuminance. If you enable that entity your sensor.xxx_illuminance will return.

1 Like

OK so im seeing a big problem here. The event_type attribute only changes once and does not revert back to unknown when the button is depressed. So using triggers to detect events only works if different buttons are being pressed each time, but doesnt trigger if the pressed button is same as the one pressed previously.

Im not sure how can i fix my existing automations which look like (already added attribute to event_type and sensor. to event. domain):

alias: Baby buddy buttons
description: ""
triggers:
  - entity_id:
      - event.baby_nappy_changing_button_action
    attribute: event_type
    id: wee
    to: single
    trigger: state
  - entity_id:
      - event.baby_nappy_changing_button_action
    attribute: event_type
    id: poo
    to: hold
    trigger: state
  - entity_id:
      - event.baby_nappy_changing_button_action
    attribute: event_type
    id: both
    to: double
    trigger: state
  - entity_id:
      - event.baby_bedroom_remote_action
    attribute: event_type
    id: bedroom_timer_start
    to: toggle
    trigger: state
  - entity_id:
      - event.baby_bedroom_remote_action
    attribute: event_type
    to: arrow_left_click
    id: bedroom_formula_feeding
    trigger: state
  - entity_id:
      - event.baby_bedroom_remote_action
    attribute: event_type
    to: brightness_up_click
    id: bedroom_nap
    trigger: state
  - entity_id:
      - event.baby_bedroom_remote_action
    attribute: event_type
    to: brightness_down_click
    id: bedroom_sleep
    trigger: state
  - entity_id:
      - event.baby_feeding_remote_action
    attribute: event_type
    to: toggle
    id: feeding_timer_start
    trigger: state
  - entity_id:
      - event.baby_feeding_remote_action
    attribute: event_type
    to: brightness_up_click
    id: feeding_solids
    trigger: state
  - entity_id:
      - event.baby_feeding_remote_action
    attribute: event_type
    to: brightness_down_click
    id: feeding_formula
    trigger: state
  - entity_id:
      - event.master_bedroom_baby_remote_action
    attribute: event_type
    to: toggle
    id: master_bedroom_timer_start
    trigger: state
  - entity_id:
      - event.master_bedroom_baby_remote_action
    attribute: event_type
    to: brightness_up_click
    id: master_bedroom_nap
    trigger: state
  - entity_id:
      - event.master_bedroom_baby_remote_action
    attribute: event_type
    to: brightness_down_click
    id: master_bedroom_sleep
    trigger: state
  - entity_id:
      - event.master_bedroom_baby_remote_action
    attribute: event_type
    to: arrow_left_click
    id: master_bedroom_formula
    trigger: state
  - entity_id:
      - event.master_bedroom_baby_remote_action
    attribute: event_type
    to: arrow_right_click
    id: master_bedroom_nappy
    trigger: state
conditions: []

This is exactly why I warned earlier and why I edited my original post

Do NOT put any “To” or “Attribute” in the trigger section of the automation.

If you do you cannot press the same button multiple times because the trigger then only fires when the event changes. You need it to trigger even when same value is sent

1 Like

Repeated to answer same problem again. This is exactly why I warned earlier and why I edited my original post

Do NOT put any “To” or “Attribute” in the trigger section of the automation.

If you do you cannot press the same button multiple times because the trigger then only fires when the event changes. You need it to trigger even when same value is sent.

FYI you can omit to: null, the attribute and state update at the exact same time.

FYI2 you can shorthand null with to: ~ in yaml.

2 Likes

The problem is solved! See the p.s. in my post.
Thanks for your input and starting this thread!

Thanks for the confirmation. I updated my original posting to not include the To: null. It confuses more than it helps

2 Likes

I appreciate this workaround, but it feels like a serious usability/feature regression, as i cannot use trigger ids anymore with the new event system? <

That’s not only going to force me to rewrite my automations, but also make the new ones much less clear and easy to read.

The only way to get it to work without changing anything in node red is to enable the legacy options. From what I’ve read the proper way to get it work without turning on legacy options for node red is to use the “mqtt in” node and use switches as per this thread: Use MQTT device trigger · zachowj/node-red-contrib-home-assistant-websocket · Discussion #1725 · GitHub

I tried it just to test it out (for the future if the legacy option gets deprecated) and it works. I have too many automations in node red to change at the moment!

That’s not true? The trigger essentially stays the same but changing the entity_id from sensor.abc to event.abc, but now conditions are:

condition: state
entity_id: event.abc
state: single # or whatever action
attribute: event_type

The only drawback now is that you can’t specify the event in the trigger.

@jchh @P6Dave @KennethLavrsen @reste_narquois

Many thanks for your replies, I now know what to do, just need time to implement.

If i cannot specify (in practice) event_type in the trigger, then i cannot really use trigger_id… theoretically i could but its pointless as it now longer identifies what exactly triggered the automation

yes but what’s the problem with using a condition? The trace still holds the trigger information too.