@@ -848,10 +848,11 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
848
848
849
849
bool set_ha_classes = false ; // set to true if we want to set the state class and device class
850
850
851
- // create the topic, depending on the type and whether the device entity is writable (a command)
851
+ // create the topic
852
+ // depending on the type and whether the device entity is writable (a command)
852
853
// https://developers.home-assistant.io/docs/core/entity
853
854
char topic[MQTT_TOPIC_MAX_SIZE];
854
- // if it's a command then we can use Number, Switch, Select. Otherwise stick to Sensor
855
+ // if it's a command then we can use Number, Switch, Select or Text . Otherwise stick to Sensor
855
856
if (has_cmd) {
856
857
switch (type) {
857
858
case DeviceValueType::INT:
@@ -878,6 +879,10 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
878
879
snprintf (topic, sizeof (topic), " sensor/%s" , config_topic);
879
880
set_ha_classes = true ;
880
881
break ;
882
+ case DeviceValueType::STRING:
883
+ snprintf (topic, sizeof (topic), " text/%s" , config_topic); // e.g. set_datetime, set_holiday, set_wwswitchtime
884
+ set_ha_classes = true ;
885
+ break ;
881
886
default :
882
887
// plain old sensor
883
888
snprintf (topic, sizeof (topic), " sensor/%s" , config_topic);
@@ -911,20 +916,18 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
911
916
912
917
char sample_val[30 ] = " 0" ; // sample, correct(!) entity value, used only to prevent warning/error in HA if real value is not published yet
913
918
914
- // handle commands, which are device entities that are writable
915
- // we add the command topic parameter
916
- // note: there is no way to handle strings in HA so datetimes (e.g. set_datetime, set_holiday, set_wwswitchtime etc) are excluded
919
+ // we add the command topic parameter for commands
917
920
if (has_cmd) {
918
- // command topic back to EMS-ESP
919
921
char command_topic[MQTT_TOPIC_MAX_SIZE];
922
+ // add command topic
920
923
if (tag >= DeviceValueTAG::TAG_HC1) {
921
924
snprintf (command_topic, sizeof (command_topic), " %s/%s/%s/%s" , mqtt_basename_.c_str (), device_name, EMSdevice::tag_to_mqtt (tag), entity);
922
925
} else {
923
926
snprintf (command_topic, sizeof (command_topic), " %s/%s/%s" , mqtt_basename_.c_str (), device_name, entity);
924
927
}
925
928
doc[" cmd_t" ] = command_topic;
926
929
927
- // for enums, add options
930
+ // extend for enums, add options
928
931
if (type == DeviceValueType::ENUM) {
929
932
JsonArray option_list = doc.createNestedArray (" ops" ); // options
930
933
if (EMSESP::system_.enum_format () == ENUM_FORMAT_INDEX) {
@@ -942,7 +945,7 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
942
945
}
943
946
944
947
} else if (type != DeviceValueType::STRING && type != DeviceValueType::BOOL) {
945
- // Must be Numeric....
948
+ // For numeric's add the range
946
949
doc[" mode" ] = " box" ; // auto, slider or box
947
950
if (num_op > 0 ) {
948
951
doc[" step" ] = 1.0 / num_op;
0 commit comments