diff --git a/simpleAPI/simpleapi.php b/simpleAPI/simpleapi.php index da79a3c2ae..44002d3f01 100644 --- a/simpleAPI/simpleapi.php +++ b/simpleAPI/simpleapi.php @@ -276,7 +276,9 @@ private function getReadParameters($params) 'get_pv_monthly_exported', 'get_pv_yearly_exported', 'get_pv_fault_str', - 'get_pv_fault_state' + 'get_pv_fault_state', + // System - Werte + 'get_lastlivevaluesjson' ]; foreach ($readableKeys as $key) { @@ -485,9 +487,17 @@ private function formatRawOutput($data) $firstKey = array_keys($data)[0]; $firstValue = $data[$firstKey]; + // Für JSON-Strings: direkt den String-Wert zurückgeben + if (is_string($firstValue)) { + return $firstValue; + } + if (is_array($firstValue) && count($firstValue) === 1) { return array_values($firstValue)[0]; } + + // Für andere Array-Strukturen: ersten Wert zurückgeben + return $firstValue; } return $data; diff --git a/simpleAPI/src/ParameterHandler.php b/simpleAPI/src/ParameterHandler.php index 3fd1306bfd..f26e015d19 100644 --- a/simpleAPI/src/ParameterHandler.php +++ b/simpleAPI/src/ParameterHandler.php @@ -200,6 +200,9 @@ public function readParameter($param, $id) case 'get_pv_fault_state': return $this->getPvFaultState($id); + case 'get_lastlivevaluesjson': + return $this->getLastLiveValuesJson(); + default: return null; } @@ -1531,4 +1534,24 @@ private function setBatMode($value) return ['success' => false, 'message' => 'Error setting bat mode: ' . $e->getMessage()]; } } + + /** + * Lese openWB/system/lastlivevaluesJson Topic 1:1 aus + */ + private function getLastLiveValuesJson() + { + $topic = "openWB/graph/lastlivevaluesJson"; + $jsonValue = $this->mqttClient->getValue($topic); + + if ($jsonValue === null) { + return [ + 'get_lastlivevaluesjson' => null + ]; + } + + // JSON-String 1:1 zurückgeben + return [ + 'get_lastlivevaluesjson' => $jsonValue + ]; + } }