Skip to content

Panic (Crash): json: unsupported value: NaN when API returns invalid solar forecast data #28490

@MatzeBu

Description

@MatzeBu

Describe the bug

evcc crashes entirely (throws a panic) when an external solar forecast service (in this case api.akkudoktor.net) seemingly returns an invalid value.
Instead of gracefully ignoring the bad data or issuing a warning, evcc produces a NaN value internally, which then causes a fatal crash when socketEncode tries to marshal the data into JSON for the Web UI or MQTT.
This results in a continuous boot-loop.

Starting evcc without an internet connection (so the API request fails cleanly with connection refused instead of receiving a bad payload) allows evcc to start and run normally.

Steps to reproduce

Configure api.akkudoktor.net as a solar forecast template in evcc.yaml (see config below).

Start evcc.

If the Akkudoktor API currently returns empty/invalid data, evcc will crash immediately after the solar forecast: accumulated... debug log.

Expected behavior:
evcc should catch invalid data (like empty strings or formatting errors from external APIs) and handle them gracefully (e.g., fallback to 0 or simply ignore the forecast for that cycle) instead of crashing with a panic.

Log (evcc 0.303.2):

Configuration details

solar:
  type: template
  template: api.akkudoktor.net
  lat: 50.67
  lon: 12.68
  dec: 5 
  kwp: 9.2 
  az: -101
  horizon: "5,5,5,5,10,10,22,22,32,32,10,15,15,18,22t0.3,25t0.3,25t0.3,25t0.4,20t0.4,20t0.4,32t0.2,35t0.1,30t0.1,28t0.1,25t0.1,20t0.1,20,20,20,20,10,10,5,5,5,5"

Log details

[site  ] DEBUG 2026/03/23 11:58:53 solar forecast: accumulated 4.543Wh from 0001-01-01 00:00:00 +0000 UTC to 2026-03-23 11:58:53 +0100 CET
[site  ] DEBUG 2026/03/23 11:58:53 solar forecast: produced 570.000
[site  ] DEBUG 2026/03/23 11:58:53 solar forecast: accumulated 566.195kWh, produced 570.000kWh, scale 1.007
[lp-1  ] DEBUG 2026/03/23 11:58:53 set smart cost limit: 0.1
[lp-1  ] DEBUG 2026/03/23 11:58:53 set battery boost limit: 15
[lp-1  ] DEBUG 2026/03/23 11:58:53 phase timer inactive
[lp-1  ] DEBUG 2026/03/23 11:58:53 pv timer inactive
[lp-1  ] DEBUG 2026/03/23 11:58:53 set charge current limit: 6A
[lp-2  ] DEBUG 2026/03/23 11:58:53 set smart cost limit: 0.1
[lp-2  ] DEBUG 2026/03/23 11:58:53 set battery boost limit: 75
[mqtt  ] ERROR 2026/03/23 11:58:53 marshal bytes: json: unsupported value: NaN
[lp-2  ] DEBUG 2026/03/23 11:58:53 phase timer inactive
[lp-2  ] DEBUG 2026/03/23 11:58:53 pv timer inactive
[lp-2  ] INFO 2026/03/23 11:58:53 vehicle updated: unknown -> Cupra Born
panic: json: unsupported value: NaN

goroutine 86 [running]:
github.com/evcc-io/evcc/server.socketEncode({0x1f5c940?, 0x7f77766b40?})
	github.com/evcc-io/evcc/server/socket_helper.go:47 +0xbc
github.com/evcc-io/evcc/server.(*SocketHub).broadcast-range1({0x1ecd007, 0x5}, {0x1f5c940?, 0x7f77766b40?})
	github.com/evcc-io/evcc/server/socket.go:167 +0x64

What type of operating system or environment does evcc run on?

HomeAssistant Add-on

External automation

  • I have made sure that no external automation like HomeAssistant or Node-RED is active or accessing any of the mentioned devices when this issue occurs.

Nightly build

  • I have verified that the issue is reproducible with the latest nightly build

Version

0.303.2

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions