diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index 6e1614661..5a15e077f 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -556,6 +556,14 @@ int http_fn_index(http_request_t* request) { hprintf255(request, "Voltage %.2fV (ch %s)", fValue, CHANNEL_GetLabel(i)); poststr(request, ""); } + else if (channelType == ChType_Voltage_div100) { + iValue = CHANNEL_Get(i); + fValue = iValue * 0.01f; + + poststr(request, ""); + hprintf255(request, "Voltage %.3fV (ch %s)", fValue, CHANNEL_GetLabel(i)); + poststr(request, ""); + } else if (channelType == ChType_ReactivePower) { iValue = CHANNEL_Get(i); @@ -1874,6 +1882,15 @@ void doHomeAssistantDiscovery(const char* topic, http_request_t* request) { discoveryQueued = true; } break; + case ChType_Voltage_div100: + { + dev_info = hass_init_sensor_device_info(VOLTAGE_SENSOR, i, 3, 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_ReadOnlyLowMidHigh: { dev_info = hass_init_sensor_device_info(READONLYLOWMIDHIGH_SENSOR, i, -1, -1); diff --git a/src/new_pins.c b/src/new_pins.c index 142350754..da6fc05ec 100644 --- a/src/new_pins.c +++ b/src/new_pins.c @@ -1056,6 +1056,7 @@ float CHANNEL_GetFinalValue(int channel) { case ChType_Frequency_div100: case ChType_Current_div100: case ChType_EnergyTotal_kWh_div100: + case ChType_Voltage_div100: dVal = (float)iVal / 100; break; case ChType_PowerFactor_div1000: @@ -1870,7 +1871,7 @@ const char* g_channelTypeNames[] = { "Illuminance", "Toggle_Inv", "OffOnRemember", - "error", + "Voltage_div100", "error", "error", "error", diff --git a/src/new_pins.h b/src/new_pins.h index 9ff32f67f..98cfdf62e 100644 --- a/src/new_pins.h +++ b/src/new_pins.h @@ -852,6 +852,13 @@ typedef enum channelType_e { //chandetail:"file":"new_pins.h", //chandetail:"driver":""} ChType_OffOnRemember, + //chandetail:{"name":"Voltage_div100", + //chandetail:"title":"TODO", + //chandetail:"descr":"For TuyaMCU power metering. Not used for BL09** and CSE** sensors. Divider is used by TuyaMCU, because TuyaMCU sends always values as integers so we have to divide them before displaying on UI", + //chandetail:"enum":"ChType_Voltage_div100", + //chandetail:"file":"new_pins.h", + //chandetail:"driver":""} + ChType_Voltage_div100, //chandetail:{"name":"Max", //chandetail:"title":"TODO", //chandetail:"descr":"This is the current total number of available channel types.",