Skip to content
Open
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
14 changes: 7 additions & 7 deletions evcc/evcc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading