Skip to content

Commit

Permalink
added Voltage_div100
Browse files Browse the repository at this point in the history
  • Loading branch information
openshwprojects committed Sep 23, 2023
1 parent 2c32726 commit 735236a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/httpserver/http_fns.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,14 @@ int http_fn_index(http_request_t* request) {
hprintf255(request, "Voltage %.2fV (ch %s)", fValue, CHANNEL_GetLabel(i));
poststr(request, "</td></tr>");
}
else if (channelType == ChType_Voltage_div100) {
iValue = CHANNEL_Get(i);
fValue = iValue * 0.01f;

poststr(request, "<tr><td>");
hprintf255(request, "Voltage %.3fV (ch %s)", fValue, CHANNEL_GetLabel(i));
poststr(request, "</td></tr>");
}
else if (channelType == ChType_ReactivePower) {
iValue = CHANNEL_Get(i);

Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/new_pins.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -1870,7 +1871,7 @@ const char* g_channelTypeNames[] = {
"Illuminance",
"Toggle_Inv",
"OffOnRemember",
"error",
"Voltage_div100",
"error",
"error",
"error",
Expand Down
7 changes: 7 additions & 0 deletions src/new_pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down

0 comments on commit 735236a

Please sign in to comment.