Skip to content

Commit bbf6d23

Browse files
author
dingo35
committed
esp32.cpp, docs: add MQTT selector for EnableC2
1 parent 44fc1ba commit bbf6d23

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

SmartEVSE-3/src/esp32.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -668,9 +668,23 @@ void mqtt_receive_callback(const String topic, const String payload) {
668668
}
669669
write_settings();
670670
} else if (topic == MQTTprefix + "/Set/EnableC2") {
671-
uint8_t value = payload.toInt();
672-
if (value <=4) { //value is always >=0 because unsigned
673-
EnableC2 = (EnableC2_t) value;
671+
// for backwards compatibility we accept both 0-4 as string argument:
672+
//{ "Not present", "Always Off", "Solar Off", "Always On", "Auto" }
673+
uint8_t value;
674+
if (isdigit(payload[0])) {
675+
value = payload.toInt();
676+
if (value <=4) { //value is always >=0 because unsigned
677+
EnableC2 = (EnableC2_t) value;
678+
}
679+
} else {
680+
bool found=false;
681+
for (value=0; value<5; value++)
682+
if (payload == StrEnableC2[value]) {
683+
found = true;
684+
break;
685+
}
686+
if (found)
687+
EnableC2 = (EnableC2_t) value;
674688
}
675689
write_settings();
676690
}
@@ -809,6 +823,10 @@ void SetupMQTTClient() {
809823
optional_payload += String(R"(, "options" : ["Off", "Normal", "Smart", "Solar", "Pause"])");
810824
MQTTclient.announce("Mode", "select", optional_payload);
811825

826+
optional_payload = MQTTclient.jsna("state_topic", String(MQTTprefix + "/EnableC2")) + MQTTclient.jsna("command_topic", String(MQTTprefix + "/Set/EnableC2"));
827+
optional_payload += String(R"(, "options" : ["Not present", "Always Off", "Solar Off", "Always On", "Auto"])");
828+
MQTTclient.announce("EnableC2", "select", optional_payload);
829+
812830
//set the parameters for and MQTTclient.announce number entities:
813831
optional_payload = MQTTclient.jsna("command_topic", String(MQTTprefix + "/Set/CurrentOverride")) + MQTTclient.jsna("min", "0") + MQTTclient.jsna("max", MaxCurrent ) + MQTTclient.jsna("mode","slider");
814832
optional_payload += MQTTclient.jsna("value_template", R"({{ value | int / 10 if value | is_number else none }})") + MQTTclient.jsna("command_template", R"({{ value | int * 10 }})");
@@ -846,6 +864,7 @@ void mqttPublishData() {
846864
MQTTclient.publish(MQTTprefix + "/NrOfPhases", Nr_Of_Phases_Charging, true, 0);
847865
MQTTclient.publish(MQTTprefix + "/Access", AccessStatus == OFF ? "Deny" : AccessStatus == ON ? "Allow" : AccessStatus == PAUSE ? "Pause" : "N/A", true, 0);
848866
MQTTclient.publish(MQTTprefix + "/RFID", !RFIDReader ? "Not Installed" : RFIDstatus >= 8 ? "NOSTATUS" : StrRFIDStatusWeb[RFIDstatus], true, 0);
867+
MQTTclient.publish(MQTTprefix + "/EnableC2", StrEnableC2[EnableC2], true, 0);
849868
if (RFIDReader) {
850869
char buf[15];
851870
printRFID(buf);

docs/configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ Valid topics you can publish to are:
258258
/Set/ColorSolar
259259
/Set/CableLock
260260
/Set/EnableC2 0 "Not present", 1 "Always Off", 2 "Solar Off", 3 "Always On", 4 "Auto" ; do not change during charging to prevent unexpected errors of your EV!
261+
You can send either the number or the string, SmartEVSE will accept both!
261262
```
262263
Your mains kWh meter data can be fed with:
263264
```

0 commit comments

Comments
 (0)