|
|
@ -255,6 +255,7 @@ class ZeroExport { |
|
|
|
|
|
|
|
/** tickerMidnight
|
|
|
|
* Time pulse Midnicht |
|
|
|
* Reboots Inverter at Midnight to reset YieldDay and clean start environment |
|
|
|
* @param void |
|
|
|
* @returns void |
|
|
|
* @todo Reboot der Inverter um Mitternacht in Ahoy selbst verschieben mit separater Config-Checkbox |
|
|
@ -263,9 +264,8 @@ class ZeroExport { |
|
|
|
void tickMidnight(void) { |
|
|
|
if (!mIsInitialized) return; |
|
|
|
|
|
|
|
// Select all Inverter to reboot
|
|
|
|
for (uint8_t group = 0; group < ZEROEXPORT_MAX_GROUPS; group++) { |
|
|
|
for (uint8_t inv = 0; inv < ZEROEXPORT_GROUP_MAX_INVERTERS; inv++) { |
|
|
|
for (uint8_t inv = 0; inv < ZEROEXPORT_GROUP_MAX_INVERTERS; inv++) { |
|
|
|
mCfg->groups[group].inverters[inv].doReboot = 1; |
|
|
|
} |
|
|
|
} |
|
|
@ -546,6 +546,17 @@ class ZeroExport { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// topic for powermeter?
|
|
|
|
for (uint8_t group = 0; group < ZEROEXPORT_MAX_GROUPS; group++) |
|
|
|
{ |
|
|
|
if(mCfg->groups[group].pm_type == zeroExportPowermeterType_t::Mqtt) |
|
|
|
{ |
|
|
|
mLog["mqttDevice"] = "topicInverter"; |
|
|
|
if(!topic.equals(mCfg->groups[group].pm_jsonPath)) return; |
|
|
|
mCfg->groups[group].pm_P = (int32_t)obj["val"]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (mCfg->debug) mLog["Msg"] = obj; |
|
|
|
sendLog(); |
|
|
|
clearLog(); |
|
|
@ -820,6 +831,14 @@ class ZeroExport { |
|
|
|
*doLog = true; |
|
|
|
} |
|
|
|
} |
|
|
|
// Battery
|
|
|
|
String gr = "zero/state/groups/" + String(group) + "/battery"; |
|
|
|
mqttObj["enabled"] = cfgGroup->battEnabled; |
|
|
|
mqttObj["voltageOn"] = cfgGroup->battVoltageOn; |
|
|
|
mqttObj["voltageOff"] = cfgGroup->battVoltageOff; |
|
|
|
mqttObj["switch"] = cfgGroup->battSwitch; |
|
|
|
mqttPublish(gr.c_str(), mqttDoc.as<std::string>().c_str()); |
|
|
|
mqttDoc.clear(); |
|
|
|
} else { |
|
|
|
mLog["en"] = false; |
|
|
|
|
|
|
@ -851,10 +870,8 @@ class ZeroExport { |
|
|
|
mCfg->groups[group].pm_P3 = mPowermeter.getDataAVG(group).P3; |
|
|
|
|
|
|
|
if ( |
|
|
|
(mCfg->groups[group].pm_P == 0) && |
|
|
|
(mCfg->groups[group].pm_P1 == 0) && |
|
|
|
(mCfg->groups[group].pm_P2 == 0) && |
|
|
|
(mCfg->groups[group].pm_P3 == 0)) { |
|
|
|
(mCfg->groups[group].pm_P == 0) && (mCfg->groups[group].pm_P1 == 0) && |
|
|
|
(mCfg->groups[group].pm_P2 == 0) && (mCfg->groups[group].pm_P3 == 0)) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
@ -864,12 +881,15 @@ class ZeroExport { |
|
|
|
mLog["P3"] = mCfg->groups[group].pm_P3; |
|
|
|
|
|
|
|
// MQTT - Powermeter
|
|
|
|
mqttObj["Sum"] = mCfg->groups[group].pm_P; |
|
|
|
mqttObj["L1"] = mCfg->groups[group].pm_P1; |
|
|
|
mqttObj["L2"] = mCfg->groups[group].pm_P2; |
|
|
|
mqttObj["L3"] = mCfg->groups[group].pm_P3; |
|
|
|
mMqtt->publish(String("zero/state/groups/" + String(group) + "/powermeter/P").c_str(), mqttDoc.as<std::string>().c_str(), false); |
|
|
|
mqttDoc.clear(); |
|
|
|
if(mMqtt->isConnected()) |
|
|
|
{ |
|
|
|
mqttObj["Sum"] = mCfg->groups[group].pm_P; |
|
|
|
mqttObj["L1"] = mCfg->groups[group].pm_P1; |
|
|
|
mqttObj["L2"] = mCfg->groups[group].pm_P2; |
|
|
|
mqttObj["L3"] = mCfg->groups[group].pm_P3; |
|
|
|
mMqtt->publish(String("zero/state/groups/" + String(group) + "/powermeter/P").c_str(), mqttDoc.as<std::string>().c_str(), false); |
|
|
|
mqttDoc.clear(); |
|
|
|
} |
|
|
|
|
|
|
|
// if (cfgGroup->pm_Publish_W) {
|
|
|
|
// cfgGroup->pm_Publish_W = false;
|
|
|
@ -1026,6 +1046,18 @@ class ZeroExport { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
// Advanced
|
|
|
|
String gr = "zero/state/groups/" + String(group) + "/advanced"; |
|
|
|
mqttObj["setPoint"] = cfgGroup->setPoint; |
|
|
|
mqttObj["refresh"] = cfgGroup->refresh; |
|
|
|
mqttObj["powerTolerance"] = cfgGroup->powerTolerance; |
|
|
|
mqttObj["powerMax"] = cfgGroup->powerMax; |
|
|
|
mqttObj["Kp"] = cfgGroup->Kp; |
|
|
|
mqttObj["Ki"] = cfgGroup->Ki; |
|
|
|
mqttObj["Kd"] = cfgGroup->Kd; |
|
|
|
mqttPublish(gr.c_str(), mqttDoc.as<std::string>().c_str()); |
|
|
|
mqttDoc.clear(); |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
@ -1527,19 +1559,39 @@ class ZeroExport { |
|
|
|
obj["cmd"] = "limit_nonpersistent_absolute"; |
|
|
|
mApi->ctrlRequest(obj); |
|
|
|
|
|
|
|
// publish to mqtt when mqtt
|
|
|
|
if(mMqtt->isConnected()) |
|
|
|
{ |
|
|
|
String gr = "zero/state/groups/" + String(group) + "/inverters/" + String(inv); |
|
|
|
mqttObj["enabled"] = cfgGroupInv->enabled; |
|
|
|
mqttObj["id"] = cfgGroupInv->id; |
|
|
|
mqttObj["target"] = cfgGroupInv->target; |
|
|
|
mqttObj["powerMin"] = cfgGroupInv->powerMin; |
|
|
|
mqttObj["powerMax"] = cfgGroupInv->powerMax; |
|
|
|
mMqtt->publish(gr.c_str(), mqttDoc.as<std::string>().c_str(), false); |
|
|
|
mqttDoc.clear(); |
|
|
|
} |
|
|
|
|
|
|
|
if (mCfg->debug) logObj["d"] = obj; |
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/**
|
|
|
|
* |
|
|
|
*/ |
|
|
|
void PubSubInit(String gr, String payload) { |
|
|
|
mMqtt->publish(gr.c_str(), payload.c_str(), false); |
|
|
|
/* mqttSubscribe
|
|
|
|
* when a MQTT Msg is needed to subscribe, then a publish is leading |
|
|
|
*/ |
|
|
|
void mqttSubscribe(String gr, String payload) |
|
|
|
{ |
|
|
|
mqttPublish(gr, payload); |
|
|
|
mMqtt->subscribe(gr.c_str(), QOS_2); |
|
|
|
} |
|
|
|
/* PubInit
|
|
|
|
* when a MQTT Msg is needed to Publish, but not to subscribe. |
|
|
|
*/ |
|
|
|
void mqttPublish(String gr, String payload, bool retain = false) |
|
|
|
{ |
|
|
|
mMqtt->publish(gr.c_str(), payload.c_str(), retain); |
|
|
|
} |
|
|
|
|
|
|
|
/**
|
|
|
|
* |
|
|
@ -1551,40 +1603,45 @@ class ZeroExport { |
|
|
|
mIsSubscribed = true; |
|
|
|
|
|
|
|
// Global (zeroExport)
|
|
|
|
mMqtt->publish("zero/set/enabled", ((mCfg->enabled) ? dict[STR_TRUE] : dict[STR_FALSE]), false); |
|
|
|
mMqtt->subscribe("zero/set/enabled", QOS_2); |
|
|
|
// TODO: Global wird fälschlicherweise hier je nach anzahl der aktivierten Gruppen bis zu 6x ausgeführt.
|
|
|
|
mqttSubscribe("zero/set/enabled", ((mCfg->enabled) ? dict[STR_TRUE] : dict[STR_FALSE])); |
|
|
|
|
|
|
|
mMqtt->publish("zero/set/sleep", ((mCfg->sleep) ? dict[STR_TRUE] : dict[STR_FALSE]), false); |
|
|
|
mMqtt->subscribe("zero/set/sleep", QOS_2); |
|
|
|
// TODO: Global wird fälschlicherweise hier je nach anzahl der aktivierten Gruppen bis zu 6x ausgeführt.
|
|
|
|
mqttSubscribe("zero/set/sleep", ((mCfg->sleep) ? dict[STR_TRUE] : dict[STR_FALSE])); |
|
|
|
|
|
|
|
// Gruppen
|
|
|
|
String gr; |
|
|
|
for (uint8_t group = 0; group < ZEROEXPORT_MAX_GROUPS; group++) { |
|
|
|
zeroExportGroup_t *cfgGroup = &mCfg->groups[group]; |
|
|
|
if(!cfgGroup->enabled) continue; // exit here when group is disabled
|
|
|
|
|
|
|
|
gr = "zero/set/groups/" + String(group); |
|
|
|
|
|
|
|
// General
|
|
|
|
PubSubInit(gr + "/enabled", ((cfgGroup->enabled) ? dict[STR_TRUE] : dict[STR_FALSE])); |
|
|
|
PubSubInit(gr + "/sleep", ((cfgGroup->enabled) ? dict[STR_TRUE] : dict[STR_FALSE])); |
|
|
|
mqttSubscribe(gr + "/enabled", ((cfgGroup->enabled) ? dict[STR_TRUE] : dict[STR_FALSE])); |
|
|
|
mqttSubscribe(gr + "/sleep", ((cfgGroup->enabled) ? dict[STR_TRUE] : dict[STR_FALSE])); |
|
|
|
|
|
|
|
// Powermeter
|
|
|
|
|
|
|
|
// Inverters
|
|
|
|
// Inverters - Only Publish
|
|
|
|
for (uint8_t inv = 0; inv < ZEROEXPORT_GROUP_MAX_INVERTERS; inv++) { |
|
|
|
zeroExportGroupInverter_t *cfgGroupInv = &cfgGroup->inverters[inv]; |
|
|
|
|
|
|
|
PubSubInit(gr + "/inverters/" + String(inv) + "/enabled", ((cfgGroupInv->enabled) ? dict[STR_TRUE] : dict[STR_FALSE])); |
|
|
|
PubSubInit(gr + "/inverters/" + String(inv) + "/powerMin", String(cfgGroupInv->powerMin)); |
|
|
|
PubSubInit(gr + "/inverters/" + String(inv) + "/powerMax", String(cfgGroupInv->powerMax)); |
|
|
|
mqttSubscribe(gr + "/inverters/" + String(inv) + "/enabled", ((cfgGroupInv->enabled) ? dict[STR_TRUE] : dict[STR_FALSE])); |
|
|
|
mqttSubscribe(gr + "/inverters/" + String(inv) + "/powerMin", String(cfgGroupInv->powerMin)); |
|
|
|
mqttSubscribe(gr + "/inverters/" + String(inv) + "/powerMax", String(cfgGroupInv->powerMax)); |
|
|
|
} |
|
|
|
|
|
|
|
// Battery
|
|
|
|
PubSubInit(gr + "/battery/switch", ((cfgGroup->battSwitch) ? dict[STR_TRUE] : dict[STR_FALSE])); |
|
|
|
mqttSubscribe(gr + "/battery/switch", ((cfgGroup->battSwitch) ? dict[STR_TRUE] : dict[STR_FALSE])); |
|
|
|
|
|
|
|
// Advanced
|
|
|
|
PubSubInit(gr + "/advanced/setPoint", String(cfgGroup->setPoint)); |
|
|
|
PubSubInit(gr + "/advanced/powerTolerance", String(cfgGroup->powerTolerance)); |
|
|
|
PubSubInit(gr + "/advanced/powerMax", String(cfgGroup->powerMax)); |
|
|
|
mqttSubscribe(gr + "/advanced/setPoint", String(cfgGroup->setPoint)); |
|
|
|
mqttSubscribe(gr + "/advanced/powerTolerance", String(cfgGroup->powerTolerance)); |
|
|
|
mqttSubscribe(gr + "/advanced/powerMax", String(cfgGroup->powerMax)); |
|
|
|
mqttSubscribe(gr + "/advanced/refresh", String(cfgGroup->refresh)); |
|
|
|
mqttSubscribe(gr + "/advanced/Kp", String(cfgGroup->Kp)); |
|
|
|
mqttSubscribe(gr + "/advanced/Ki", String(cfgGroup->Ki)); |
|
|
|
mqttSubscribe(gr + "/advanced/Kd", String(cfgGroup->Kd)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -1603,54 +1660,20 @@ class ZeroExport { |
|
|
|
String gr; |
|
|
|
|
|
|
|
// Global (zeroExport)
|
|
|
|
// TODO: Global wird fälschlicherweise hier je nach anzahl der aktivierten Gruppen bis zu 6x ausgeführt.
|
|
|
|
mMqtt->publish("zero/state/enabled", ((mCfg->enabled) ? dict[STR_TRUE] : dict[STR_FALSE]), false); |
|
|
|
// TODO: Global wird fälschlicherweise hier je nach anzahl der aktivierten Gruppen bis zu 6x ausgeführt.
|
|
|
|
mMqtt->publish("zero/state/sleep", ((mCfg->sleep) ? dict[STR_TRUE] : dict[STR_FALSE]), false); |
|
|
|
mqttSubscribe("zero/set/enabled", ((mCfg->enabled) ? dict[STR_TRUE] : dict[STR_FALSE])); |
|
|
|
mqttSubscribe("zero/set/sleep", ((mCfg->sleep) ? dict[STR_TRUE] : dict[STR_FALSE])); |
|
|
|
|
|
|
|
// General
|
|
|
|
gr = "zero/state/groups/" + String(group) + "/enabled"; |
|
|
|
mMqtt->publish(gr.c_str(), ((cfgGroup->enabled) ? dict[STR_TRUE] : dict[STR_FALSE]), false); |
|
|
|
|
|
|
|
mqttPublish(gr.c_str(), ((cfgGroup->enabled) ? dict[STR_TRUE] : dict[STR_FALSE])); |
|
|
|
mqttPublish(gr.c_str(), ((cfgGroup->sleep) ? dict[STR_TRUE] : dict[STR_FALSE])); |
|
|
|
|
|
|
|
gr = "zero/state/groups/" + String(group) + "/sleep"; |
|
|
|
mMqtt->publish(gr.c_str(), ((cfgGroup->sleep) ? dict[STR_TRUE] : dict[STR_FALSE]), false); |
|
|
|
|
|
|
|
gr = "zero/state/groups/" + String(group) + "/name"; |
|
|
|
mMqtt->publish(gr.c_str(), cfgGroup->name, false); |
|
|
|
|
|
|
|
// Inverters
|
|
|
|
for (uint8_t inv = 0; inv < ZEROEXPORT_GROUP_MAX_INVERTERS; inv++) { |
|
|
|
zeroExportGroupInverter_t *cfgGroupInv = &cfgGroup->inverters[inv]; |
|
|
|
gr = "zero/state/groups/" + String(group) + "/inverters/" + String(inv); |
|
|
|
mqttObj["enabled"] = cfgGroupInv->enabled; |
|
|
|
mqttObj["id"] = cfgGroupInv->id; |
|
|
|
mqttObj["target"] = cfgGroupInv->target; |
|
|
|
mqttObj["powerMin"] = cfgGroupInv->powerMin; |
|
|
|
mqttObj["powerMax"] = cfgGroupInv->powerMax; |
|
|
|
mMqtt->publish(gr.c_str(), mqttDoc.as<std::string>().c_str(), false); |
|
|
|
mqttDoc.clear(); |
|
|
|
} |
|
|
|
|
|
|
|
// Battery
|
|
|
|
gr = "zero/state/groups/" + String(group) + "/battery"; |
|
|
|
mqttObj["enabled"] = cfgGroup->battEnabled; |
|
|
|
mqttObj["voltageOn"] = cfgGroup->battVoltageOn; |
|
|
|
mqttObj["voltageOff"] = cfgGroup->battVoltageOff; |
|
|
|
mqttObj["switch"] = cfgGroup->battSwitch; |
|
|
|
mMqtt->publish(gr.c_str(), mqttDoc.as<std::string>().c_str(), false); |
|
|
|
mqttDoc.clear(); |
|
|
|
|
|
|
|
// Advanced
|
|
|
|
gr = "zero/state/groups/" + String(group) + "/advanced"; |
|
|
|
mqttObj["setPoint"] = cfgGroup->setPoint; |
|
|
|
mqttObj["refresh"] = cfgGroup->refresh; |
|
|
|
mqttObj["powerTolerance"] = cfgGroup->powerTolerance; |
|
|
|
mqttObj["powerMax"] = cfgGroup->powerMax; |
|
|
|
mqttObj["Kp"] = cfgGroup->Kp; |
|
|
|
mqttObj["Ki"] = cfgGroup->Ki; |
|
|
|
mqttObj["Kd"] = cfgGroup->Kd; |
|
|
|
mMqtt->publish(gr.c_str(), mqttDoc.as<std::string>().c_str(), false); |
|
|
|
mqttDoc.clear(); |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|