evcc icon indicating copy to clipboard operation
evcc copied to clipboard

enphase: API changed

Open jaykayone opened this issue 1 month ago • 9 comments

Describe the bug

Your enphase template uses the http protocol: templates/definition/meter/enphase.yaml

I have enphase working locally and it only works in https, http sends a "301 moved permanently" code.

Could you add a parameter to specify the protocol to use so that it stays does not break things for people on other versions of the API ?

Steps to reproduce

  1. Add enphase pv to config
  2. It tries to communicate with enphase via http instead of https
  3. jq gets empty results ...

Configuration details

meters:
  - name: my_pv
    type: template
    template: enphase
    usage: pv
    host: envoy.local 
    token: xxxx

Log details

May 07 19:56:25 raspberrypi evcc[7833]: [http  ] TRACE 2024/05/07 19:56:25 GET https://envoy.local/production.json
May 07 19:56:25 raspberrypi evcc[7833]: [http  ] TRACE 2024/05/07 19:56:25 {"production":[{"type":"inverters","activeCount":19,"readingTime":1715104599,"wNow":205,"whLifetime":461440}],"storage":[{"type":"acb","activeCount":0,"readingTime":0,"wNow":0,"whNow":0,"state":"idle"}]}
May 07 19:56:25 raspberrypi evcc[7833]: [http  ] TRACE 2024/05/07 19:56:25 GET http://envoy.local/production.json
May 07 19:56:25 raspberrypi evcc[7833]: [http  ] TRACE 2024/05/07 19:56:25 <html>
May 07 19:56:25 raspberrypi evcc[7833]: <head><title>301 Moved Permanently</title></head>
May 07 19:56:25 raspberrypi evcc[7833]: <body>
May 07 19:56:25 raspberrypi evcc[7833]: <center><h1>301 Moved Permanently</h1></center>
May 07 19:56:25 raspberrypi evcc[7833]: <hr><center>openresty/1.17.8.1</center>
May 07 19:56:25 raspberrypi evcc[7833]: </body>
May 07 19:56:25 raspberrypi evcc[7833]: </html>
May 07 19:56:25 raspberrypi evcc[7833]: [http  ] TRACE 2024/05/07 19:56:25 GET https://envoy.local/production.json
May 07 19:56:26 raspberrypi evcc[7833]: [http  ] TRACE 2024/05/07 19:56:26 {"production":[{"type":"inverters","activeCount":19,"readingTime":1715104599,"wNow":205,"whLifetime":461440}],"storage":[{"type":"acb","activeCount":0,"readingTime":0,"wNow":0,"whNow":0,"state":"idle"}]}

What type of operating system are you running?

Linux

Version

v0.126.2

jaykayone avatar May 07 '24 08:05 jaykayone

Missing log of actual problem. Should not be necessary if Enphase sends a redirect header.

andig avatar May 07 '24 09:05 andig

Yes it follows the redirect according to the trace.

but there is now data shown as you seen in the log, whNow is 205 but the ui shows no data and the log in the UI says: pv 1 power: jq: empty result

jaykayone avatar May 07 '24 18:05 jaykayone

Please run with --log-trace

andig avatar May 07 '24 18:05 andig

i added the log in trace mode in the description

jaykayone avatar May 07 '24 18:05 jaykayone

Sorry, I meant:

Please run with --log-headers

andig avatar May 07 '24 18:05 andig

