I'm trying to adapt the Rainmaker matter_light example to be used for a color temperature light but I'm having some issues with how the firmware interacts with the Rainmaker app.
In its base form, if I commision the example using the ESP Rainmaker app I can see that the hue and saturation controls are exposed, and if I commission it using my iPhone and Apple Homepod, I can see the color picker.
To change the example to a color temperature light, I edit app_matter_light_create() in app_matter_light.cpp and change the creation of the extended_color_light to a color_temperature_light. I also remove the creation of the hue_saturation control clusters since I assume that creating the color_temperature_light takes care of that for me. This is what my app_matter_light_create() looks like:
- esp_err_t app_matter_light_create(app_driver_handle_t driver_handle)
- {
- node_t *node = node::get();
- if (!node) {
- ESP_LOGE(TAG, "Matter node not found");
- return ESP_FAIL;
- }
- color_temperature_light::config_t light_config;
- light_config.on_off.on_off = DEFAULT_POWER;
- light_config.on_off.lighting.start_up_on_off = nullptr;
- light_config.level_control.current_level = DEFAULT_BRIGHTNESS;
- light_config.level_control.lighting.start_up_current_level = DEFAULT_BRIGHTNESS;
- light_config.color_control.color_mode = static_cast<uint8_t>(ColorControl::ColorMode::kColorTemperature);
- light_config.color_control.enhanced_color_mode =
- static_cast<uint8_t>(ColorControlServer::EnhancedColorMode::kColorTemperature);
- light_config.color_control.color_temperature.color_temperature_mireds = REMAP_TO_RANGE_INVERSE(COLOR_TEMP_STARTUP, MATTER_TEMPERATURE_FACTOR);
- light_config.color_control.color_temperature.color_temp_physical_min_mireds = REMAP_TO_RANGE_INVERSE(COLOR_TEMP_MAX, MATTER_TEMPERATURE_FACTOR);
- light_config.color_control.color_temperature.color_temp_physical_max_mireds = REMAP_TO_RANGE_INVERSE(COLOR_TEMP_MIN, MATTER_TEMPERATURE_FACTOR);
- light_config.color_control.color_temperature.couple_color_temp_to_level_min_mireds = REMAP_TO_RANGE_INVERSE(COLOR_TEMP_MAX, MATTER_TEMPERATURE_FACTOR);
- light_config.color_control.color_temperature.startup_color_temperature_mireds = REMAP_TO_RANGE_INVERSE(COLOR_TEMP_STARTUP, MATTER_TEMPERATURE_FACTOR);
- endpoint_t *endpoint = color_temperature_light::create(node, &light_config, ENDPOINT_FLAG_NONE, driver_handle);
- /* These node and endpoint handles can be used to create/add other endpoints and clusters. */
- if (!node || !endpoint) {
- ESP_LOGE(TAG, "Matter node creation failed");
- }
- light_endpoint_id = endpoint::get_id(endpoint);
- ESP_LOGI(TAG, "Light created with endpoint_id %d", light_endpoint_id);
- return ESP_OK;
- }
When I commision this new firmware with my iPhone and Apply Homepod, it recognizes it as a color temperature light and only lets me pick CCT on the color picker (not RGB). However, when I add it to Rainmaker, it doesn't expose any color control - only power and brightness. I also tried adding the CCT control cluster as well, but I got the same result. This is what it looked like with the CCT control cluster added.
- esp_err_t app_matter_light_create(app_driver_handle_t driver_handle)
- {
- node_t *node = node::get();
- if (!node) {
- ESP_LOGE(TAG, "Matter node not found");
- return ESP_FAIL;
- }
- color_temperature_light::config_t light_config;
- light_config.on_off.on_off = DEFAULT_POWER;
- light_config.on_off.lighting.start_up_on_off = nullptr;
- light_config.level_control.current_level = DEFAULT_BRIGHTNESS;
- light_config.level_control.lighting.start_up_current_level = DEFAULT_BRIGHTNESS;
- light_config.color_control.color_mode = static_cast<uint8_t>(ColorControl::ColorMode::kColorTemperature);
- light_config.color_control.enhanced_color_mode =
- static_cast<uint8_t>(ColorControlServer::EnhancedColorMode::kColorTemperature);
- light_config.color_control.color_temperature.color_temperature_mireds = REMAP_TO_RANGE_INVERSE(COLOR_TEMP_STARTUP, MATTER_TEMPERATURE_FACTOR);
- light_config.color_control.color_temperature.color_temp_physical_min_mireds = REMAP_TO_RANGE_INVERSE(COLOR_TEMP_MAX, MATTER_TEMPERATURE_FACTOR);
- light_config.color_control.color_temperature.color_temp_physical_max_mireds = REMAP_TO_RANGE_INVERSE(COLOR_TEMP_MIN, MATTER_TEMPERATURE_FACTOR);
- light_config.color_control.color_temperature.couple_color_temp_to_level_min_mireds = REMAP_TO_RANGE_INVERSE(COLOR_TEMP_MAX, MATTER_TEMPERATURE_FACTOR);
- light_config.color_control.color_temperature.startup_color_temperature_mireds = REMAP_TO_RANGE_INVERSE(COLOR_TEMP_STARTUP, MATTER_TEMPERATURE_FACTOR);
- endpoint_t *endpoint = color_temperature_light::create(node, &light_config, ENDPOINT_FLAG_NONE, driver_handle);
- /* These node and endpoint handles can be used to create/add other endpoints and clusters. */
- if (!node || !endpoint) {
- ESP_LOGE(TAG, "Matter node creation failed");
- }
- light_endpoint_id = endpoint::get_id(endpoint);
- ESP_LOGI(TAG, "Light created with endpoint_id %d", light_endpoint_id);
- /* Add additional features to the node */
- cluster_t *cluster = cluster::get(endpoint, ColorControl::Id);
- cluster::color_control::feature::color_temperature::config_t temperature_config;
- temperature_config.color_temp_physical_max_mireds = REMAP_TO_RANGE_INVERSE(COLOR_TEMP_MIN, MATTER_TEMPERATURE_FACTOR);
- temperature_config.color_temp_physical_min_mireds = REMAP_TO_RANGE_INVERSE(COLOR_TEMP_MAX, MATTER_TEMPERATURE_FACTOR);
- temperature_config.couple_color_temp_to_level_min_mireds = REMAP_TO_RANGE_INVERSE(COLOR_TEMP_MAX, MATTER_TEMPERATURE_FACTOR);
- esp_err_t cluster_add_res = cluster::color_control::feature::color_temperature::add(cluster, &temperature_config);
- return ESP_OK;
- }
Any idea if I'm doing something wrong or there's an issue with the Rainmaker app? I'm confused as to why the Apple software is recognizing it as a color temperature control device but Rainmaker won't.