Skip to content

Commit

Permalink
Pytes: Implement CAN message 0x360
Browse files Browse the repository at this point in the history
This one-byte message is set to 0xff to request charging below a
 certain SoC threshold (10% in my tests).
  • Loading branch information
ranma authored and AndreasBoehm committed Oct 10, 2024
1 parent bac4894 commit 4ba55b7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/BatteryStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ class PytesBatteryStats : public BatteryStats {
public:
void getLiveViewData(JsonVariant& root) const final;
void mqttPublish() const final;
bool getImmediateChargingRequest() const { return _chargeImmediately; };
float getChargeCurrentLimitation() const { return _chargeCurrentLimit; };

private:
Expand Down Expand Up @@ -247,6 +248,8 @@ class PytesBatteryStats : public BatteryStats {
bool _warningHighTemperatureCharge;
bool _warningInternalFailure;
bool _warningCellImbalance;

bool _chargeImmediately;
};

class JkBmsBatteryStats : public BatteryStats {
Expand Down
3 changes: 3 additions & 0 deletions src/BatteryStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ void PytesBatteryStats::getLiveViewData(JsonVariant& root) const
if (_dischargedEnergy != -1) {
addLiveViewValue(root, "dischargedEnergy", _dischargedEnergy, "kWh", 1);
}
addLiveViewTextValue(root, "chargeImmediately", (_chargeImmediately?"yes":"no"));

addLiveViewInSection(root, "cells", "cellMinVoltage", static_cast<float>(_cellMinMilliVolt)/1000, "V", 3);
addLiveViewInSection(root, "cells", "cellMaxVoltage", static_cast<float>(_cellMaxMilliVolt)/1000, "V", 3);
Expand Down Expand Up @@ -482,6 +483,8 @@ void PytesBatteryStats::mqttPublish() const
MqttSettings.publish("battery/warning/highTemperatureCharge", String(_warningHighTemperatureCharge));
MqttSettings.publish("battery/warning/bmsInternal", String(_warningInternalFailure));
MqttSettings.publish("battery/warning/cellImbalance", String(_warningCellImbalance));

MqttSettings.publish("battery/charging/chargeImmediately", String(_chargeImmediately));
}

void JkBmsBatteryStats::mqttPublish() const
Expand Down
2 changes: 2 additions & 0 deletions src/MqttHandleBatteryHass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ void MqttHandleBatteryHassClass::loop()
publishBinarySensor("Warning Temperature high (charge)", "mdi:thermometer-high", "warning/highTemperatureCharge", "1", "0");
publishBinarySensor("Warning BMS internal", "mdi:alert-outline", "warning/bmsInternal", "1", "0");
publishBinarySensor("Warning Cell Imbalance", "mdi:alert-outline", "warning/cellImbalance", "1", "0");

publishBinarySensor("Charge immediately", "mdi:alert", "charging/chargeImmediately", "1", "0");
break;

case 5: // SBS Unipower
Expand Down
9 changes: 9 additions & 0 deletions src/PytesCanReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@ void PytesCanReceiver::onMessage(twai_message_t rx_message)
break;
}

case 0x360: { // Charging request
_stats->_chargeImmediately = rx_message.data[0]; // 0xff requests charging.
if (_verboseLogging) {
MessageOutput.printf("[Pytes] chargeImmediately: %d\r\n",
_stats->_chargeImmediately);
}
break;
}

case 0x372: { // BankInfo
_stats->_moduleCountOnline = this->readUnsignedInt16(rx_message.data);
_stats->_moduleCountBlockingCharge = this->readUnsignedInt16(rx_message.data + 2);
Expand Down

0 comments on commit 4ba55b7

Please sign in to comment.