mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-02-11 05:55:41 +00:00
HA discovery energy_sensor from tuyaMCU (#864)
Handle EnergyTotal_kWh_div1000
This commit is contained in:
committed by
GitHub
parent
12cb936ecf
commit
23cbd2c7f1
@ -539,6 +539,13 @@ 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 ENERGY_SENSOR:
|
||||
cJSON_AddStringToObject(info->root, "dev_cla", "energy");
|
||||
cJSON_AddStringToObject(info->root, "unit_of_meas", "kWh");
|
||||
sprintf(g_hassBuffer, "~/%d/get", channel);
|
||||
cJSON_AddStringToObject(info->root, "stat_cla", "total_increasing");
|
||||
cJSON_AddStringToObject(info->root, "stat_t", g_hassBuffer);
|
||||
break;
|
||||
case POWERFACTOR_SENSOR:
|
||||
cJSON_AddStringToObject(info->root, "dev_cla", "power_factor");
|
||||
//cJSON_AddStringToObject(info->root, "unit_of_meas", "W");
|
||||
|
||||
@ -63,6 +63,8 @@ typedef enum {
|
||||
READONLYLOWMIDHIGH_SENSOR,
|
||||
// lx unit
|
||||
ILLUMINANCE_SENSOR,
|
||||
|
||||
ENERGY_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.
|
||||
|
||||
@ -1981,6 +1981,24 @@ void doHomeAssistantDiscovery(const char* topic, http_request_t* request) {
|
||||
discoveryQueued = true;
|
||||
}
|
||||
break;
|
||||
case ChType_EnergyTotal_kWh_div100:
|
||||
{
|
||||
dev_info = hass_init_sensor_device_info(ENERGY_SENSOR, i, 3, 2);
|
||||
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_EnergyTotal_kWh_div1000:
|
||||
{
|
||||
dev_info = hass_init_sensor_device_info(ENERGY_SENSOR, i, 3, 3);
|
||||
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;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user