diff --git a/ChangeLog.md b/ChangeLog.md index cd3deb8d..b6da05eb 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -7,6 +7,7 @@ ## Features * add support for setting visual ping, IP gateway, MAC from ID, and variant to ebuspicloader +* add step variable for numeric values to message definition in MQTT integration # 22.4 (2022-09-18) diff --git a/contrib/etc/ebusd/mqtt-hassio.cfg b/contrib/etc/ebusd/mqtt-hassio.cfg index d3d4d616..4b426509 100644 --- a/contrib/etc/ebusd/mqtt-hassio.cfg +++ b/contrib/etc/ebusd/mqtt-hassio.cfg @@ -56,7 +56,7 @@ # %basetype the base data type ID (e.g. "UCH"). # %comment the field comment (if any). # %unit the field unit (if any). -# %min and %max the minimum/maximum possible value for number fields. +# %min, %max, and %step the minimum/maximum possible value and step value for number fields. # %topic the field (or message) update topic built from the mqtttopic configuration option and/or the %topic variable # defined here. @@ -239,7 +239,8 @@ type_part-by = %type_topic type_part-number = , "command_topic":"%topic/set", "min":%min, - "max":%max%unit_of_measurement%state_class%type_class_number + "max":%max, + "step":%step%unit_of_measurement%state_class%type_class_number # HA integration: %type_part variable for sensor %type_topic type_part-sensor = %unit_of_measurement%state_class%type_class_sensor diff --git a/contrib/etc/ebusd/mqtt-integration.cfg b/contrib/etc/ebusd/mqtt-integration.cfg index 82f8ce49..f7e486e6 100644 --- a/contrib/etc/ebusd/mqtt-integration.cfg +++ b/contrib/etc/ebusd/mqtt-integration.cfg @@ -50,7 +50,7 @@ # %basetype the base data type ID (e.g. "UCH"). # %comment the field comment (if any). # %unit the field unit (if any). -# %min and %max the minimum/maximum possible value for number fields. +# %min, %max, and %step the minimum/maximum possible value and step value for number fields. # %topic the field (or message) update topic built from the mqtttopic configuration option and/or the %topic variable # defined here. diff --git a/src/ebusd/mqtthandler.cpp b/src/ebusd/mqtthandler.cpp index a67086ab..4f1ae37b 100755 --- a/src/ebusd/mqtthandler.cpp +++ b/src/ebusd/mqtthandler.cpp @@ -1085,7 +1085,20 @@ void MqttHandler::run() { } if (dt->getMinMax(true, g_publishFormat, &ostr) == RESULT_OK) { values.set("max", ostr.str()); + ostr.str(""); } + if (dt->readFromRawValue(1, g_publishFormat, &ostr) != RESULT_OK) { + // fallback method, when smallest number didn't work + int divisor = dt->getDivisor(); + float step = 1.0f; + if (divisor > 1) { + step /= static_cast(divisor); + } else if (divisor < 0) { + step *= static_cast(-divisor); + } + ostr << static_cast(step); + } + values.set("step", ostr.str()); } if (!m_typeSwitches.empty()) { values.reduce(true);