@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:
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 all sensor.*_click entities are removed. Use the MQTT device trigger instead.
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?
… 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.
@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 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?
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
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).
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
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