home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.24k stars 29.86k forks source link

Buttons connected via Matter sends unusable events #103144

Closed einord closed 10 months ago

einord commented 10 months ago

The problem

Buttons that are connected to Home Assistant via matter have during the latest updates gotten worse when sending events, so that they are unusable.

Testing with my Aqara Wireless Mini Switch that is connected to Home Assistant via Matter, and when clicking once on the button results in three state_changed events where all of them are exactly the same and have the new_state.event_type value "initial_press". This makes it impossible to reliably count the number of presses in an automation.

Previously it was possible to get a "multi_press_complete" event_type (which had a "totalNumberOfPressesCounted" value), but these seems to be completely gone now. I can't get it to trigger this event at all.

The only trigger that can be used on the button is the "battery level changes", which is not helpful for any interaction with the button at all.

Am I doing something wrong, is the Matter integration still changing somehow how buttons are implemented, or is this a bug? I can't find any other information about this issue from anyone else when searching.

What version of Home Assistant Core has the issue?

2023.10.5

What was the last working version of Home Assistant Core?

2023.9.x

What type of installation are you running?

Home Assistant Supervised

Integration causing the issue

Matter

Link to integration documentation on our website

https://www.home-assistant.io/integrations/matter/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

An example of what the button event look like, but there's multiple for every press, they all look the same, and there's no longer any way to know how many actual presses there was.

event_type: state_changed data: entity_id: event.alarmknapp old_state: entity_id: event.alarmknapp state: "2023-10-31T19:22:19.828+00:00" attributes: event_types:

home-assistant[bot] commented 10 months ago

