Feature: Publish Radio statistics to home assistant
This commit is contained in:
parent
181802a76b
commit
bef81eed45
@ -65,6 +65,7 @@ private:
|
|||||||
void publishInverterButton(std::shared_ptr<InverterAbstract> inv, const char* caption, const char* icon, const char* category, const char* deviceClass, const char* subTopic, const char* payload);
|
void publishInverterButton(std::shared_ptr<InverterAbstract> inv, const char* caption, const char* icon, const char* category, const char* deviceClass, const char* subTopic, const char* payload);
|
||||||
void publishInverterNumber(std::shared_ptr<InverterAbstract> inv, const char* caption, const char* icon, const char* category, const char* commandTopic, const char* stateTopic, const char* unitOfMeasure, const int16_t min = 1, const int16_t max = 100, float step = 1.0);
|
void publishInverterNumber(std::shared_ptr<InverterAbstract> inv, const char* caption, const char* icon, const char* category, const char* commandTopic, const char* stateTopic, const char* unitOfMeasure, const int16_t min = 1, const int16_t max = 100, float step = 1.0);
|
||||||
void publishInverterBinarySensor(std::shared_ptr<InverterAbstract> inv, const char* caption, const char* subTopic, const char* payload_on, const char* payload_off);
|
void publishInverterBinarySensor(std::shared_ptr<InverterAbstract> inv, const char* caption, const char* subTopic, const char* payload_on, const char* payload_off);
|
||||||
|
void publishInverterSensor(std::shared_ptr<InverterAbstract> inv, const char* caption, const char* subTopic, const char* icon, const char* category, const char* device_class, const char* unit_of_measure);
|
||||||
|
|
||||||
static void createInverterInfo(JsonDocument& doc, std::shared_ptr<InverterAbstract> inv);
|
static void createInverterInfo(JsonDocument& doc, std::shared_ptr<InverterAbstract> inv);
|
||||||
static void createDtuInfo(JsonDocument& doc);
|
static void createDtuInfo(JsonDocument& doc);
|
||||||
|
|||||||
@ -88,6 +88,17 @@ void MqttHandleHassClass::publishConfig()
|
|||||||
publishInverterBinarySensor(inv, "Reachable", "status/reachable", "1", "0");
|
publishInverterBinarySensor(inv, "Reachable", "status/reachable", "1", "0");
|
||||||
publishInverterBinarySensor(inv, "Producing", "status/producing", "1", "0");
|
publishInverterBinarySensor(inv, "Producing", "status/producing", "1", "0");
|
||||||
|
|
||||||
|
yield();
|
||||||
|
|
||||||
|
publishInverterSensor(inv, "TX Requests", "radio/tx_request", "", "diagnostic", "", "");
|
||||||
|
publishInverterSensor(inv, "RX Success", "radio/rx_success", "", "diagnostic", "", "");
|
||||||
|
publishInverterSensor(inv, "RX Fail Receive Nothing", "radio/rx_fail_nothing", "", "diagnostic", "", "");
|
||||||
|
publishInverterSensor(inv, "RX Fail Receive Partial", "radio/rx_fail_partial", "", "diagnostic", "", "");
|
||||||
|
publishInverterSensor(inv, "RX Fail Receive Corrupt", "radio/rx_fail_corrupt", "", "diagnostic", "", "");
|
||||||
|
publishInverterSensor(inv, "TX Re-Request Fragment", "radio/tx_re_request", "", "diagnostic", "", "");
|
||||||
|
|
||||||
|
yield();
|
||||||
|
|
||||||
// Loop all channels
|
// Loop all channels
|
||||||
for (auto& t : inv->Statistics()->getChannelTypes()) {
|
for (auto& t : inv->Statistics()->getChannelTypes()) {
|
||||||
for (auto& c : inv->Statistics()->getChannelsByType(t)) {
|
for (auto& c : inv->Statistics()->getChannelsByType(t)) {
|
||||||
@ -295,6 +306,55 @@ void MqttHandleHassClass::publishInverterBinarySensor(std::shared_ptr<InverterAb
|
|||||||
publish(configTopic, buffer);
|
publish(configTopic, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MqttHandleHassClass::publishInverterSensor(std::shared_ptr<InverterAbstract> inv, const char* caption, const char* subTopic, const char* icon, const char* category, const char* device_class, const char* unit_of_measure)
|
||||||
|
{
|
||||||
|
const String serial = inv->serialString();
|
||||||
|
|
||||||
|
String sensorId = caption;
|
||||||
|
sensorId.replace(" ", "_");
|
||||||
|
sensorId.toLowerCase();
|
||||||
|
|
||||||
|
const String configTopic = "sensor/dtu_" + serial
|
||||||
|
+ "/" + sensorId
|
||||||
|
+ "/config";
|
||||||
|
|
||||||
|
const String statTopic = MqttSettings.getPrefix() + serial + "/" + subTopic;
|
||||||
|
|
||||||
|
JsonDocument root;
|
||||||
|
|
||||||
|
root["name"] = caption;
|
||||||
|
root["uniq_id"] = serial + "_" + sensorId;
|
||||||
|
if (strcmp(device_class, "")) {
|
||||||
|
root["dev_cla"] = device_class;
|
||||||
|
}
|
||||||
|
if (strcmp(category, "")) {
|
||||||
|
root["ent_cat"] = category;
|
||||||
|
}
|
||||||
|
if (strcmp(icon, "")) {
|
||||||
|
root["ic"] = icon;
|
||||||
|
}
|
||||||
|
if (strcmp(unit_of_measure, "")) {
|
||||||
|
root["unit_of_meas"] = unit_of_measure;
|
||||||
|
}
|
||||||
|
root["stat_t"] = statTopic;
|
||||||
|
|
||||||
|
root["avty_t"] = MqttSettings.getPrefix() + Configuration.get().Mqtt.Lwt.Topic;
|
||||||
|
|
||||||
|
const CONFIG_T& config = Configuration.get();
|
||||||
|
root["pl_avail"] = config.Mqtt.Lwt.Value_Online;
|
||||||
|
root["pl_not_avail"] = config.Mqtt.Lwt.Value_Offline;
|
||||||
|
|
||||||
|
createInverterInfo(root, inv);
|
||||||
|
|
||||||
|
if (!Utils::checkJsonAlloc(root, __FUNCTION__, __LINE__)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String buffer;
|
||||||
|
serializeJson(root, buffer);
|
||||||
|
publish(configTopic, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
void MqttHandleHassClass::publishDtuSensor(const char* name, const char* device_class, const char* category, const char* icon, const char* unit_of_measure, const char* subTopic)
|
void MqttHandleHassClass::publishDtuSensor(const char* name, const char* device_class, const char* category, const char* icon, const char* unit_of_measure, const char* subTopic)
|
||||||
{
|
{
|
||||||
String id = name;
|
String id = name;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user