diff --git a/src/current_shaper.cpp b/src/current_shaper.cpp index 24244c2f..0e2badd6 100644 --- a/src/current_shaper.cpp +++ b/src/current_shaper.cpp @@ -122,14 +122,15 @@ void CurrentShaperTask::shapeCurrent() { if (mqtt_solar != "") { max_pwr += solar; } - else if (mqtt_grid_ie != "" && (grid_ie <= 0)) { - max_pwr -= grid_ie; - } } - if(!config_threephase_enabled()) + if(!config_threephase_enabled()) { _max_cur = round(((max_pwr - _live_pwr) / evse.getVoltage()) + (evse.getAmps())); - else + } + + else { _max_cur = round(((max_pwr - _live_pwr) / evse.getVoltage() / 3) + (evse.getAmps())); + } + _changed = true; diff --git a/src/divert.cpp b/src/divert.cpp index 1a26fa0c..1e8666a8 100644 --- a/src/divert.cpp +++ b/src/divert.cpp @@ -160,6 +160,9 @@ void DivertTask::update_state() if (_mode == DivertMode::Eco) { double voltage = _evse->getVoltage(); + if (config_threephase_enabled()) { + voltage = voltage * 3; + } // Calculate current if (mqtt_grid_ie != "") diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 12069800..6006c86f 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -76,9 +76,10 @@ void mqttmsg_callback(MongooseString topic, MongooseString payload) { grid_ie = payload_str.toInt(); DBUGF("grid:%dW", grid_ie); divert.update_state(); - //recalculate shaper - if (shaper.getState()) { - shaper.shapeCurrent(); + + // if shaper use the same topic as grid_ie + if (mqtt_live_pwr == mqtt_grid_ie) { + shaper.setLivePwr(grid_ie); } } else if (topic_string == mqtt_live_pwr) @@ -311,8 +312,11 @@ mqtt_connect() if(config_current_shaper_enabled()) { if (mqtt_live_pwr != "") { - mqttclient.subscribe(mqtt_live_pwr); - yield(); + if ( mqtt_live_pwr != mqtt_grid_ie ) { + // only subscribe once + mqttclient.subscribe(mqtt_live_pwr); + yield(); + } } } // subscribe to vehicle information from MQTT if we are configured for it