mqtt discovery: Set icon for soil moisture sensor

master
Dustin 2022-05-16 21:42:41 -05:00
parent 1ea3de712e
commit c933b4cdcd
1 changed files with 7 additions and 1 deletions

View File

@ -13,6 +13,7 @@ struct sensor_config {
const char* unit; const char* unit;
const char* state_class; const char* state_class;
const char* entity_category; const char* entity_category;
const char* icon;
}; };
static bool publish_config(PubSubClient* mqtt, const char* topic, static bool publish_config(PubSubClient* mqtt, const char* topic,
@ -34,6 +35,9 @@ static bool publish_config(PubSubClient* mqtt, const char* topic,
if (config->entity_category != NULL) { if (config->entity_category != NULL) {
doc["entity_category"] = config->entity_category; doc["entity_category"] = config->entity_category;
} }
if (config->icon != NULL) {
doc["icon"] = config->icon;
}
auto device = doc.createNestedObject("device"); auto device = doc.createNestedObject("device");
device["manufacturer"] = DEVICE_MANUFACTURER; device["manufacturer"] = DEVICE_MANUFACTURER;
device["name"] = DEVICE_NAME; device["name"] = DEVICE_NAME;
@ -61,7 +65,9 @@ bool publish_all_config(PubSubClient* mqtt, const char* ident) {
.device_class = NULL, .device_class = NULL,
.unit = NULL, .unit = NULL,
.state_class = "measurement", .state_class = "measurement",
.entity_category = NULL}; .entity_category = NULL,
.icon = "mdi:water",
};
publish_config(mqtt, TOPIC_CFG_MOISTURE, &moisture); publish_config(mqtt, TOPIC_CFG_MOISTURE, &moisture);
struct sensor_config temperature = { struct sensor_config temperature = {
.name = "Garden Sensor Temperature", .name = "Garden Sensor Temperature",