Hey there @home-assistant/matter, mind taking a look at this issue as it has been labeled with an integration (matter) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `matter` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign matter` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


matter documentation matter source (message by IssueLinks)

Coder84619 commented 10 months ago

I have a Tuo button, and on HAOS 11.1 and the latest Matter add-on and enabled the beta features. I too fail to see any Device triggers based on button events. I only see triggers based on battery level.

marcelveldt commented 10 months ago

OK, in that case we probably have some regression then if it worked in the previous version. This is crap for me to test as I do not have access to these button/switch devices. I'll take a look in the code if I can spot something obviuous, maybe just a simple attribute name change or something

marcelveldt commented 10 months ago

I have a Tuo button, and on HAOS 11.1 and the latest Matter add-on and enabled the beta features. I too fail to see any Device triggers based on button events. I only see triggers based on battery level.

Be aware that Matter does not have so called "device triggers" defined. You will just have to create a manual automation based on the events. So that list of predefined automations is empty for Matter buttons (except the battery).

You should be able to make multi press automations based on the "totalNumberOfPressesCounted" attribute of the event entity. If that feature is somehow now missing in the latest beta, we have to figure out if that is due to a change in the Aqara bridge implementation or the Matter SDK or our implementation.

Coder84619 commented 10 months ago

I'm very unclear how you even use events in automation triggers. I don't see an 'events' top level object type. Can you pretend I'm 5 years old and walk me though the process?

marcelveldt commented 10 months ago

If you want to act on a specific count, you could add in a condition (or choose sequence) to also check the totalNumberOfPressesCounted attribute for a certain number.

Coder84619 commented 10 months ago

@marcelveldt perfect! Thank you. Now, are the event names for Matter buttons defined in the Matter spec or by the device firmware? For the Tuo button HA lists: event_types: initial_press, short_release, long_press, long_release, multi_press_ongoing, multi_press_complete

marcelveldt commented 10 months ago

The spec defines the possible event names/types while the device specifies which of those it supports. For example the multi_press events do not exist for some remotes

einord commented 10 months ago

@marcelveldt @Coder84619 Exactly what I was able to do previously and listen to the "multi_press" event and the "totalNumberOfPressesCounted".

But now I'm only able to trigger the initial_press (3 times for every press) or the "long_press". I don't have any other matter based button, so I can't tell for sure if it has anything to do with the Matter integration or Aqara. The Aqara hub updates itself automatically, so I can't tell if it has updated itself at the same point the button stopped working properly.

marcelveldt commented 10 months ago

@Coder84619 can you please test it with your Tuo button so we can rule out if its regression in our/sdk code or in the Aqara matter bridge.

@einord did you enable the beta toggle inside the Matter server add-on ? If not, you were still running the same version as weeks ago so I'm pretty sure this is regression in the Aqara bridge. I see these Aqara switches are actually available in my country, I'm going to order one to test this myself.

einord commented 10 months ago

@marcelveldt No, the beta toggle is disabled, so I guess it means that the problem likely is on Aqara's end?

marcelveldt commented 10 months ago

@marcelveldt No, the beta toggle is disabled, so I guess it means that the problem likely is on Aqara's end?

Yes, I'm afraid so... I'va also traced source code and nothing changed in this regard but let's wait for someone with a Tuo button to confirm that still works.

Coder84619 commented 10 months ago

@marcelveldt Tuo button works as expected for single press, double press and three presses. However, I'm baffled as to how I count the presses as a condition (quite a hack if you ask me). Numeric state only has above or below, not an "equals" or "is" condition that I can see. So I can't see how I properly filter on 1, 2 or 3 or more presses.

The whole Matter button support needs to be revamped. It's basically useless in its current form for EASILY acting on 1 or more presses to trigger an action. It's so 'hacky' that I'm not going to bother using it. My Tuo buttons will be ONLY Apple Home until it's intuitive in HA.

marcelveldt commented 10 months ago

@marcelveldt Tuo button works as expected for single press, double press and three presses. However, I'm baffled as to how I count the presses as a condition (quite a hack if you ask me). Numeric state only has above or below, not an "equals" or "is" condition that I can see. So I can't see how I properly filter on 1, 2 or 3 or more presses.

The whole Matter button support needs to be revamped. It's basically useless in its current form for EASILY acting on 1 or more presses to trigger an action. It's so 'hacky' that I'm not going to bother using it. My Tuo buttons will be ONLY Apple Home until it's intuitive in HA.

I agree it is cumbersome and a lot of manual work but our automation engine is not hacky. It is very flexible and thus complicated, especially because we not provide any examples or template configurations for your remote's automations.

You can use the regular "state" comparison to do an exact match for a specified number press. So in condition you specify state again, your device and for the attribute you select the totalNumberOfPressesCounted and as state you can enter the number.

OK, anyways, @einord it is still working in our Matter integration, just the Aqara implementation seems to be broken for multi press. I'll order one of these buttons myself to give it a try. You are 100% certain this used to work ?

@Coder84619 thanks for testing it with the Tuo remote, have a look at our automations documentation how to deal with it. We are going to look for ways to make this more easy with some predefined templates or something because you have a solid point that this is way too complicated now to setup, especially if you're not used to manually creating automations in our automation editor.

Coder84619 commented 10 months ago

@marcelveldt thanks. But until it's '5 year old simple' (like it is in Apple Home) to trigger on one or multiple Matter button presses, I've removed them from HA and won't be using them for the foreseeable future.

marcelveldt commented 10 months ago

I'll forward your feedback to our UX people ;-)

jamesrupertball commented 10 months ago

I, too, am having this issue with an Aqara Wireless Mini Switch integrated via Matter. I have only just added it so I can't comment on it working in prior versions. Using the state trigger, I can trigger an automation using the event type attribute but I can't distinguish between the various events (initial press, long press etc). I have the same issue as @einord explained where you get multiple almost identical state_changed events for each press. Just wanted to add my experience to this issue.

einord commented 10 months ago

@marcelveldt Hi, sorry for slow feedback (I've been sick for a few days). Yes, about a month ago I bought the Aqara M2 Hub, just to easier let my Aqara devices integrate with HA. I have since then had the button to activate/deactivate the house alarm when leaving (not very safe, I know, but more as a test for a while). It worked without problem and we could activate / deactivate the alarm without any issues.

Suddenly we noticed that it had stopped working when double-pressing the button a few days ago and that's when I started listening to the events and notices that the "multi_press_complete" just had stopped triggering entirely.

marcelveldt commented 10 months ago

This issue is originated by the Aqara M2 Hub I'm afraid. Just tested with the firmware 4.0.4_008.0646 and then it works fine again. I'll now update it to the 4.0.6.x update to see if it breaks

marcelveldt commented 10 months ago

And yes, confirmed. Updated the M2 Hub and now the events are broken. I even double checked the raw data and its indeed sending the wrong data. So this is not an issue with HA but with Aqara.

The second issue that is reported in this report (that our UX for automating on button presses) will be looked at, we have a few ideas to make it easier.

einord commented 9 months ago

For anyone else experiencing the same issues, I can tell that this has now been resolved by Aqara and seems to be working as expected again.

I reached out to Aqara support a few weeks ago, gave them examples of the event data I got in Home Assistant. Their technical team took over quickly and today they returned to me telling that they released an update for this, and now it seems to work properly (at least as far as I can see for now) and multi presses work as expected again.

The new M2 Hub version resolving this issue is 4.0.7_0006.0646

@marcelveldt, @jamesrupertball and others interested