Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fan slider attribute update fails (CON-1496) #1228

Closed
We-Inkling opened this issue Jan 4, 2025 · 2 comments
Closed

Fan slider attribute update fails (CON-1496) #1228

We-Inkling opened this issue Jan 4, 2025 · 2 comments

Comments

@We-Inkling
Copy link

We-Inkling commented Jan 4, 2025

void update_matter_device_task(void *param)
{
matter_device_t device;

while (1) {
    // Wait for data to be available in the queue
    if (xQueueReceive(matterQueue, &device, pdMS_TO_TICKS(500))) {

        if (device.load != "Fan" && device.load != "Dimmer") {
            esp_matter_attr_val_t val = esp_matter_invalid(NULL);
            uint32_t attribute_id = OnOff::Attributes::OnOff::Id; 
            uint32_t cluster_id = OnOff::Id;
            attribute_t *attribute = attribute::get(device.id, cluster_id, attribute_id);
            attribute::get_val(attribute, &val);
            val.val.b = device.command;
            attribute::update(device.id, cluster_id, attribute_id, &val); 
        }
        else
        {
            if (device.load == "Fan") {

                mode_flag = true;
                percent_flag = true;
                
                printf("Fan Command: %d\n", device.command);
                
                uint32_t fan_cluster_id = FanControl::Id;
                uint32_t attribute_id_mode = FanControl::Attributes::FanMode::Id;

                esp_matter_attr_val_t val_m = esp_matter_invalid(NULL);
                attribute_t *attribute_mode = attribute::get(device.id, fan_cluster_id, attribute_id_mode);
                attribute::get_val(attribute_mode, &val_m);
                if ( device.command > LOW_MODE_PERCENT_MIN && device.command <= LOW_MODE_PERCENT_MAX) val_m.val.u8 = chip::to_underlying(FanModeEnum::kLow);
                else if ( device.command > MED_MODE_PERCENT_MIN && device.command <= MED_MODE_PERCENT_MAX) val_m.val.u8 = chip::to_underlying(FanModeEnum::kMedium);
                else if ( device.command > HIGH_MODE_PERCENT_MIN) val_m.val.u8 = chip::to_underlying(FanModeEnum::kHigh);
                else if (device.command == 0) val_m.val.u8 = chip::to_underlying(FanModeEnum::kOff);
                attribute::update(device.id, fan_cluster_id, attribute_id_mode, &val_m);

                
                uint32_t attribute_id_percent = FanControl::Attributes::PercentSetting::Id; 
                attribute_t *attribute_percent = attribute::get(device.id, fan_cluster_id, attribute_id_percent);
                esp_matter_attr_val_t val_p = esp_matter_invalid(NULL);
                attribute::get_val(attribute_percent, &val_p);
                //printf("Device ID: %d, Cluster ID: %ld, Attribute ID: %ld\n", device.id, fan_cluster_id, attribute_id_mode);
                val_p.val.u8 = device.command;
                attribute::update(device.id, fan_cluster_id, attribute_id_percent, &val_p); 
                
                //printf("Device ID: %d, Cluster ID: %ld, Attribute ID: %ld\n", device.id, fan_cluster_id, attribute_id_percent);
                
                
            
            }
            else if (device.load == "Dimmer") {
                esp_matter_attr_val_t val = esp_matter_invalid(NULL);
                uint32_t attribute_id = LevelControl::Attributes::CurrentLevel::Id; 
                uint32_t cluster_id = LevelControl::Id;
                attribute_t *attribute = attribute::get(device.id, cluster_id, attribute_id);
                attribute::get_val(attribute, &val);
                val.val.u8 = device.command;
                attribute::update(device.id,cluster_id,attribute_id, &val); 
                dimmer_flag = true;
            }

        }
    }
}

}

above is the code i run as a task to update the attributes of my various device types mainly light ,dimmers and fan when the respective touch are operated .
The seems to work fine for the dimmer and Light whereus in case of fan slider/percent/mode update sometimes it fails and sometime it works

Please suggest a solution for this or alternate method to update the attributes fo the fan

@github-actions github-actions bot changed the title Fan slider attribute update fails Fan slider attribute update fails (CON-1496) Jan 4, 2025
@jadhavrohit924
Copy link
Contributor

@We-Inkling, are there any logs of when you failed to update an attribute? Logs will be beneficial in solving your issue.

@We-Inkling
Copy link
Author

Thank you for your response. I was able to identify and resolve the issue. The problem arose because the update was being executed as a FreeRTOS task, which caused it to proceed without waiting for the previous update to complete. Changing the implementation to a function call resolved the issue effectively.

Closing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants