From 8432316afdee210f89eb9c8b2bdcc661b44f81f1 Mon Sep 17 00:00:00 2001 From: Bastian Date: Sat, 24 Oct 2026 15:35:21 +0200 Subject: [PATCH] fix(evcc): remove non-existent result wrapper from /api/state parsing The evcc /api/state endpoint returns a flat JSON object directly, not a {"result": {...}} wrapped payload. The previous code checked for $json->result which was always null, so pvPower and chargePower were never read and the tile permanently displayed 0.0 kW for both values. The API test still passed because it only checks the HTTP 200 status. Fix: read pvPower and loadpoints directly from $json, and guard on $json->apiReady === true (a field present in all evcc /api/state responses) instead of the absent result key. --- evcc/evcc.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/evcc/evcc.php b/evcc/evcc.php index f334974d47..25cb7abadb 100644 --- a/evcc/evcc.php +++ b/evcc/evcc.php @@ -32,22 +32,22 @@ public function livestats() $res = parent::execute($this->url('api/state'), $this->getAttrs()); if ($res !== null) { $json = json_decode($res->getBody()); - // The state payload is wrapped in a "result" object. Fields vary by - // configuration, so read each one defensively. - if ($json !== null && isset($json->result)) { - $result = $json->result; + // The evcc /api/state response is a flat JSON object - there is no + // "result" wrapper. Fields vary by configuration, so read each one + // defensively. + if ($json !== null && isset($json->apiReady) && $json->apiReady === true) { $status = 'active'; // pvPower is only present when a PV meter is configured (grid-only // setups omit it); default to 0 so the tile still renders. - $pvWatts = isset($result->pvPower) ? (float) $result->pvPower : 0.0; + $pvWatts = isset($json->pvPower) ? (float) $json->pvPower : 0.0; $data['pv'] = $this->formatKw($pvWatts); // Sum chargePower across all loadpoints - loadpoints is evcc's core // config and effectively always present. $chargeWatts = 0.0; - if (isset($result->loadpoints) && is_array($result->loadpoints)) { - foreach ($result->loadpoints as $lp) { + if (isset($json->loadpoints) && is_array($json->loadpoints)) { + foreach ($json->loadpoints as $lp) { if (isset($lp->chargePower)) { $chargeWatts += (float) $lp->chargePower; }