diff --git a/src/httpserver/hass.c b/src/httpserver/hass.c index 05ff770cc..7bf91835f 100644 --- a/src/httpserver/hass.c +++ b/src/httpserver/hass.c @@ -67,6 +67,9 @@ void hass_populate_unique_id(ENTITY_TYPE type, int index, char* uniq_id) { case CO2_SENSOR: sprintf(uniq_id, "%s_%s_%d", longDeviceName, "co2", index); break; + case ILLUMINANCE_SENSOR: + sprintf(uniq_id, "%s_%s_%d", longDeviceName, "illuminance", index); + break; case SMOKE_SENSOR: sprintf(uniq_id, "%s_%s_%d", longDeviceName, "smoke", index); break; @@ -235,6 +238,9 @@ HassDeviceInfo* hass_init_device_info(ENTITY_TYPE type, int index, char* payload case VOLTAGE_SENSOR: sprintf(g_hassBuffer, "%s Voltage", CFG_GetShortDeviceName()); break; + case ILLUMINANCE_SENSOR: + sprintf(g_hassBuffer, "%s Illuminance", CFG_GetShortDeviceName()); + break; default: sprintf(g_hassBuffer, "%s %s", CFG_GetShortDeviceName(), CHANNEL_GetLabel(index)); break; @@ -499,6 +505,12 @@ HassDeviceInfo* hass_init_sensor_device_info(ENTITY_TYPE type, int channel, int sprintf(g_hassBuffer, "~/%d/get", channel); cJSON_AddStringToObject(info->root, "stat_t", g_hassBuffer); break; + case ILLUMINANCE_SENSOR: + cJSON_AddStringToObject(info->root, "dev_cla", "illuminance"); + cJSON_AddStringToObject(info->root, "unit_of_meas", "lx"); + sprintf(g_hassBuffer, "~/%d/get", channel); + cJSON_AddStringToObject(info->root, "stat_t", g_hassBuffer); + break; case BATTERY_SENSOR: cJSON_AddStringToObject(info->root, "dev_cla", "battery"); cJSON_AddStringToObject(info->root, "unit_of_meas", "%"); diff --git a/src/httpserver/hass.h b/src/httpserver/hass.h index f6fc1a345..5c5e0c953 100644 --- a/src/httpserver/hass.h +++ b/src/httpserver/hass.h @@ -61,6 +61,8 @@ typedef enum { SMOKE_SENSOR, /// @brief READONLYLOWMIDHIGH_SENSOR, + // lx unit + ILLUMINANCE_SENSOR, } ENTITY_TYPE; //unique_id is defined in hass_populate_unique_id and is based on CFG_GetDeviceName() whose size is CGF_DEVICE_NAME_SIZE. diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index 15b040b6b..58c6a45fb 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -480,6 +480,13 @@ int http_fn_index(http_request_t* request) { poststr(request, ""); } + else if (channelType == ChType_Illuminance) { + iValue = CHANNEL_Get(i); + + poststr(request, ""); + hprintf255(request, "Illuminance (%s) = %i Lux", CHANNEL_GetLabel(i), iValue); + poststr(request, ""); + } else if (channelType == ChType_ReadOnly) { iValue = CHANNEL_Get(i); @@ -1866,6 +1873,15 @@ void doHomeAssistantDiscovery(const char* topic, http_request_t* request) { discoveryQueued = true; } break; + case ChType_Illuminance: + { + dev_info = hass_init_sensor_device_info(ILLUMINANCE_SENSOR, i, -1, -1); + MQTT_QueuePublish(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN); + hass_free_device_info(dev_info); + + discoveryQueued = true; + } + break; case ChType_ReadOnly: { dev_info = hass_init_sensor_device_info(CUSTOM_SENSOR, i, -1, -1); diff --git a/src/new_pins.c b/src/new_pins.c index e0d3c029f..251419243 100644 --- a/src/new_pins.c +++ b/src/new_pins.c @@ -1815,7 +1815,7 @@ const char* g_channelTypeNames[] = { "Power_div10", "ReadOnlyLowMidHigh", "SmokePercent", - "error", + "Illuminance", "error", "error", "error", diff --git a/src/new_pins.h b/src/new_pins.h index 5df25407a..ef2fb4990 100644 --- a/src/new_pins.h +++ b/src/new_pins.h @@ -818,6 +818,13 @@ typedef enum channelType_e { //chandetail:"file":"new_pins.h", //chandetail:"driver":""} ChType_SmokePercent, + //chandetail:{"name":"Illuminance", + //chandetail:"title":"TODO", + //chandetail:"descr":"Illuminance in Lux", + //chandetail:"enum":"ChType_Illuminance", + //chandetail:"file":"new_pins.h", + //chandetail:"driver":""} + ChType_Illuminance, //chandetail:{"name":"Max", //chandetail:"title":"TODO",