Implement inverter restart by mqtt topic
This commit is contained in:
parent
753ab1312e
commit
da0998c809
@ -69,3 +69,4 @@ cmd topics are used to set values. Status topics are updated from values set in
|
|||||||
| [serial]/cmd/limit_nonpersistent_relative | W | Set the inverter limit as a percentage of total production capability. The value will reset to the last persistent value at night without power. The updated value will show up in the web GUI and limit_relative topic immediatly. | % |
|
| [serial]/cmd/limit_nonpersistent_relative | W | Set the inverter limit as a percentage of total production capability. The value will reset to the last persistent value at night without power. The updated value will show up in the web GUI and limit_relative topic immediatly. | % |
|
||||||
| [serial]/cmd/limit_nonpersistent_absolute | W | Set the inverter limit as a absolute value. The value will reset to the last persistent value at night without power. The updated value will show up in the web GUI and limit_relative topic after around 4 minutes. | Watt (W) |
|
| [serial]/cmd/limit_nonpersistent_absolute | W | Set the inverter limit as a absolute value. The value will reset to the last persistent value at night without power. The updated value will show up in the web GUI and limit_relative topic after around 4 minutes. | Watt (W) |
|
||||||
| [serial]/cmd/power | W | Turn the inverter on (1) or off (0) | 0 or 1 |
|
| [serial]/cmd/power | W | Turn the inverter on (1) or off (0) | 0 or 1 |
|
||||||
|
| [serial]/cmd/restart | W | Restarts the inverters (also resets YieldDay) | 1 |
|
||||||
@ -115,7 +115,11 @@ bool HM_Abstract::resendActivePowerControlRequest(HoymilesRadio* radio)
|
|||||||
|
|
||||||
bool HM_Abstract::sendPowerControlRequest(HoymilesRadio* radio, bool turnOn)
|
bool HM_Abstract::sendPowerControlRequest(HoymilesRadio* radio, bool turnOn)
|
||||||
{
|
{
|
||||||
_powerState = turnOn;
|
if (turnOn) {
|
||||||
|
_powerState = 1;
|
||||||
|
} else {
|
||||||
|
_powerState = 0;
|
||||||
|
}
|
||||||
|
|
||||||
PowerControlCommand* cmd = radio->enqueCommand<PowerControlCommand>();
|
PowerControlCommand* cmd = radio->enqueCommand<PowerControlCommand>();
|
||||||
cmd->setPowerOn(turnOn);
|
cmd->setPowerOn(turnOn);
|
||||||
@ -125,7 +129,33 @@ bool HM_Abstract::sendPowerControlRequest(HoymilesRadio* radio, bool turnOn)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool HM_Abstract::sendRestartControlRequest(HoymilesRadio* radio)
|
||||||
|
{
|
||||||
|
_powerState = 2;
|
||||||
|
|
||||||
|
PowerControlCommand* cmd = radio->enqueCommand<PowerControlCommand>();
|
||||||
|
cmd->setRestart();
|
||||||
|
cmd->setTargetAddress(serial());
|
||||||
|
PowerCommand()->setLastPowerCommandSuccess(CMD_PENDING);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool HM_Abstract::resendPowerControlRequest(HoymilesRadio* radio)
|
bool HM_Abstract::resendPowerControlRequest(HoymilesRadio* radio)
|
||||||
{
|
{
|
||||||
return sendPowerControlRequest(radio, _powerState);
|
switch (_powerState) {
|
||||||
|
case 0:
|
||||||
|
return sendPowerControlRequest(radio, false);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
return sendPowerControlRequest(radio, true);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
return sendRestartControlRequest(radio);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -12,6 +12,7 @@ public:
|
|||||||
bool sendActivePowerControlRequest(HoymilesRadio* radio, float limit, PowerLimitControlType type);
|
bool sendActivePowerControlRequest(HoymilesRadio* radio, float limit, PowerLimitControlType type);
|
||||||
bool resendActivePowerControlRequest(HoymilesRadio* radio);
|
bool resendActivePowerControlRequest(HoymilesRadio* radio);
|
||||||
bool sendPowerControlRequest(HoymilesRadio* radio, bool turnOn);
|
bool sendPowerControlRequest(HoymilesRadio* radio, bool turnOn);
|
||||||
|
bool sendRestartControlRequest(HoymilesRadio* radio);
|
||||||
bool resendPowerControlRequest(HoymilesRadio* radio);
|
bool resendPowerControlRequest(HoymilesRadio* radio);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -19,5 +20,5 @@ private:
|
|||||||
float _activePowerControlLimit = 0;
|
float _activePowerControlLimit = 0;
|
||||||
PowerLimitControlType _activePowerControlType = PowerLimitControlType::AbsolutNonPersistent;
|
PowerLimitControlType _activePowerControlType = PowerLimitControlType::AbsolutNonPersistent;
|
||||||
|
|
||||||
bool _powerState = true;
|
uint8_t _powerState = 1;
|
||||||
};
|
};
|
||||||
@ -53,6 +53,7 @@ public:
|
|||||||
virtual bool sendActivePowerControlRequest(HoymilesRadio* radio, float limit, PowerLimitControlType type) = 0;
|
virtual bool sendActivePowerControlRequest(HoymilesRadio* radio, float limit, PowerLimitControlType type) = 0;
|
||||||
virtual bool resendActivePowerControlRequest(HoymilesRadio* radio) = 0;
|
virtual bool resendActivePowerControlRequest(HoymilesRadio* radio) = 0;
|
||||||
virtual bool sendPowerControlRequest(HoymilesRadio* radio, bool turnOn) = 0;
|
virtual bool sendPowerControlRequest(HoymilesRadio* radio, bool turnOn) = 0;
|
||||||
|
virtual bool sendRestartControlRequest(HoymilesRadio* radio) = 0;
|
||||||
virtual bool resendPowerControlRequest(HoymilesRadio* radio) = 0;
|
virtual bool resendPowerControlRequest(HoymilesRadio* radio) = 0;
|
||||||
|
|
||||||
AlarmLogParser* EventLog();
|
AlarmLogParser* EventLog();
|
||||||
|
|||||||
@ -15,6 +15,7 @@
|
|||||||
#define TOPIC_SUB_LIMIT_NONPERSISTENT_RELATIVE "limit_nonpersistent_relative"
|
#define TOPIC_SUB_LIMIT_NONPERSISTENT_RELATIVE "limit_nonpersistent_relative"
|
||||||
#define TOPIC_SUB_LIMIT_NONPERSISTENT_ABSOLUTE "limit_nonpersistent_absolute"
|
#define TOPIC_SUB_LIMIT_NONPERSISTENT_ABSOLUTE "limit_nonpersistent_absolute"
|
||||||
#define TOPIC_SUB_POWER "power"
|
#define TOPIC_SUB_POWER "power"
|
||||||
|
#define TOPIC_SUB_RESTART "restart"
|
||||||
|
|
||||||
MqttSettingsClass::MqttSettingsClass()
|
MqttSettingsClass::MqttSettingsClass()
|
||||||
{
|
{
|
||||||
@ -48,6 +49,7 @@ void MqttSettingsClass::onMqttConnect(bool sessionPresent)
|
|||||||
mqttClient->subscribe(String(topic + "+/cmd/" + TOPIC_SUB_LIMIT_NONPERSISTENT_RELATIVE).c_str(), 0);
|
mqttClient->subscribe(String(topic + "+/cmd/" + TOPIC_SUB_LIMIT_NONPERSISTENT_RELATIVE).c_str(), 0);
|
||||||
mqttClient->subscribe(String(topic + "+/cmd/" + TOPIC_SUB_LIMIT_NONPERSISTENT_ABSOLUTE).c_str(), 0);
|
mqttClient->subscribe(String(topic + "+/cmd/" + TOPIC_SUB_LIMIT_NONPERSISTENT_ABSOLUTE).c_str(), 0);
|
||||||
mqttClient->subscribe(String(topic + "+/cmd/" + TOPIC_SUB_POWER).c_str(), 0);
|
mqttClient->subscribe(String(topic + "+/cmd/" + TOPIC_SUB_POWER).c_str(), 0);
|
||||||
|
mqttClient->subscribe(String(topic + "+/cmd/" + TOPIC_SUB_RESTART).c_str(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MqttSettingsClass::onMqttDisconnect(espMqttClientTypes::DisconnectReason reason)
|
void MqttSettingsClass::onMqttDisconnect(espMqttClientTypes::DisconnectReason reason)
|
||||||
@ -155,10 +157,19 @@ void MqttSettingsClass::onMqttMessage(const espMqttClientTypes::MessagePropertie
|
|||||||
Serial.println("Ignored because retained");
|
Serial.println("Ignored because retained");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if(!strcmp(setting, TOPIC_SUB_POWER)) {
|
} else if (!strcmp(setting, TOPIC_SUB_POWER)) {
|
||||||
// Turn inverter on or off
|
// Turn inverter on or off
|
||||||
Serial.printf("Set inverter power to: %d\n", payload_val);
|
Serial.printf("Set inverter power to: %d\n", payload_val);
|
||||||
inv->sendPowerControlRequest(Hoymiles.getRadio(), payload_val > 0);
|
inv->sendPowerControlRequest(Hoymiles.getRadio(), payload_val > 0);
|
||||||
|
|
||||||
|
} else if (!strcmp(setting, TOPIC_SUB_RESTART)) {
|
||||||
|
// Restart inverter
|
||||||
|
Serial.printf("Restart inverter\n");
|
||||||
|
if (!properties.retain && payload_val == 1) {
|
||||||
|
inv->sendRestartControlRequest(Hoymiles.getRadio());
|
||||||
|
} else {
|
||||||
|
Serial.println("Ignored because retained");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user