From 3c8b0440d52b6b8081ed6a9782c089c99c1752eb Mon Sep 17 00:00:00 2001 From: KevinWieland Date: Thu, 13 Nov 2025 23:17:49 +0100 Subject: [PATCH 1/4] HTTP simpleAPI erweitert --- simpleAPI/simpleapi.php | 15 ++ simpleAPI/src/ParameterHandler.php | 373 +++++++++++++++++++++++++++++ 2 files changed, 388 insertions(+) diff --git a/simpleAPI/simpleapi.php b/simpleAPI/simpleapi.php index fe75951319..a71b24dda8 100644 --- a/simpleAPI/simpleapi.php +++ b/simpleAPI/simpleapi.php @@ -198,6 +198,20 @@ private function getReadParameters($params) // Chargepoint - Status & Energie 'get_chargepoint_imported', 'get_chargepoint_exported', + 'get_chargepoint_daily_imported', + 'get_chargepoint_daily_exported', + 'get_chargepoint_frequency', + 'get_chargepoint_rfid', + 'get_chargepoint_rfid_timestamp', + 'get_chargepoint_evse_current', + 'get_chargepoint_power_factors', + 'get_chargepoint_power_factor_p1', + 'get_chargepoint_power_factor_p2', + 'get_chargepoint_power_factor_p3', + 'get_chargepoint_config_name', + 'get_chargepoint_connected_vehicle_name', + 'get_chargepoint_charge_template_name', + 'get_chargepoint_charge_template_min_current', 'get_chargepoint_soc', 'get_chargepoint_state_str', 'get_chargepoint_fault_str', @@ -395,6 +409,7 @@ private function isComplexParameter($param) 'get_chargepoint_voltages', 'get_chargepoint_currents', 'get_chargepoint_powers', + 'get_chargepoint_power_factors', 'get_counter_voltages', 'get_counter_currents', 'get_counter_powers', diff --git a/simpleAPI/src/ParameterHandler.php b/simpleAPI/src/ParameterHandler.php index e2f2d107cf..f44516e41a 100644 --- a/simpleAPI/src/ParameterHandler.php +++ b/simpleAPI/src/ParameterHandler.php @@ -69,6 +69,34 @@ public function readParameter($param, $id) return $this->getChargepointImported($id); case 'get_chargepoint_exported': return $this->getChargepointExported($id); + case 'get_chargepoint_daily_imported': + return $this->getChargepointDailyImported($id); + case 'get_chargepoint_daily_exported': + return $this->getChargepointDailyExported($id); + case 'get_chargepoint_frequency': + return $this->getChargepointFrequency($id); + case 'get_chargepoint_rfid': + return $this->getChargepointRfid($id); + case 'get_chargepoint_rfid_timestamp': + return $this->getChargepointRfidTimestamp($id); + case 'get_chargepoint_evse_current': + return $this->getChargepointEvseCurrent($id); + case 'get_chargepoint_power_factors': + return $this->getChargepointPowerFactors($id); + case 'get_chargepoint_power_factor_p1': + return $this->getChargepointPowerFactor($id, 1); + case 'get_chargepoint_power_factor_p2': + return $this->getChargepointPowerFactor($id, 2); + case 'get_chargepoint_power_factor_p3': + return $this->getChargepointPowerFactor($id, 3); + case 'get_chargepoint_config_name': + return $this->getChargepointConfigName($id); + case 'get_chargepoint_connected_vehicle_name': + return $this->getChargepointConnectedVehicleName($id); + case 'get_chargepoint_charge_template_name': + return $this->getChargepointChargeTemplateName($id); + case 'get_chargepoint_charge_template_min_current': + return $this->getChargepointChargeTemplateMinCurrent($id); case 'get_chargepoint_soc': return $this->getChargepointSoc($id); case 'get_chargepoint_state_str': @@ -807,6 +835,351 @@ private function setChargepointLock($chargepointId, $value) return ['success' => false, 'message' => 'Failed to set chargepoint lock']; } + /** + * Chargepoint Daily Imported + */ + private function getChargepointDailyImported($id) + { + try { + $topic = "openWB/chargepoint/{$id}/get/daily_imported"; + $value = $this->mqttClient->getValue($topic); + return ["chargepoint_{$id}" => ['daily_imported' => floatval($value ?? 0)]]; + } catch (Exception $e) { + return ["chargepoint_{$id}" => ['daily_imported' => 0]]; + } + } + + /** + * Chargepoint Daily Exported + */ + private function getChargepointDailyExported($id) + { + try { + $topic = "openWB/chargepoint/{$id}/get/daily_exported"; + $value = $this->mqttClient->getValue($topic); + return ["chargepoint_{$id}" => ['daily_exported' => floatval($value ?? 0)]]; + } catch (Exception $e) { + return ["chargepoint_{$id}" => ['daily_exported' => 0]]; + } + } + + /** + * Chargepoint Frequency + */ + private function getChargepointFrequency($id) + { + try { + $topic = "openWB/chargepoint/{$id}/get/frequency"; + $value = $this->mqttClient->getValue($topic); + return ["chargepoint_{$id}" => ['frequency' => floatval($value ?? 0)]]; + } catch (Exception $e) { + return ["chargepoint_{$id}" => ['frequency' => 0]]; + } + } + + /** + * Chargepoint RFID + */ + private function getChargepointRfid($id) + { + try { + $topic = "openWB/chargepoint/{$id}/get/rfid"; + $value = $this->mqttClient->getValue($topic); + return ["chargepoint_{$id}" => ['rfid' => strval($value ?? '')]]; + } catch (Exception $e) { + return ["chargepoint_{$id}" => ['rfid' => '']]; + } + } + + /** + * Chargepoint RFID Timestamp + */ + private function getChargepointRfidTimestamp($id) + { + try { + $topic = "openWB/chargepoint/{$id}/get/rfid_timestamp"; + $value = $this->mqttClient->getValue($topic); + return ["chargepoint_{$id}" => ['rfid_timestamp' => intval($value ?? 0)]]; + } catch (Exception $e) { + return ["chargepoint_{$id}" => ['rfid_timestamp' => 0]]; + } + } + + /** + * Chargepoint EVSE Current + */ + private function getChargepointEvseCurrent($id) + { + try { + $topic = "openWB/chargepoint/{$id}/get/evse_current"; + $value = $this->mqttClient->getValue($topic); + return ["chargepoint_{$id}" => ['evse_current' => floatval($value ?? 0)]]; + } catch (Exception $e) { + return ["chargepoint_{$id}" => ['evse_current' => 0]]; + } + } + + /** + * Chargepoint Power Factors (alle Phasen) + */ + private function getChargepointPowerFactors($id) + { + try { + $topic = "openWB/chargepoint/{$id}/get/power_factors"; + $value = $this->mqttClient->getValue($topic); + $powerFactors = json_decode($value ?? '[]', true) ?: [0, 0, 0]; + + return [ + "chargepoint_{$id}" => [ + 'power_factors' => [ + floatval($powerFactors[0] ?? 0), + floatval($powerFactors[1] ?? 0), + floatval($powerFactors[2] ?? 0) + ] + ] + ]; + } catch (Exception $e) { + return [ + "chargepoint_{$id}" => [ + 'power_factors' => [0, 0, 0] + ] + ]; + } + } + + /** + * Chargepoint Power Factor einzelne Phase + */ + private function getChargepointPowerFactor($id, $phase) + { + try { + $topic = "openWB/chargepoint/{$id}/get/power_factors"; + $value = $this->mqttClient->getValue($topic); + $powerFactors = json_decode($value ?? '[]', true) ?: [0, 0, 0]; + + return [ + "chargepoint_{$id}" => [ + "power_factor_p{$phase}" => floatval($powerFactors[$phase - 1] ?? 0) + ] + ]; + } catch (Exception $e) { + return [ + "chargepoint_{$id}" => [ + "power_factor_p{$phase}" => 0 + ] + ]; + } + } + + /** + * Chargepoint Config Name + */ + private function getChargepointConfigName($id) + { + try { + $topic = "openWB/chargepoint/{$id}/config"; + $value = $this->mqttClient->getValue($topic); + $config = json_decode($value ?? '{}', true) ?: []; + + return ["chargepoint_{$id}" => ['config_name' => strval($config['name'] ?? '')]]; + } catch (Exception $e) { + return ["chargepoint_{$id}" => ['config_name' => '']]; + } + } + + /** + * Chargepoint Connected Vehicle Name + */ + private function getChargepointConnectedVehicleName($id) + { + try { + $topic = "openWB/chargepoint/{$id}/get/connected_vehicle/info"; + $value = $this->mqttClient->getValue($topic); + $info = json_decode($value ?? '{}', true) ?: []; + + return ["chargepoint_{$id}" => ['connected_vehicle_name' => strval($info['name'] ?? '')]]; + } catch (Exception $e) { + return ["chargepoint_{$id}" => ['connected_vehicle_name' => '']]; + } + } + + /** + * Chargepoint Charge Template Name + */ + private function getChargepointChargeTemplateName($id) + { + try { + $topic = "openWB/chargepoint/{$id}/set/charge_template"; + $value = $this->mqttClient->getValue($topic); + $template = json_decode($value ?? '{}', true) ?: []; + + return ["chargepoint_{$id}" => ['charge_template_name' => strval($template['name'] ?? '')]]; + } catch (Exception $e) { + return ["chargepoint_{$id}" => ['charge_template_name' => '']]; + } + } + + /** + * Chargepoint Charge Template Min Current + */ + private function getChargepointChargeTemplateMinCurrent($id) + { + try { + $topic = "openWB/chargepoint/{$id}/set/charge_template"; + $value = $this->mqttClient->getValue($topic); + $template = json_decode($value ?? '{}', true) ?: []; + + $minCurrent = 0; + if (isset($template['chargemode']['pv_charging']['min_current'])) { + $minCurrent = $template['chargemode']['pv_charging']['min_current']; + } + + return ["chargepoint_{$id}" => ['charge_template_min_current' => floatval($minCurrent)]]; + } catch (Exception $e) { + return ["chargepoint_{$id}" => ['charge_template_min_current' => 0]]; + } + } + + /** + * Chargepoint Imported + */ + private function getChargepointImported($id) + { + try { + $topic = "openWB/chargepoint/{$id}/get/imported"; + $value = $this->mqttClient->getValue($topic); + return ["chargepoint_{$id}" => ['imported' => floatval($value ?? 0)]]; + } catch (Exception $e) { + return ["chargepoint_{$id}" => ['imported' => 0]]; + } + } + + /** + * Chargepoint Exported + */ + private function getChargepointExported($id) + { + try { + $topic = "openWB/chargepoint/{$id}/get/exported"; + $value = $this->mqttClient->getValue($topic); + return ["chargepoint_{$id}" => ['exported' => floatval($value ?? 0)]]; + } catch (Exception $e) { + return ["chargepoint_{$id}" => ['exported' => 0]]; + } + } + + /** + * Chargepoint SoC + */ + private function getChargepointSoc($id) + { + try { + $topic = "openWB/chargepoint/{$id}/get/soc"; + $value = $this->mqttClient->getValue($topic); + return ["chargepoint_{$id}" => ['soc' => intval($value ?? 0)]]; + } catch (Exception $e) { + return ["chargepoint_{$id}" => ['soc' => 0]]; + } + } + + /** + * Chargepoint State String + */ + private function getChargepointStateStr($id) + { + try { + $topic = "openWB/chargepoint/{$id}/get/state_str"; + $value = $this->mqttClient->getValue($topic); + return ["chargepoint_{$id}" => ['state_str' => strval($value ?? '')]]; + } catch (Exception $e) { + return ["chargepoint_{$id}" => ['state_str' => '']]; + } + } + + /** + * Chargepoint Fault String + */ + private function getChargepointFaultStr($id) + { + try { + $topic = "openWB/chargepoint/{$id}/get/fault_str"; + $value = $this->mqttClient->getValue($topic); + return ["chargepoint_{$id}" => ['fault_str' => strval($value ?? '')]]; + } catch (Exception $e) { + return ["chargepoint_{$id}" => ['fault_str' => '']]; + } + } + + /** + * Chargepoint Fault State + */ + private function getChargepointFaultState($id) + { + try { + $topic = "openWB/chargepoint/{$id}/get/fault_state"; + $value = $this->mqttClient->getValue($topic); + return ["chargepoint_{$id}" => ['fault_state' => intval($value ?? 0)]]; + } catch (Exception $e) { + return ["chargepoint_{$id}" => ['fault_state' => 0]]; + } + } + + /** + * Chargepoint Phases in Use + */ + private function getChargepointPhasesInUse($id) + { + try { + $topic = "openWB/chargepoint/{$id}/get/phases_in_use"; + $value = $this->mqttClient->getValue($topic); + return ["chargepoint_{$id}" => ['phases_in_use' => intval($value ?? 0)]]; + } catch (Exception $e) { + return ["chargepoint_{$id}" => ['phases_in_use' => 0]]; + } + } + + /** + * Chargepoint Plug State + */ + private function getChargepointPlugState($id) + { + try { + $topic = "openWB/chargepoint/{$id}/get/plug_state"; + $value = $this->mqttClient->getValue($topic); + return ["chargepoint_{$id}" => ['plug_state' => boolval($value ?? false)]]; + } catch (Exception $e) { + return ["chargepoint_{$id}" => ['plug_state' => false]]; + } + } + + /** + * Chargepoint Charge State + */ + private function getChargepointChargeState($id) + { + try { + $topic = "openWB/chargepoint/{$id}/get/charge_state"; + $value = $this->mqttClient->getValue($topic); + return ["chargepoint_{$id}" => ['charge_state' => boolval($value ?? false)]]; + } catch (Exception $e) { + return ["chargepoint_{$id}" => ['charge_state' => false]]; + } + } + + /** + * Chargepoint Chargemode + */ + private function getChargepointChargemode($id) + { + try { + $topic = "openWB/chargepoint/{$id}/get/chargemode"; + $value = $this->mqttClient->getValue($topic); + return ["chargepoint_{$id}" => ['chargemode' => strval($value ?? '')]]; + } catch (Exception $e) { + return ["chargepoint_{$id}" => ['chargemode' => '']]; + } + } + /** * Batterie-Modus setzen */ From 594e55a30c4a87f6af258fc826cca107af51535f Mon Sep 17 00:00:00 2001 From: KevinWieland Date: Thu, 13 Nov 2025 23:43:00 +0100 Subject: [PATCH 2/4] simpleAPI add write functions --- simpleAPI/simpleapi.php | 24 +- simpleAPI/src/ParameterHandler.php | 342 +++++++++++++++++++++++++++++ 2 files changed, 364 insertions(+), 2 deletions(-) diff --git a/simpleAPI/simpleapi.php b/simpleAPI/simpleapi.php index a71b24dda8..f340beaea3 100644 --- a/simpleAPI/simpleapi.php +++ b/simpleAPI/simpleapi.php @@ -161,7 +161,12 @@ private function getWriteParameters($params) 'minimal_permanent_current', 'max_price_eco', 'chargepoint_lock', - 'bat_mode' + 'bat_mode', + 'instant_charging_limit', + 'instant_charging_amount', + 'instant_charging_soc', + 'vehicle', + 'manual_soc' ]; foreach ($writeableKeys as $key) { @@ -433,7 +438,12 @@ private function isChargepointParameter($param) 'minimal_permanent_current', 'max_price_eco', 'chargepoint_lock', - 'bat_mode' + 'bat_mode', + 'instant_charging_limit', + 'instant_charging_amount', + 'instant_charging_soc', + 'vehicle', + 'manual_soc' ]; return in_array($param, $chargepointParameters) || strpos($param, 'chargepoint') !== false; @@ -449,6 +459,16 @@ private function getSuccessMessage($param, $value, $chargepointId) return "Chargemode for chargepoint {$chargepointId} set to {$value}."; case 'chargecurrent': return "Chargecurrent for chargepoint {$chargepointId} set to {$value}A"; + case 'instant_charging_limit': + return "Instant charging limit for chargepoint {$chargepointId} set to {$value}."; + case 'instant_charging_amount': + return "Instant charging amount for chargepoint {$chargepointId} set to {$value}kWh."; + case 'instant_charging_soc': + return "Instant charging SoC for chargepoint {$chargepointId} set to {$value}%."; + case 'vehicle': + return "Vehicle {$value} assigned to chargepoint {$chargepointId}."; + case 'manual_soc': + return "Manual SoC set to {$value}% for chargepoint {$chargepointId}."; default: return "Parameter {$param} set to {$value}."; } diff --git a/simpleAPI/src/ParameterHandler.php b/simpleAPI/src/ParameterHandler.php index f44516e41a..6245a2f707 100644 --- a/simpleAPI/src/ParameterHandler.php +++ b/simpleAPI/src/ParameterHandler.php @@ -222,6 +222,16 @@ public function writeParameter($param, $value, $chargepointId = null) return $this->setChargepointLock($chargepointId, $value); case 'bat_mode': return $this->setBatMode($value); + case 'instant_charging_limit': + return $this->setInstantChargingLimit($chargepointId, $value); + case 'instant_charging_amount': + return $this->setInstantChargingAmount($chargepointId, $value); + case 'instant_charging_soc': + return $this->setInstantChargingSoc($chargepointId, $value); + case 'vehicle': + return $this->setVehicle($chargepointId, $value); + case 'manual_soc': + return $this->setManualSoc($chargepointId, $value); default: return ['success' => false, 'message' => 'Unknown write parameter']; } @@ -1180,6 +1190,338 @@ private function getChargepointChargemode($id) } } + /** + * Instant Charging Limit setzen + */ + private function setInstantChargingLimit($chargepointId, $value) + { + $validLimits = ['none', 'amount', 'soc']; + + if (!in_array($value, $validLimits)) { + return ['success' => false, 'message' => 'Invalid instant_charging_limit. Valid values: ' . implode(', ', $validLimits)]; + } + + try { + $templateTopic = "openWB/chargepoint/{$chargepointId}/set/charge_template"; + $templateJson = $this->mqttClient->getValue($templateTopic); + if (!$templateJson) { + return ['success' => false, 'message' => 'Could not read current charge template']; + } + + $template = json_decode($templateJson, true); + if (!$template || !isset($template['chargemode']['instant_charging'])) { + return ['success' => false, 'message' => 'Invalid charge template format or missing instant_charging']; + } + + $template['chargemode']['instant_charging']['limit']['selected'] = $value; + $setTopic = "openWB/set/chargepoint/{$chargepointId}/set/charge_template"; + $newTemplateJson = json_encode($template); + + if ($this->mqttClient->setValue($setTopic, $newTemplateJson)) { + return ['success' => true, 'message' => "Instant charging limit set to {$value} for chargepoint {$chargepointId}"]; + } + return ['success' => false, 'message' => 'Failed to update charge template']; + } catch (Exception $e) { + return ['success' => false, 'message' => 'Error setting instant charging limit: ' . $e->getMessage()]; + } + } + + /** + * Instant Charging Amount setzen (kWh -> Wh) + */ + private function setInstantChargingAmount($chargepointId, $value) + { + $amount = floatval($value); + if ($amount < 0) { + return ['success' => false, 'message' => 'Amount must be >= 0']; + } + + // kWh zu Wh konvertieren + $amountWh = intval($amount * 1000); + + try { + $templateTopic = "openWB/chargepoint/{$chargepointId}/set/charge_template"; + $templateJson = $this->mqttClient->getValue($templateTopic); + if (!$templateJson) { + return ['success' => false, 'message' => 'Could not read current charge template']; + } + + $template = json_decode($templateJson, true); + if (!$template || !isset($template['chargemode']['instant_charging'])) { + return ['success' => false, 'message' => 'Invalid charge template format or missing instant_charging']; + } + + $template['chargemode']['instant_charging']['limit']['amount'] = $amountWh; + $setTopic = "openWB/set/chargepoint/{$chargepointId}/set/charge_template"; + $newTemplateJson = json_encode($template); + + if ($this->mqttClient->setValue($setTopic, $newTemplateJson)) { + return ['success' => true, 'message' => "Instant charging amount set to {$value}kWh ({$amountWh}Wh) for chargepoint {$chargepointId}"]; + } + return ['success' => false, 'message' => 'Failed to update charge template']; + } catch (Exception $e) { + return ['success' => false, 'message' => 'Error setting instant charging amount: ' . $e->getMessage()]; + } + } + + /** + * Instant Charging SoC setzen + */ + private function setInstantChargingSoc($chargepointId, $value) + { + $soc = intval($value); + if ($soc < 0 || $soc > 100) { + return ['success' => false, 'message' => 'SoC must be between 0 and 100']; + } + + try { + $templateTopic = "openWB/chargepoint/{$chargepointId}/set/charge_template"; + $templateJson = $this->mqttClient->getValue($templateTopic); + if (!$templateJson) { + return ['success' => false, 'message' => 'Could not read current charge template']; + } + + $template = json_decode($templateJson, true); + if (!$template || !isset($template['chargemode']['instant_charging'])) { + return ['success' => false, 'message' => 'Invalid charge template format or missing instant_charging']; + } + + $template['chargemode']['instant_charging']['limit']['soc'] = $soc; + $setTopic = "openWB/set/chargepoint/{$chargepointId}/set/charge_template"; + $newTemplateJson = json_encode($template); + + if ($this->mqttClient->setValue($setTopic, $newTemplateJson)) { + return ['success' => true, 'message' => "Instant charging SoC set to {$soc}% for chargepoint {$chargepointId}"]; + } + return ['success' => false, 'message' => 'Failed to update charge template']; + } catch (Exception $e) { + return ['success' => false, 'message' => 'Error setting instant charging SoC: ' . $e->getMessage()]; + } + } + + /** + * Fahrzeug für Chargepoint setzen + */ + private function setVehicle($chargepointId, $value) + { + $vehicleId = intval($value); + if ($vehicleId < 0) { + return ['success' => false, 'message' => 'Vehicle ID must be >= 0']; + } + + try { + $topic = "openWB/set/chargepoint/{$chargepointId}/config/ev"; + + if ($this->mqttClient->setValue($topic, strval($vehicleId))) { + return ['success' => true, 'message' => "Vehicle {$vehicleId} assigned to chargepoint {$chargepointId}"]; + } + return ['success' => false, 'message' => 'Failed to set vehicle']; + } catch (Exception $e) { + return ['success' => false, 'message' => 'Error setting vehicle: ' . $e->getMessage()]; + } + } + + /** + * Manuellen SoC für Fahrzeug setzen + */ + private function setManualSoc($chargepointId, $value) + { + $soc = intval($value); + if ($soc < 0 || $soc > 100) { + return ['success' => false, 'message' => 'Manual SoC must be between 0 and 100']; + } + + try { + // Erst die Fahrzeug-ID vom Chargepoint ermitteln + $configTopic = "openWB/chargepoint/{$chargepointId}/config"; + $configJson = $this->mqttClient->getValue($configTopic); + if (!$configJson) { + return ['success' => false, 'message' => 'Could not read chargepoint config']; + } + + $config = json_decode($configJson, true); + if (!$config || !isset($config['ev'])) { + return ['success' => false, 'message' => 'No vehicle assigned to chargepoint']; + } + + $vehicleId = $config['ev']; + $topic = "openWB/set/vehicle/{$vehicleId}/soc_module/calculated_soc_state/manual_soc"; + + if ($this->mqttClient->setValue($topic, strval($soc))) { + return ['success' => true, 'message' => "Manual SoC set to {$soc}% for vehicle {$vehicleId} (chargepoint {$chargepointId})"]; + } + return ['success' => false, 'message' => 'Failed to set manual SoC']; + } catch (Exception $e) { + return ['success' => false, 'message' => 'Error setting manual SoC: ' . $e->getMessage()]; + } + } + + /** + * Instant Charging Limit setzen + */ + private function setInstantChargingLimit($chargepointId, $value) + { + $validLimits = ['none', 'amount', 'soc']; + + if (!in_array($value, $validLimits)) { + return ['success' => false, 'message' => 'Invalid instant_charging_limit. Valid values: ' . implode(', ', $validLimits)]; + } + + try { + $templateTopic = "openWB/chargepoint/{$chargepointId}/set/charge_template"; + $templateJson = $this->mqttClient->getValue($templateTopic); + if (!$templateJson) { + return ['success' => false, 'message' => 'Could not read current charge template']; + } + + $template = json_decode($templateJson, true); + if (!$template || !isset($template['chargemode']['instant_charging'])) { + return ['success' => false, 'message' => 'Invalid charge template format or missing instant_charging']; + } + + $template['chargemode']['instant_charging']['limit']['selected'] = $value; + $setTopic = "openWB/set/chargepoint/{$chargepointId}/set/charge_template"; + $newTemplateJson = json_encode($template); + + if ($this->mqttClient->setValue($setTopic, $newTemplateJson)) { + return ['success' => true, 'message' => "Instant charging limit set to {$value} for chargepoint {$chargepointId}"]; + } + return ['success' => false, 'message' => 'Failed to update charge template']; + } catch (Exception $e) { + return ['success' => false, 'message' => 'Error setting instant charging limit: ' . $e->getMessage()]; + } + } + + /** + * Instant Charging Amount setzen (kWh -> Wh) + */ + private function setInstantChargingAmount($chargepointId, $value) + { + $amount = floatval($value); + if ($amount < 0) { + return ['success' => false, 'message' => 'Amount must be >= 0']; + } + + // kWh zu Wh konvertieren + $amountWh = intval($amount * 1000); + + try { + $templateTopic = "openWB/chargepoint/{$chargepointId}/set/charge_template"; + $templateJson = $this->mqttClient->getValue($templateTopic); + if (!$templateJson) { + return ['success' => false, 'message' => 'Could not read current charge template']; + } + + $template = json_decode($templateJson, true); + if (!$template || !isset($template['chargemode']['instant_charging'])) { + return ['success' => false, 'message' => 'Invalid charge template format or missing instant_charging']; + } + + $template['chargemode']['instant_charging']['limit']['amount'] = $amountWh; + $setTopic = "openWB/set/chargepoint/{$chargepointId}/set/charge_template"; + $newTemplateJson = json_encode($template); + + if ($this->mqttClient->setValue($setTopic, $newTemplateJson)) { + return ['success' => true, 'message' => "Instant charging amount set to {$value}kWh ({$amountWh}Wh) for chargepoint {$chargepointId}"]; + } + return ['success' => false, 'message' => 'Failed to update charge template']; + } catch (Exception $e) { + return ['success' => false, 'message' => 'Error setting instant charging amount: ' . $e->getMessage()]; + } + } + + /** + * Instant Charging SoC setzen + */ + private function setInstantChargingSoc($chargepointId, $value) + { + $soc = intval($value); + if ($soc < 0 || $soc > 100) { + return ['success' => false, 'message' => 'SoC must be between 0 and 100']; + } + + try { + $templateTopic = "openWB/chargepoint/{$chargepointId}/set/charge_template"; + $templateJson = $this->mqttClient->getValue($templateTopic); + if (!$templateJson) { + return ['success' => false, 'message' => 'Could not read current charge template']; + } + + $template = json_decode($templateJson, true); + if (!$template || !isset($template['chargemode']['instant_charging'])) { + return ['success' => false, 'message' => 'Invalid charge template format or missing instant_charging']; + } + + $template['chargemode']['instant_charging']['limit']['soc'] = $soc; + $setTopic = "openWB/set/chargepoint/{$chargepointId}/set/charge_template"; + $newTemplateJson = json_encode($template); + + if ($this->mqttClient->setValue($setTopic, $newTemplateJson)) { + return ['success' => true, 'message' => "Instant charging SoC set to {$soc}% for chargepoint {$chargepointId}"]; + } + return ['success' => false, 'message' => 'Failed to update charge template']; + } catch (Exception $e) { + return ['success' => false, 'message' => 'Error setting instant charging SoC: ' . $e->getMessage()]; + } + } + + /** + * Fahrzeug für Chargepoint setzen + */ + private function setVehicle($chargepointId, $value) + { + $vehicleId = intval($value); + if ($vehicleId < 0) { + return ['success' => false, 'message' => 'Vehicle ID must be >= 0']; + } + + try { + $topic = "openWB/set/chargepoint/{$chargepointId}/config/ev"; + + if ($this->mqttClient->setValue($topic, strval($vehicleId))) { + return ['success' => true, 'message' => "Vehicle {$vehicleId} assigned to chargepoint {$chargepointId}"]; + } + return ['success' => false, 'message' => 'Failed to set vehicle']; + } catch (Exception $e) { + return ['success' => false, 'message' => 'Error setting vehicle: ' . $e->getMessage()]; + } + } + + /** + * Manuellen SoC für Fahrzeug setzen + */ + private function setManualSoc($chargepointId, $value) + { + $soc = intval($value); + if ($soc < 0 || $soc > 100) { + return ['success' => false, 'message' => 'Manual SoC must be between 0 and 100']; + } + + try { + // Erst die Fahrzeug-ID vom Chargepoint ermitteln + $configTopic = "openWB/chargepoint/{$chargepointId}/config"; + $configJson = $this->mqttClient->getValue($configTopic); + if (!$configJson) { + return ['success' => false, 'message' => 'Could not read chargepoint config']; + } + + $config = json_decode($configJson, true); + if (!$config || !isset($config['ev'])) { + return ['success' => false, 'message' => 'No vehicle assigned to chargepoint']; + } + + $vehicleId = $config['ev']; + $topic = "openWB/set/vehicle/{$vehicleId}/soc_module/calculated_soc_state/manual_soc"; + + if ($this->mqttClient->setValue($topic, strval($soc))) { + return ['success' => true, 'message' => "Manual SoC set to {$soc}% for vehicle {$vehicleId} (chargepoint {$chargepointId})"]; + } + return ['success' => false, 'message' => 'Failed to set manual SoC']; + } catch (Exception $e) { + return ['success' => false, 'message' => 'Error setting manual SoC: ' . $e->getMessage()]; + } + } + /** * Batterie-Modus setzen */ From 9ef13b09ac2d24f98dc4a89c1696d8bdfe7e9890 Mon Sep 17 00:00:00 2001 From: KevinWieland Date: Thu, 13 Nov 2025 23:55:51 +0100 Subject: [PATCH 3/4] neuer parameter --- simpleAPI/simpleapi.php | 1 + simpleAPI/src/ParameterHandler.php | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/simpleAPI/simpleapi.php b/simpleAPI/simpleapi.php index f340beaea3..352c59fb5d 100644 --- a/simpleAPI/simpleapi.php +++ b/simpleAPI/simpleapi.php @@ -217,6 +217,7 @@ private function getReadParameters($params) 'get_chargepoint_connected_vehicle_name', 'get_chargepoint_charge_template_name', 'get_chargepoint_charge_template_min_current', + 'get_chargepoint_instant_charging_current', 'get_chargepoint_soc', 'get_chargepoint_state_str', 'get_chargepoint_fault_str', diff --git a/simpleAPI/src/ParameterHandler.php b/simpleAPI/src/ParameterHandler.php index 6245a2f707..96d83811b5 100644 --- a/simpleAPI/src/ParameterHandler.php +++ b/simpleAPI/src/ParameterHandler.php @@ -97,6 +97,8 @@ public function readParameter($param, $id) return $this->getChargepointChargeTemplateName($id); case 'get_chargepoint_charge_template_min_current': return $this->getChargepointChargeTemplateMinCurrent($id); + case 'get_chargepoint_instant_charging_current': + return $this->getChargepointInstantChargingCurrent($id); case 'get_chargepoint_soc': return $this->getChargepointSoc($id); case 'get_chargepoint_state_str': @@ -1050,6 +1052,27 @@ private function getChargepointChargeTemplateMinCurrent($id) } } + /** + * Chargepoint Instant Charging Current + */ + private function getChargepointInstantChargingCurrent($id) + { + try { + $topic = "openWB/chargepoint/{$id}/set/charge_template"; + $value = $this->mqttClient->getValue($topic); + $template = json_decode($value ?? '{}', true) ?: []; + + $instantCurrent = 0; + if (isset($template['chargemode']['instant_charging']['current'])) { + $instantCurrent = $template['chargemode']['instant_charging']['current']; + } + + return ["chargepoint_{$id}" => ['instant_charging_current' => floatval($instantCurrent)]]; + } catch (Exception $e) { + return ["chargepoint_{$id}" => ['instant_charging_current' => 0]]; + } + } + /** * Chargepoint Imported */ From 19084c762a41b83d5ecefdca9fb5b1cba36797b4 Mon Sep 17 00:00:00 2001 From: KevinWieland Date: Thu, 13 Nov 2025 23:59:49 +0100 Subject: [PATCH 4/4] neuer parameter --- simpleAPI/simpleapi.php | 1 + simpleAPI/src/ParameterHandler.php | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/simpleAPI/simpleapi.php b/simpleAPI/simpleapi.php index 352c59fb5d..da79a3c2ae 100644 --- a/simpleAPI/simpleapi.php +++ b/simpleAPI/simpleapi.php @@ -218,6 +218,7 @@ private function getReadParameters($params) 'get_chargepoint_charge_template_name', 'get_chargepoint_charge_template_min_current', 'get_chargepoint_instant_charging_current', + 'get_chargepoint_pv_charging_min_current', 'get_chargepoint_soc', 'get_chargepoint_state_str', 'get_chargepoint_fault_str', diff --git a/simpleAPI/src/ParameterHandler.php b/simpleAPI/src/ParameterHandler.php index 96d83811b5..d60228e0cb 100644 --- a/simpleAPI/src/ParameterHandler.php +++ b/simpleAPI/src/ParameterHandler.php @@ -99,6 +99,8 @@ public function readParameter($param, $id) return $this->getChargepointChargeTemplateMinCurrent($id); case 'get_chargepoint_instant_charging_current': return $this->getChargepointInstantChargingCurrent($id); + case 'get_chargepoint_pv_charging_min_current': + return $this->getChargepointPvChargingMinCurrent($id); case 'get_chargepoint_soc': return $this->getChargepointSoc($id); case 'get_chargepoint_state_str': @@ -1073,6 +1075,27 @@ private function getChargepointInstantChargingCurrent($id) } } + /** + * Chargepoint PV Charging Min Current + */ + private function getChargepointPvChargingMinCurrent($id) + { + try { + $topic = "openWB/chargepoint/{$id}/set/charge_template"; + $value = $this->mqttClient->getValue($topic); + $template = json_decode($value ?? '{}', true) ?: []; + + $pvMinCurrent = 0; + if (isset($template['chargemode']['pv_charging']['min_current'])) { + $pvMinCurrent = $template['chargemode']['pv_charging']['min_current']; + } + + return ["chargepoint_{$id}" => ['pv_charging_min_current' => floatval($pvMinCurrent)]]; + } catch (Exception $e) { + return ["chargepoint_{$id}" => ['pv_charging_min_current' => 0]]; + } + } + /** * Chargepoint Imported */