pi@raspberrypi:~ $ evcc meter --log-headers
[main  ] INFO 2024/05/07 21:25:20 evcc 0.126.2
[main  ] INFO 2024/05/07 21:25:20 using config file: /etc/evcc.yaml
[db    ] INFO 2024/05/07 21:25:20 using sqlite database: /home/pi/.evcc/evcc.db
[db    ] TRACE 2024/05/07 21:25:20 SELECT count(*) FROM sqlite_master WHERE type='table' AND name="settings" -1 <nil>
[db    ] TRACE 2024/05/07 21:25:20 SELECT sql FROM sqlite_master WHERE type IN ("table","index") AND tbl_name = "settings" AND sql IS NOT NULL order by type = "table" desc 1 <nil>
[db    ] TRACE 2024/05/07 21:25:20 SELECT * FROM `settings` LIMIT 1 -1 <nil>
[db    ] TRACE 2024/05/07 21:25:20 SELECT * FROM `settings` 1 <nil>
[db    ] TRACE 2024/05/07 21:25:20 SELECT count(*) FROM sqlite_master WHERE type='table' AND name="devices" -1 <nil>
[db    ] TRACE 2024/05/07 21:25:20 SELECT count(*) FROM sqlite_master WHERE type='table' AND name="device_details" -1 <nil>
[db    ] TRACE 2024/05/07 21:25:20 SELECT count(*) FROM sqlite_master WHERE type='table' AND name="configs" -1 <nil>
[db    ] TRACE 2024/05/07 21:25:20 SELECT sql FROM sqlite_master WHERE type IN ("table","index") AND tbl_name = "configs" AND sql IS NOT NULL order by type = "table" desc 1 <nil>
[db    ] TRACE 2024/05/07 21:25:20 SELECT * FROM `configs` LIMIT 1 -1 <nil>
[db    ] TRACE 2024/05/07 21:25:20 SELECT count(*) FROM sqlite_master WHERE type='table' AND name="config_details" -1 <nil>
[db    ] TRACE 2024/05/07 21:25:20 SELECT sql FROM sqlite_master WHERE type IN ("table","index") AND tbl_name = "config_details" AND sql IS NOT NULL order by type = "table" desc 2 <nil>
[db    ] TRACE 2024/05/07 21:25:20 SELECT * FROM `config_details` LIMIT 1 -1 <nil>
[db    ] TRACE 2024/05/07 21:25:20 SELECT count(*) FROM sqlite_master WHERE type = "table" AND tbl_name = "config_details" AND (sql LIKE "%CONSTRAINT ""fk_configs_details"" %" OR sql LIKE "%CONSTRAINT fk_configs_details %" OR sql LIKE "%CONSTRAINT `fk_configs_details`%" OR sql LIKE "%CONSTRAINT [fk_configs_details]%" OR sql LIKE "%CONSTRAINT 	fk_configs_details	%") -1 <nil>
[db    ] TRACE 2024/05/07 21:25:20 SELECT count(*) FROM sqlite_master WHERE type = "index" AND tbl_name = "config_details" AND name = "idx_unique" -1 <nil>
[db    ] TRACE 2024/05/07 21:25:20 SELECT count(*) FROM sqlite_master WHERE type = "table" AND tbl_name = "config_details" AND (sql LIKE "%CONSTRAINT ""fk_devices_details"" %" OR sql LIKE "%CONSTRAINT fk_devices_details %" OR sql LIKE "%CONSTRAINT `fk_devices_details`%" OR sql LIKE "%CONSTRAINT [fk_devices_details]%" OR sql LIKE "%CONSTRAINT 	fk_devices_details	%") -1 <nil>
[db    ] TRACE 2024/05/07 21:25:20 SELECT count(*) FROM sqlite_master WHERE type = "table" AND tbl_name = "config_details" AND (sql LIKE "%""device_id"" %" OR sql LIKE "%device_id %" OR sql LIKE "%`device_id`%" OR sql LIKE "%[device_id]%" OR sql LIKE "%	device_id	%") -1 <nil>
[db    ] TRACE 2024/05/07 21:25:20 SELECT * FROM `configs` WHERE `configs`.`class` = 2 ORDER BY id 0 <nil>
[http  ] TRACE 2024/05/07 21:25:20 GET http://envoy.local/production.json
[http  ] TRACE 2024/05/07 21:25:21 
GET /production.json HTTP/1.1
Host: envoy.local
User-Agent: Go-http-client/1.1
Authorization: Bearer xxx Accept-Encoding: gzip

HTTP/1.1 301 Moved Permanently
Content-Length: 175
Connection: keep-alive
Content-Type: text/html
Date: Tue, 07 May 2024 19:25:47 GMT
Location: https://envoy.local/production.json
Server: openresty/1.17.8.1

<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>openresty/1.17.8.1</center>
</body>
</html>
[http  ] TRACE 2024/05/07 21:25:21 GET https://envoy.local/production.json
[http  ] TRACE 2024/05/07 21:25:23 
GET /production.json HTTP/1.1
Host: envoy.local
User-Agent: Go-http-client/1.1
Authorization: Bearer xxx
Referer: http://envoy.local/production.json
Accept-Encoding: gzip

