show freemem in KB, add more HA icons

This commit is contained in:
proddy
2021-05-10 14:10:16 +02:00
parent 37bee39cea
commit bc69ca0a9b
5 changed files with 43 additions and 8 deletions

View File

@@ -34,7 +34,9 @@ static const __FlashStringHelper * DeviceValueUOM_s[] __attribute__((__aligned__
F_(minutes), F_(minutes),
F_(ua), F_(ua),
F_(bar), F_(bar),
F_(kw) F_(kw),
F_(kb),
F_(seconds)
}; };

View File

@@ -31,7 +31,6 @@
namespace emsesp { namespace emsesp {
// Home Assistant icons (https://materialdesignicons.com/) // Home Assistant icons (https://materialdesignicons.com/)
// MAKE_PSTR(icontemperature, "mdi:temperature-celsius")
MAKE_PSTR(icontemperature, "mdi:coolant-temperature") MAKE_PSTR(icontemperature, "mdi:coolant-temperature")
MAKE_PSTR(iconpercent, "mdi:percent-outline") MAKE_PSTR(iconpercent, "mdi:percent-outline")
MAKE_PSTR(iconfire, "mdi:fire") MAKE_PSTR(iconfire, "mdi:fire")
@@ -40,6 +39,8 @@ MAKE_PSTR(iconflame, "mdi:flash")
MAKE_PSTR(iconvalve, "mdi:valve") MAKE_PSTR(iconvalve, "mdi:valve")
MAKE_PSTR(iconpump, "mdi:pump") MAKE_PSTR(iconpump, "mdi:pump")
MAKE_PSTR(iconheatpump, "mdi:water-pump") MAKE_PSTR(iconheatpump, "mdi:water-pump")
MAKE_PSTR(iconclock, "mdi:clock-outline")
MAKE_PSTR(iconmemory, "mdi:memory")
enum DeviceValueType : uint8_t { enum DeviceValueType : uint8_t {
BOOL, BOOL,
@@ -57,7 +58,24 @@ enum DeviceValueType : uint8_t {
// Unit Of Measurement mapping - maps to DeviceValueUOM_s in emsdevice.cpp // Unit Of Measurement mapping - maps to DeviceValueUOM_s in emsdevice.cpp
// uom - also used with HA // uom - also used with HA
// sequence is important! // sequence is important!
enum DeviceValueUOM : uint8_t { NONE = 0, DEGREES, PERCENT, LMIN, KWH, WH, HOURS, MINUTES, UA, BAR, KW, PUMP }; enum DeviceValueUOM : uint8_t {
NONE = 0,
DEGREES,
PERCENT,
LMIN,
KWH,
WH,
HOURS,
MINUTES,
UA,
BAR,
KW,
KB,
SECONDS,
PUMP // special, do not remove
};
// TAG mapping - maps to DeviceValueTAG_s in emsdevice.cpp // TAG mapping - maps to DeviceValueTAG_s in emsdevice.cpp
enum DeviceValueTAG : uint8_t { enum DeviceValueTAG : uint8_t {

View File

@@ -165,6 +165,8 @@ MAKE_PSTR(hours, "hours")
MAKE_PSTR(ua, "uA") MAKE_PSTR(ua, "uA")
MAKE_PSTR(lmin, "l/min") MAKE_PSTR(lmin, "l/min")
MAKE_PSTR(kw, "kW") MAKE_PSTR(kw, "kW")
MAKE_PSTR(kb, "KB")
MAKE_PSTR(seconds, "seconds")
// TAG mapping - maps to DeviceValueTAG_s in emsdevice.cpp // TAG mapping - maps to DeviceValueTAG_s in emsdevice.cpp
// use empty string if want to suppress showing tags // use empty string if want to suppress showing tags

View File

@@ -709,10 +709,15 @@ void Mqtt::ha_status() {
// create the sensors // create the sensors
// must match the MQTT payload keys // must match the MQTT payload keys
publish_mqtt_ha_sensor(DeviceValueType::INT, DeviceValueTAG::TAG_HEARTBEAT, F("WiFi strength"), EMSdevice::DeviceType::SYSTEM, F("rssi")); publish_mqtt_ha_sensor(DeviceValueType::INT, DeviceValueTAG::TAG_HEARTBEAT, F("WiFi strength"), EMSdevice::DeviceType::SYSTEM, F("rssi"), DeviceValueUOM::PERCENT);
publish_mqtt_ha_sensor(DeviceValueType::INT, DeviceValueTAG::TAG_HEARTBEAT, F("Uptime"), EMSdevice::DeviceType::SYSTEM, F("uptime")); publish_mqtt_ha_sensor(DeviceValueType::INT, DeviceValueTAG::TAG_HEARTBEAT, F("Uptime"), EMSdevice::DeviceType::SYSTEM, F("uptime"));
publish_mqtt_ha_sensor(DeviceValueType::INT, DeviceValueTAG::TAG_HEARTBEAT, F("Uptime (sec)"), EMSdevice::DeviceType::SYSTEM, F("uptime_sec")); publish_mqtt_ha_sensor(DeviceValueType::INT,
publish_mqtt_ha_sensor(DeviceValueType::INT, DeviceValueTAG::TAG_HEARTBEAT, F("Free memory"), EMSdevice::DeviceType::SYSTEM, F("freemem")); DeviceValueTAG::TAG_HEARTBEAT,
F("Uptime (sec)"),
EMSdevice::DeviceType::SYSTEM,
F("uptime_sec"),
DeviceValueUOM::SECONDS);
publish_mqtt_ha_sensor(DeviceValueType::INT, DeviceValueTAG::TAG_HEARTBEAT, F("Free memory"), EMSdevice::DeviceType::SYSTEM, F("freemem"), DeviceValueUOM::KB);
publish_mqtt_ha_sensor(DeviceValueType::INT, DeviceValueTAG::TAG_HEARTBEAT, F("# MQTT fails"), EMSdevice::DeviceType::SYSTEM, F("mqttfails")); publish_mqtt_ha_sensor(DeviceValueType::INT, DeviceValueTAG::TAG_HEARTBEAT, F("# MQTT fails"), EMSdevice::DeviceType::SYSTEM, F("mqttfails"));
publish_mqtt_ha_sensor(DeviceValueType::INT, DeviceValueTAG::TAG_HEARTBEAT, F("# Rx received"), EMSdevice::DeviceType::SYSTEM, F("rxreceived")); publish_mqtt_ha_sensor(DeviceValueType::INT, DeviceValueTAG::TAG_HEARTBEAT, F("# Rx received"), EMSdevice::DeviceType::SYSTEM, F("rxreceived"));
publish_mqtt_ha_sensor(DeviceValueType::INT, DeviceValueTAG::TAG_HEARTBEAT, F("# Rx fails"), EMSdevice::DeviceType::SYSTEM, F("rxfails")); publish_mqtt_ha_sensor(DeviceValueType::INT, DeviceValueTAG::TAG_HEARTBEAT, F("# Rx fails"), EMSdevice::DeviceType::SYSTEM, F("rxfails"));
@@ -1008,6 +1013,14 @@ void Mqtt::publish_mqtt_ha_sensor(uint8_t type, // EMSdevice
case DeviceValueUOM::PUMP: case DeviceValueUOM::PUMP:
doc["ic"] = F_(iconpump); doc["ic"] = F_(iconpump);
break; break;
case DeviceValueUOM::SECONDS:
case DeviceValueUOM::MINUTES:
case DeviceValueUOM::HOURS:
doc["ic"] = F_(iconclock);
break;
case DeviceValueUOM::KB:
doc["ic"] = F_(iconmemory);
break;
case DeviceValueUOM::NONE: case DeviceValueUOM::NONE:
default: default:
break; break;

View File

@@ -474,7 +474,7 @@ bool System::heartbeat_json(JsonObject & doc) {
doc["dallasfails"] = EMSESP::sensor_fails(); doc["dallasfails"] = EMSESP::sensor_fails();
} }
#ifndef EMSESP_STANDALONE #ifndef EMSESP_STANDALONE
doc["freemem"] = ESP.getFreeHeap(); doc["freemem"] = ESP.getFreeHeap() / 1000L; // kilobytes
#endif #endif
if (analog_enabled_) { if (analog_enabled_) {
@@ -897,7 +897,7 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & json
node["version"] = EMSESP_APP_VERSION; node["version"] = EMSESP_APP_VERSION;
node["uptime"] = uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3); node["uptime"] = uuid::log::format_timestamp_ms(uuid::get_uptime_ms(), 3);
#ifndef EMSESP_STANDALONE #ifndef EMSESP_STANDALONE
node["freemem"] = ESP.getFreeHeap(); node["freemem"] = ESP.getFreeHeap() / 1000L; // kilobytes
#endif #endif
node = json.createNestedObject("Status"); node = json.createNestedObject("Status");