Skip to content

Matter Switch driver generates artificial button presses when switching back to the driver #2672

@mocelet

Description

@mocelet

After switching back from my custom driver to the stock Matter Switch driver, an automation executed on its own when it should not.

The issue was discussed some time ago in the SmartThings Community so it's probably already known:
https://community.smartthings.com/t/when-switching-from-another-driver-matter-buttons-may-generate-non-real-presses/305587

Matter Switch driver has this line in the initial configuration code that, essentially, generates button presses without user interaction:

device:emit_event_for_endpoint(ep, capabilities.button.button.pushed({state_change = false}))

That's not a problem when a device is new and the user has not created any routine yet since nothing will happen. However, if the user came from another driver and already had automations in place (or, I believe, when using the Hub Replace feature), they will run if the last pressed event was different than the pushed the driver artificially emits.

Mind state_change = false will not prevent that since it just means it will not generate a state change if the previous state was the same.

Other non-Matter button drivers use a function like this to skip the event if the capability was already initialized:

switch_utils.emit_event_if_latest_state_missing = function(device, component, capability, attribute_name, value)
if device:get_latest_state(component, capability.ID, attribute_name) == nil then
device:emit_event(value)
end
end

Another option is to just delete those false presses since they're probably not needed now and as soon as the user presses a button it's going to have a state anyway.

Edit: In fact, in the previous example there's a bug since emit_event emits all the events to main instead of the component requested and should be emit_component_event(component, value). Kind or proves those events are not really needed, if any only for the main component, not for all the others.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions