add flag to use kWh instead of Wh for energy

This commit is contained in:
openshwprojects
2023-05-05 09:49:45 +02:00
parent 21c6a0dd7e
commit c783f39380
4 changed files with 33 additions and 13 deletions

View File

@@ -385,7 +385,12 @@ HassDeviceInfo* hass_init_power_sensor_device_info(int index) {
const char* device_class_value = counter_devClasses[index - OBK_CONSUMPTION_TOTAL];
if (strlen(device_class_value) > 0) {
cJSON_AddStringToObject(info->root, "dev_cla", device_class_value); //device_class=energy
cJSON_AddStringToObject(info->root, "unit_of_meas", "Wh"); //unit_of_measurement
if (CFG_HasFlag(OBK_FLAG_MQTT_ENERGY_IN_KWH)) {
cJSON_AddStringToObject(info->root, "unit_of_meas", "kWh"); //unit_of_measurement
}
else {
cJSON_AddStringToObject(info->root, "unit_of_meas", "Wh"); //unit_of_measurement
}
//state_class can be measurement, total or total_increasing. Energy values should be total_increasing.
cJSON_AddStringToObject(info->root, "stat_cla", "total_increasing");

View File

@@ -2435,7 +2435,7 @@ const char* g_obk_flagNames[] = {
"[WiFi] Quick connect to WiFi on reboot (TODO: check if it works for you and report on github)",
"[Power] Set power and current to zero if all relays are open",
"[MQTT] [Debug] Publish all channels (don't enable it, it will be publish all 64 possible channels on connect)",
"error",
"[MQTT] Use kWh unit for energy consumption (total, last hour, today) instead of Wh",
"error",
"error",
"error",