The new version (2.x) has a lot of breaking changes:
@mcarty Thanks for the GitHub discussion link. As per that article, I added the following lines to my Zigbee2MQTT config file and everything seems to be working:
advanced:
homeassistant_legacy_entity_attributes: false
homeassistant_legacy_triggers: false
legacy_api: false
legacy_availability_payload: false
device_options:
legacy: false
Is that all that needs to be done? I just skimmed over the rest of the topic and there’s a lot of info, so I could be missing something.
Actually none of my aqara buttons work. I’m thinking this line in that article is talking about that issue:
Only breaking when legacy is enabled:
- All click sensors have been removed (
homeassistant.legacy_triggers
setting). This means allsensor.*_click
entities are removed. Use the MQTT device trigger instead.
Am I right?
… yeah, I had to go edit the triggers in all my automations with the aqara buttons. Changed them to MQTT device triggers.
For future reference, you can also use a State Trigger with the device’s event
entities.
Main advantage is that if the device is ever replaced, as long as the new one’s name remains the same, you won’t have to modify any automations that reference it.
In contrast, an MQTT Device Trigger uses the device’s device_id
and it will automatically change when the physical device is changed (requiring you to update all of its related automations).
@123 Thanks for the info. I just read over this article. I did not find any event attributes (in Developer Tools → States) for my aqara buttons. Is there something I need to do to activate event entities?
… found the answer in the article. Added the following to Zigbee2MQTT config.yaml:
homeassistant:
experimental_event_entities: true
… as a followup on configuring by event entities, the event_type status stays with the last action. So, for example, if I do a single click, the event_type changes to “single” and stays that way until I make a different action, like a double click, and then it changes to “double” until a different action type. Ideally the event_type state would go back to “null” shortly after the action, so I can toggle things on/off with a single click or double click. I do have a workaround by just adding an automation that sets all the event_type attributes to “null” 1 second after the action (i.e. single, double, or hold).
You could also read the full posting 123 linked to. It says exactly how to handle the new event entities so you can detect multiple clicks on the same button. Do not put any valies in the trigger. Never.
I’ve just had to do the same thing - updated Zigbee2MQTT to 2.0 and everything broke - seems reverting fixed things…
It’s still not entirely clear to me what has broken however, even after reading this thread and others on Reddit
The only things I know are:
- I updated Zigbee2MQTT to v2
- I am using a Sonoff Zigbee Dongle
- I received 502 Bad Gateway when trying to load the Zigbee2MQTT dashboard
- The addon was telling me that it was not started when the addon page showed that it was…
Can anyone advise what actually needs to be done to prevent this break!?
@KennethLavrsen: Thank you for the information. I’m trying to configure the triggers without any values, as you suggested, but it’s not working properly, and I’m wondering if I can get your input.
I did review your post titled “Using the new action events in Zigbee2MQTT 2.0”. Where I’m not understanding things is the lines on how to format the conditions. In your examples, it looks like a template with curly brackets around the “trigger.to_state.attributes…” part. I tried to simulate what you did, but the automation throws an error; the yaml is as follows:
alias: Testing Zigbee2MQTT v2
description: ""
triggers:
- entity_id:
- event.zigbee_smart_button_action
id: Single
trigger: state
not_from: unavailable
enabled: true
conditions: []
actions:
- alias: >-
If Generic Fan Plug is ON --> turn it OFF; else if it is OFF --> turn it
ON
if:
- condition: "{{trigger.to_state.attributes.event_type == 'single'}}"
- condition: state
entity_id: switch.generic_smart_plug
state: "on"
enabled: true
then:
- action: switch.turn_off
metadata: {}
data: {}
target:
entity_id: switch.generic_smart_plug
else:
- if:
- condition: "{{trigger.to_state.attributes.event_type == 'single'}}"
- condition: state
entity_id: switch.generic_smart_plug
state: "off"
enabled: true
then:
- action: switch.turn_on
metadata: {}
data: {}
target:
entity_id: switch.generic_smart_plug
enabled: true
mode: single
So, then I tried changing the conditions to states, as follows, but it only works intermittently:
alias: Testing Zigbee2MQTT v2
description: ""
triggers:
- entity_id:
- event.zigbee_smart_button_action
id: Single
trigger: state
not_from: unavailable
enabled: true
conditions: []
actions:
- alias: >-
If Generic Fan Plug is ON --> turn it OFF; else if it is OFF --> turn it
ON
if:
- condition: or
conditions:
- condition: state
entity_id: event.zigbee_smart_button_action
attribute: event_type
state: single
- condition: state
entity_id: switch.generic_smart_plug
state: "on"
enabled: true
then:
- action: switch.turn_off
metadata: {}
data: {}
target:
entity_id: switch.generic_smart_plug
else:
- if:
- condition: state
entity_id: event.zigbee_smart_button_action
attribute: event_type
state: single
- condition: state
entity_id: switch.generic_smart_plug
state: "off"
enabled: true
then:
- action: switch.turn_on
metadata: {}
data: {}
target:
entity_id: switch.generic_smart_plug
enabled: true
mode: single
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.
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