Skip to content

Commit

Permalink
generate better (valid?) RGBCW and RGB HA configs for bulbs
Browse files Browse the repository at this point in the history
  • Loading branch information
openshwprojects committed Oct 2, 2022
1 parent e07a199 commit 2284d0e
Showing 1 changed file with 69 additions and 3 deletions.
72 changes: 69 additions & 3 deletions src/httpserver/http_fns.c
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,9 @@ int http_fn_ha_cfg(http_request_t *request) {
int i;
char mqttAdded = 0;
char *uniq_id;
char switchAdded = 0;
char lightAdded = 0;
int bLedDriverChipRunning;

shortDeviceName = CFG_GetShortDeviceName();
clientId = CFG_GetMQTTClientId();
Expand All @@ -1293,8 +1296,9 @@ int http_fn_ha_cfg(http_request_t *request) {

get_Relay_PWM_Count(&relayCount, &pwmCount);

bLedDriverChipRunning = DRV_IsRunning("SM2135") || DRV_IsRunning("BP5758D");

if(relayCount > 0) {
char switchAdded = 0;

for(i = 0; i < CHANNEL_MAX; i++) {
if(h_isChannelRelay(i)) {
Expand Down Expand Up @@ -1323,8 +1327,70 @@ int http_fn_ha_cfg(http_request_t *request) {
}
}
}
if(pwmCount > 0) {
char lightAdded = 0;
if(pwmCount == 5 || bLedDriverChipRunning) {
// Enable + RGB control + CW control
if (mqttAdded == 0){
poststr(request,"mqtt:\n");
mqttAdded=1;
}
if (switchAdded == 0){
poststr(request," light:\n");
switchAdded=1;
}

uniq_id = hass_build_unique_id(ENTITY_LIGHT,i);
hprintf128(request," - unique_id: \"%s\"\n",uniq_id);
os_free(uniq_id);

hprintf128(request," name: \"%s %i\"\n",shortDeviceName,i);


hprintf128(request," rgb_command_template: \"{{ '#%02x%02x%02x0000' | format(red, green, blue)}}\"\n");
hprintf128(request," rgb_state_topic: \"cmnd/%s/led_basecolor_rgb\"\n",clientId);
hprintf128(request," rgb_command_topic: \"cmnd/%s/led_basecolor_rgb\"\n",clientId);
hprintf128(request," command_topic: \"cmnd/%s/led_enableAll\"\n",clientId);
hprintf128(request," availability_topic: \"%s/connected\"\n",clientId);
hprintf128(request," payload_on: 1\n");
hprintf128(request," payload_off: 0\n");
hprintf128(request," brightness_command_topic: \"cmnd/%s/led_dimmer\"\n",clientId);
hprintf128(request," brightness_scale: 100\n");
hprintf128(request," brightness_value_template: \"{{ value_json.Dimmer }}\"\n");
hprintf128(request," color_temp_command_topic: \"cmnd/%s/led_temperature\"\n",clientId);
hprintf128(request," color_temp_state_topic: \"cmnd/%s/ctr\"\n",clientId);
hprintf128(request," color_temp_value_template: \"{{ value_json.CT }}\"\n");
} else
if(pwmCount == 3) {
// Enable + RGB control
if (mqttAdded == 0){
poststr(request,"mqtt:\n");
mqttAdded=1;
}
if (switchAdded == 0){
poststr(request," light:\n");
switchAdded=1;
}

uniq_id = hass_build_unique_id(ENTITY_LIGHT,i);
hprintf128(request," - unique_id: \"%s\"\n",uniq_id);
os_free(uniq_id);

hprintf128(request," name: \"%s %i\"\n",shortDeviceName,i);


hprintf128(request," rgb_command_template: \"{{ '#%02x%02x%02x0000' | format(red, green, blue)}}\"\n");
hprintf128(request," rgb_state_topic: \"cmnd/%s/led_basecolor_rgb\"\n",clientId);
hprintf128(request," rgb_command_topic: \"cmnd/%s/led_basecolor_rgb\"\n",clientId);
hprintf128(request," command_topic: \"cmnd/%s/led_enableAll\"\n",clientId);
hprintf128(request," availability_topic: \"%s/connected\"\n",clientId);
hprintf128(request," payload_on: 1\n");
hprintf128(request," payload_off: 0\n");
hprintf128(request," brightness_command_topic: \"cmnd/%s/led_dimmer\"\n",clientId);
hprintf128(request," brightness_scale: 100\n");
hprintf128(request," brightness_value_template: \"{{ value_json.Dimmer }}\"\n");
//hprintf128(request," color_temp_command_topic: \"cmnd/%s/led_temperature\"\n",clientId);
//hprintf128(request," color_temp_state_topic: \"cmnd/%s/ctr\"\n",clientId);
//hprintf128(request," color_temp_value_template: \"{{ value_json.CT }}\"\n");
} else if(pwmCount > 0) {

for(i = 0; i < CHANNEL_MAX; i++) {
if(h_isChannelPWM(i)) {
Expand Down

0 comments on commit 2284d0e

Please sign in to comment.