HTTP/1.1 200 OK
Transfer-Encoding: chunked
Cache-Control: no-cache
Connection: keep-alive
Content-Type: application/json
Date: Tue, 07 May 2024 19:25:49 GMT
Expires: 1
Pragma: no-cache
Server: openresty/1.17.8.1
Set-Cookie: sessionId=TAO9egg7mmJjtB7uzTnKbEkmWOzZc0pc; Secure; HttpOnly; path=/
Strict-Transport-Security: max-age=63072000; includeSubdomains
X-Content-Type-Options: nosniff
X-Frame-Options: DENY

c9
{"production":[{"type":"inverters","activeCount":19,"readingTime":1715108566,"wNow":2,"whLifetime":461493}],"storage":[{"type":"acb","activeCount":0,"readingTime":0,"wNow":0,"whNow":0,"state":"idle"}]}
0
[http  ] TRACE 2024/05/07 21:25:23 GET http://envoy.local/production.json
[http  ] TRACE 2024/05/07 21:25:23 
GET /production.json HTTP/1.1
Host: envoy.local
User-Agent: Go-http-client/1.1
Authorization: Bearer xxx
Accept-Encoding: gzip

HTTP/1.1 301 Moved Permanently
Content-Length: 175
Connection: keep-alive
Content-Type: text/html
Date: Tue, 07 May 2024 19:25:49 GMT
Location: https://envoy.local/production.json
Server: openresty/1.17.8.1

<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>openresty/1.17.8.1</center>
</body>
</html>
[http  ] TRACE 2024/05/07 21:25:23 GET https://envoy.local/production.json
[http  ] TRACE 2024/05/07 21:25:26 
GET /production.json HTTP/1.1
Host: envoy.local
User-Agent: Go-http-client/1.1
Authorization: Bearer xxx
Referer: http://envoy.local/production.json
Accept-Encoding: gzip

HTTP/1.1 200 OK
Transfer-Encoding: chunked
Cache-Control: no-cache
Connection: keep-alive
Content-Type: application/json
Date: Tue, 07 May 2024 19:25:52 GMT
Expires: 1
Pragma: no-cache
Server: openresty/1.17.8.1
Set-Cookie: sessionId=TAO9egg7mmJjtB7uzTnKbEkmWOzZc0pc; Secure; HttpOnly; path=/
Strict-Transport-Security: max-age=63072000; includeSubdomains
X-Content-Type-Options: nosniff
X-Frame-Options: DENY

c9
{"production":[{"type":"inverters","activeCount":19,"readingTime":1715108566,"wNow":2,"whLifetime":461493}],"storage":[{"type":"acb","activeCount":0,"readingTime":0,"wNow":0,"whNow":0,"state":"idle"}]}
0
Power:  jq: empty result
Energy: jq: empty result

jaykayone avatar May 07 '24 19:05 jaykayone

Redirect works as expected. Only there is no .measurementType == "production". Seems the api has changed, too.

andig avatar May 07 '24 19:05 andig

Workaround for now is to use:

meters:

  • name: Enphase type: custom power: source: http uri: https://ip_envoy/production.json method: GET auth: type: bearer password: token insecure: true jq: .production[0].wNow timeout: 60s

Lightmanster avatar May 09 '24 14:05 Lightmanster

Feel free to add a new template. V2 api is not compatible.

andig avatar May 09 '24 15:05 andig

Hi,

maybe not directly related but I am getting an

Mai 26 10:24:26 raspi-evcc evcc[6188]: [site ] ERROR 2024/05/26 10:24:26 grid meter: unexpected status: 401 (Unauthorized)

some hours after configuration. I added the meter (grid & pv) in evcc.yaml and also tried configuration via UI (..and deleted the yaml configuration part).

After putting a new token from enphase data are retrieved but again after some hours I am getting this error..

Any hints or workarounds? Thank you!

log-headers:

evcc --log-headers [main ] INFO 2024/05/26 10:30:47 evcc 0.126.4 [main ] INFO 2024/05/26 10:30:47 using config file: /etc/evcc.yaml [main ] INFO 2024/05/26 10:30:47 starting ui and api at :7070 [db ] INFO 2024/05/26 10:30:47 using sqlite database: /var/lib/evcc/evcc.db [proxy-502] DEBUG 2024/05/26 10:30:47 modbus proxy for 192.168.178.28:502 listening at :502 [lp-1 ] DEBUG 2024/05/26 10:30:48 charge total import: 4325.000kWh [site ] WARN 2024/05/26 10:30:48 battery configured but residualPower is missing or <= 0 (add residualPower: 100 to site), see https://docs.evcc.io/en/docs/reference/configuration/site#residualpower [site ] INFO 2024/05/26 10:30:48 site config: [site ] INFO 2024/05/26 10:30:48 meters: grid ✓ pv ✓ battery ✓ [site ] INFO 2024/05/26 10:30:48 grid: power ✓ energy ✗ currents ✗ [site ] INFO 2024/05/26 10:30:48 pv 1: power ✓ energy ✓ currents ✗ [site ] INFO 2024/05/26 10:30:48 battery 1: power ✓ energy ✗ currents ✗ soc ✓ capacity ✓ [site ] INFO 2024/05/26 10:30:48 vehicles: [site ] INFO 2024/05/26 10:30:48 vehicle 1: range ✓ finish ✓ status ✓ climate ✗ wakeup ✓ [site ] INFO 2024/05/26 10:30:48 vehicle 2: range ✓ finish ✗ status ✓ climate ✗ wakeup ✓ [lp-1 ] INFO 2024/05/26 10:30:48 loadpoint 1: [lp-1 ] INFO 2024/05/26 10:30:48 mode: minpv [lp-1 ] INFO 2024/05/26 10:30:48 charger: power ✓ energy ✓ currents ✓ phases ✗ wakeup ✗ [lp-1 ] INFO 2024/05/26 10:30:48 meters: charge ✓ [lp-1 ] INFO 2024/05/26 10:30:48 charge: power ✓ energy ✓ currents ✓ [site ] DEBUG 2024/05/26 10:30:48 set buffer soc: 50 [site ] DEBUG 2024/05/26 10:30:48 set buffer start soc: 60 [site ] DEBUG 2024/05/26 10:30:48 set priority soc: 20 [lp-1 ] DEBUG 2024/05/26 10:30:48 phase timer inactive [lp-1 ] DEBUG 2024/05/26 10:30:48 pv timer inactive [lp-1 ] DEBUG 2024/05/26 10:30:48 max charge current: 6A [site ] DEBUG 2024/05/26 10:30:48 ---- [lp-1 ] DEBUG 2024/05/26 10:30:48 charge power: 7600W [lp-1 ] DEBUG 2024/05/26 10:30:48 charge currents: [11 10.9 11]A [site ] ERROR 2024/05/26 10:30:49 pv 1 power: unexpected status: 401 (Unauthorized) [site ] DEBUG 2024/05/26 10:30:49 pv power: 0W [site ] DEBUG 2024/05/26 10:30:49 battery soc: 77% [site ] DEBUG 2024/05/26 10:30:49 battery power: 1337W [site ] ERROR 2024/05/26 10:30:50 grid meter: unexpected status: 401 (Unauthorized)

evcc meter --log-headersrs

[main ] INFO 2024/05/26 10:33:12 evcc 0.126.4 [main ] INFO 2024/05/26 10:33:12 using config file: /etc/evcc.yaml [db ] INFO 2024/05/26 10:33:12 using sqlite database: /var/lib/evcc/evcc.db db:1 ... Power: unexpected status: 401 (Unauthorized)

db:3 ... Power: unexpected status: 401 (Unauthorized) Energy: unexpected status: 401 (Unauthorized)

db:4 .... Power: -3816W Soc: 77% Capacity: 16.5kWh

BeneWilh avatar May 26 '24 08:05 BeneWilh

Maybe the token expires. Impossible to say without logfile and api documentation.

andig avatar May 26 '24 09:05 andig

Maybe the token expires. Impossible to say without logfile and api documentation.

yes, semms to be the case... haven't found any documentation how/where to put credentials so that the token could get renewed by the system. If you are owner and self-installer... token it seems token ist valid only for 12 hrs ... I am a self-installer

https://enphase.com/download/accessing-iq-gateway-local-apis-or-local-ui-token-based-authentication?_ga=2.207755409.223774952.1678687434-1765750934.1676903595

NOTE: Tokens are valid for a finite time. This is to ensure safety and you must generate a new token upon expiry.

• If the user is a system owner, the token is valid for 1 year. • If the user is an installer, the token is valid for 12 hours.

Log_enphase_token_renewed

.... you see in the upper part the log with error 401 and in the second part the values correctly... inbetween I renewed manually the token from enphase....

so, it would be really nice if someone could help implementing the automatic renewel of the token.

BeneWilh avatar May 26 '24 15:05 BeneWilh