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.14k stars 29.81k forks source link

Matter - Pressed Twice (Three, Four) doesn't clear #124236

Open LarryWMSN opened 3 weeks ago

LarryWMSN commented 3 weeks ago

The problem

When using the new Pressed Twice (three, four or five times) for an automation, the state of the button doesn't clear. This is an issue if a Press Twice event turns on lights in another room and then it is turned off from a different event. The primary event will stay in the Twice Pressed status, so it won't trigger as expected the next time. This can be worked around by doing a single, triple... press to change the status, but that's not optimal as those events can have automations tied to them.

What version of Home Assistant Core has the issue?

core-2024.8.2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

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

No response

home-assistant[bot] commented 3 weeks 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. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


matter documentation matter source (message by IssueLinks)

LarryWMSN commented 3 weeks ago

This is not a repeat of issue https://github.com/home-assistant/core/issues/123347

The problem that caused that issue was not identified completely and therefore closed. The yaml solution fails under many scenarios since the event_state doesn't reset. This prevents an action from getting triggered again until a different event_state is triggered. The same trigger may need to happen two times in a row, separated by some time (could be days or more), if another action caused changes to any of the same objects as the initial automation.

marcelveldt commented 3 weeks ago

Yes, this is by design for the event entity - the event_type attribute just contains the last fired event type. The only thing that changes every time is the state to the timestamp of the last action.

marcelveldt commented 3 weeks ago

To create automations for event entities you never filter for event_type but just for state and then you check the event type with an additional if or choose statement

LarryWMSN commented 3 weeks ago

The main issue is that a multi press is an event in reality, but it is treated as a state by HA (tied to the trigger on a generic button event), therefore actions that you would want to automate are made more complex.

Imagine a motion detector that stayed in the motion state once activated, lack of motion isn't an event so it would never clear if it were handled the same way as multi-press is in HA. The firmware creates the idle event as a timeout of the motion state once motion is no longer detected. Since the matter switches do not maintain multi-press in their firmware, HA is taking on that role.

The issue becomes that you cannot create a single automation that handles all the buttons on Matter switch; you would need to create a separate automation for up and down or any other button that may be included to do this intuitively. A trigger Id can be used to accomplish this in a single automation, but this seems overly complex for most non-advanced users.

So, I guess this issue should be changed to a feature request to add a state timeout back to "Unknown" to the matter button entities. Or, even better, to have multi-press events be first class attribute citizens on the button with no dependency on state. If you accept the timeout feature, a default option for "forever" would keep the current behavior, but I suspect most users would want it to be a few seconds at most. We could close this issue if required and I can open up a feature request if that's the proper etiquette.

jvmahon commented 3 weeks ago

@LarryWMSN I did a write-up on how to properly set up triggers for the event entity, with emphasis on the Inovelli VTM31. This may help: https://github.com/jvmahon/HomeAssistant-Tools/wiki/Matter-Devices-%E2%80%90-Setting-Up-A-Basic-Automation-Using-Button-Taps

If you're using the Inovelli device, this Blueprint is also very helpful: https://gist.github.com/sethvargo/ed6f1cc1ce9e974f484ec34af00f6776

LarryWMSN commented 3 weeks ago

I am using a VTM31 too and the blueprint is exactly the same as what I built as an automation using your guide as a starting point. But my contention is still that this isn't very discoverable for an average user to find and, building an automation from scratch requires understanding more logic and flow skills than most users will have. These multi-press events are individual events that should trigger and then cease to exist, using state may make it easier to create the integration but I don't believe this delivers a good or consistent user experience. I do want to thank @jvmahon and @marcelveldt (and Seth Vargo) for all the work you're putting in.

home-assistant[bot] commented 1 week ago

core documentation core source

marcelveldt commented 1 week ago

This is not a Matter integration issue but a fundamental issue in the event entity itself: when the same event type gets fired multiple times in a row, it doesn't trigger a state update and thus rendering all automations based on the explicit event type unusable.

The only workaround for this is to not listen to the event_type attribute but listen to the state change and then filter the event type in your actions (or conditions). That is, at least until this issue gets fixed at core level.