BatteryLevelPercent for HA

This commit is contained in:
Tester23
2025-01-05 14:39:19 +01:00
parent 489e8a1a33
commit 3a1c3e9bbf
3 changed files with 14 additions and 1 deletions

View File

@ -608,6 +608,12 @@ HassDeviceInfo* hass_init_sensor_device_info(ENTITY_TYPE type, int channel, int
cJSON_AddStringToObject(info->root, "unit_of_meas", "%");
cJSON_AddStringToObject(info->root, "stat_t", "~/battery/get");
break;
case BATTERY_CHANNEL_SENSOR:
cJSON_AddStringToObject(info->root, "dev_cla", "battery");
cJSON_AddStringToObject(info->root, "unit_of_meas", "%");
sprintf(g_hassBuffer, "~/%d/get", channel);
cJSON_AddStringToObject(info->root, "stat_t", g_hassBuffer);
break;
case BATTERY_VOLTAGE_SENSOR:
cJSON_AddStringToObject(info->root, "dev_cla", "voltage");
cJSON_AddStringToObject(info->root, "unit_of_meas", "mV");

View File

@ -37,7 +37,7 @@ typedef enum {
/// @brief Humidity sensor
HUMIDITY_SENSOR,
/// @brief Battery level sensor in perc
/// @brief Battery level sensor in perc, under battery topic
BATTERY_SENSOR,
/// @brief Battery votage sensor in mV
BATTERY_VOLTAGE_SENSOR,
@ -89,6 +89,8 @@ typedef enum {
WATER_QUALITY_ORP,
// TDS
WATER_QUALITY_TDS,
/// @brief Battery level sensor in perc, under channel topic
BATTERY_CHANNEL_SENSOR,
} ENTITY_TYPE;

View File

@ -1967,6 +1967,11 @@ void doHomeAssistantDiscovery(const char* topic, http_request_t* request) {
{
dev_info = hass_init_sensor_device_info(READONLYLOWMIDHIGH_SENSOR, i, -1, -1, 1);
}
break;
case ChType_BatteryLevelPercent:
{
dev_info = hass_init_sensor_device_info(BATTERY_CHANNEL_SENSOR, i, -1, -1, 1);
}
break;
case ChType_SmokePercent:
{