Feature: expose 'full solar passsthrough active' via MQTT (#1136)
This commit is contained in:
parent
e3f9da75b9
commit
e95b70efeb
@ -15,6 +15,7 @@ private:
|
||||
void publish(const String& subtopic, const String& payload);
|
||||
void publishNumber(const char* caption, const char* icon, const char* category, const char* commandTopic, const char* stateTopic, const char* unitOfMeasure, const int16_t min, const int16_t max, const float step);
|
||||
void publishSelect(const char* caption, const char* icon, const char* category, const char* commandTopic, const char* stateTopic);
|
||||
void publishBinarySensor(const char* caption, const char* icon, const char* stateTopic, const char* payload_on, const char* payload_off);
|
||||
void createDeviceInfo(JsonDocument& root);
|
||||
|
||||
Task _loopTask;
|
||||
|
||||
@ -44,6 +44,7 @@ public:
|
||||
uint8_t getInverterUpdateTimeouts() const { return _inverterUpdateTimeouts; }
|
||||
uint8_t getPowerLimiterState();
|
||||
int32_t getLastRequestedPowerLimit() { return _lastRequestedPowerLimit; }
|
||||
bool getFullSolarPassThroughEnabled() const { return _fullSolarPassThroughEnabled; }
|
||||
|
||||
enum class Mode : unsigned {
|
||||
Normal = 0,
|
||||
|
||||
@ -91,6 +91,7 @@ void MqttHandlePowerLimiterClass::loop()
|
||||
MqttSettings.publish("powerlimiter/status/threshold/voltage/stop", String(config.PowerLimiter.VoltageStopThreshold));
|
||||
|
||||
if (config.Vedirect.Enabled) {
|
||||
MqttSettings.publish("powerlimiter/status/full_solar_passthrough_active", String(PowerLimiter.getFullSolarPassThroughEnabled()));
|
||||
MqttSettings.publish("powerlimiter/status/threshold/voltage/full_solar_passthrough_start", String(config.PowerLimiter.FullSolarPassThroughStartVoltage));
|
||||
MqttSettings.publish("powerlimiter/status/threshold/voltage/full_solar_passthrough_stop", String(config.PowerLimiter.FullSolarPassThroughStopVoltage));
|
||||
}
|
||||
|
||||
@ -75,6 +75,10 @@ void MqttHandlePowerLimiterHassClass::publishConfig()
|
||||
"config", "threshold/voltage/stop", "threshold/voltage/stop", "V", 16, 60, 0.1);
|
||||
|
||||
if (config.Vedirect.Enabled) {
|
||||
publishBinarySensor("full solar passthrough active",
|
||||
"mdi:transmission-tower-import",
|
||||
"full_solar_passthrough_active", "1", "0");
|
||||
|
||||
publishNumber("DPL full solar passthrough start voltage",
|
||||
"mdi:transmission-tower-import", "config",
|
||||
"threshold/voltage/full_solar_passthrough_start",
|
||||
@ -187,6 +191,47 @@ void MqttHandlePowerLimiterHassClass::publishNumber(
|
||||
publish(configTopic, buffer);
|
||||
}
|
||||
|
||||
void MqttHandlePowerLimiterHassClass::publishBinarySensor(
|
||||
const char* caption, const char* icon,
|
||||
const char* stateTopic, const char* payload_on, const char* payload_off)
|
||||
{
|
||||
|
||||
String numberId = caption;
|
||||
numberId.replace(" ", "_");
|
||||
numberId.toLowerCase();
|
||||
|
||||
const String configTopic = "binary_sensor/" + MqttHandleHass.getDtuUniqueId() + "/" + numberId + "/config";
|
||||
|
||||
const String statTopic = MqttSettings.getPrefix() + "powerlimiter/status/" + stateTopic;
|
||||
|
||||
JsonDocument root;
|
||||
|
||||
root["name"] = caption;
|
||||
root["uniq_id"] = MqttHandleHass.getDtuUniqueId() + "_" + numberId;
|
||||
if (strcmp(icon, "")) {
|
||||
root["ic"] = icon;
|
||||
}
|
||||
root["stat_t"] = statTopic;
|
||||
root["pl_on"] = payload_on;
|
||||
root["pl_off"] = payload_off;
|
||||
|
||||
auto const& config = Configuration.get();
|
||||
if (config.Mqtt.Hass.Expire) {
|
||||
root["exp_aft"] = config.Mqtt.PublishInterval * 3;
|
||||
}
|
||||
|
||||
createDeviceInfo(root);
|
||||
|
||||
if (!Utils::checkJsonAlloc(root, __FUNCTION__, __LINE__)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String buffer;
|
||||
serializeJson(root, buffer);
|
||||
publish(configTopic, buffer);
|
||||
}
|
||||
|
||||
|
||||
void MqttHandlePowerLimiterHassClass::createDeviceInfo(JsonDocument& root)
|
||||
{
|
||||
JsonObject object = root["dev"].to<JsonObject>();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user