Page 1 of 1

Add Matter Dimmer Switch behaviour

Posted: Mon Mar 10, 2025 7:45 am
by tomasmcguinness
I am trying to convert the light_switch example to a Dimmer Switch.

I changed the endpoint creation in app_main.cpp to

Code: Select all

dimmer_switch::config_t switch_config;
endpoint_t *endpoint = dimmer_switch::create(node, &switch_config, ENDPOINT_FLAG_NONE, switch_handle);
in the app_driver.cpp, I added a new function connected to another button. It contents look like this:

Code: Select all

LevelControl::Commands::MoveToLevel::Type moveToLevelCommand;
moveToLevelCommand.level = 55;
moveToLevelCommand.transitionTime.SetNonNull(0);
moveToLevelCommand.optionsMask = static_cast<chip::BitMask<chip::app::Clusters::LevelControl::LevelControlOptions>>(0U);
moveToLevelCommand.optionsOverride = static_cast<chip::BitMask<chip::app::Clusters::LevelControl::LevelControlOptions>>(0U);

client::request_handle_t req_handle;
req_handle.type = esp_matter::client::INVOKE_CMD;
req_handle.command_path.mClusterId = LevelControl::Id;
req_handle.command_path.mCommandId = LevelControl::Commands::MoveToLevel::Id;
req_handle.request_data = &moveToLevelCommand;

lock::chip_stack_lock(portMAX_DELAY);
client::cluster_update(switch_endpoint_id, &req_handle);
lock::chip_stack_unlock();
I have adding bindings to a "Light" (using the light example) and I can successfully turn the light on and off.

However, when it comes to performing the MoveToLevel command I believe I am missing something from the app_driver_client_group_invoke_command_callback callback function.

When I tried the code initially, I got the "Unsupport Cluster" error. I added an if statement for the LevelControl cluster

Code: Select all

else if (req_handle->command_path.mClusterId == LevelControl::Id)
{
    strcpy(command_data_str, "{}");
}
but am unclear what the command_data_str payload should be.

I have found some references online to indicate I shouldn't use JSON at all. This implies that the light_switch example might be out of date.

My first question: Is this the correct approach?

My second question: What should the JSON payload be i.e. is it as simple as

Code: Select all

{ "level": 10, "transitionTime": 0, "optionsMask": 0, "optionsOverride": 0 }