Skip to content

Commit 74b4547

Browse files
Merge pull request #551 from KipK/shaper
Allow shaper to use same topic as grid_ie
2 parents a285f54 + 2edb190 commit 74b4547

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

src/current_shaper.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,15 @@ void CurrentShaperTask::shapeCurrent() {
122122
if (mqtt_solar != "") {
123123
max_pwr += solar;
124124
}
125-
else if (mqtt_grid_ie != "" && (grid_ie <= 0)) {
126-
max_pwr -= grid_ie;
127-
}
128125
}
129-
if(!config_threephase_enabled())
126+
if(!config_threephase_enabled()) {
130127
_max_cur = round(((max_pwr - _live_pwr) / evse.getVoltage()) + (evse.getAmps()));
131-
else
128+
}
129+
130+
else {
132131
_max_cur = round(((max_pwr - _live_pwr) / evse.getVoltage() / 3) + (evse.getAmps()));
132+
}
133+
133134

134135

135136
_changed = true;

src/divert.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ void DivertTask::update_state()
160160
if (_mode == DivertMode::Eco)
161161
{
162162
double voltage = _evse->getVoltage();
163+
if (config_threephase_enabled()) {
164+
voltage = voltage * 3;
165+
}
163166

164167
// Calculate current
165168
if (mqtt_grid_ie != "")

src/mqtt.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ void mqttmsg_callback(MongooseString topic, MongooseString payload) {
7676
grid_ie = payload_str.toInt();
7777
DBUGF("grid:%dW", grid_ie);
7878
divert.update_state();
79-
//recalculate shaper
80-
if (shaper.getState()) {
81-
shaper.shapeCurrent();
79+
80+
// if shaper use the same topic as grid_ie
81+
if (mqtt_live_pwr == mqtt_grid_ie) {
82+
shaper.setLivePwr(grid_ie);
8283
}
8384
}
8485
else if (topic_string == mqtt_live_pwr)
@@ -311,8 +312,11 @@ mqtt_connect()
311312
if(config_current_shaper_enabled())
312313
{
313314
if (mqtt_live_pwr != "") {
314-
mqttclient.subscribe(mqtt_live_pwr);
315-
yield();
315+
if ( mqtt_live_pwr != mqtt_grid_ie ) {
316+
// only subscribe once
317+
mqttclient.subscribe(mqtt_live_pwr);
318+
yield();
319+
}
316320
}
317321
}
318322
// subscribe to vehicle information from MQTT if we are configured for it

0 commit comments

Comments
 (0)