Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion simpleAPI/simpleapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 23 additions & 0 deletions simpleAPI/src/ParameterHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
];
}
}