macxq / foxess-ha

Home Assistant & FoxESS integration. Monitor you photovoltaic installation directly from HA ☀️ ⚡️
120 stars 37 forks source link

Unexpected error fetching FoxESS data: Expecting value: line 1 column 1 (char 0) #177

Open guba91 opened 1 year ago

guba91 commented 1 year ago

HA 2023.5.3 foxess-ha version: v0.26

Logger: custom_components.foxess.sensor Source: custom_components/foxess/sensor.py:276 Integration: foxess (documentation, issues) First occurred: 23 maggio 2023 alle ore 16:33:05 (4 occurrences) Last logged: 23 maggio 2023 alle ore 16:58:25

Unexpected error fetching FoxESS data: Expecting value: line 1 column 1 (char 0) Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 258, in _async_refresh self.data = await self._async_update_data() File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 217, in _async_update_data return await self.update_method() File "/config/custom_components/foxess/sensor.py", line 141, in async_update_data await getAddresbook(hass, headersData, allData, deviceID, username, hashedPassword,0) File "/config/custom_components/foxess/sensor.py", line 276, in getAddresbook response = json.loads(restAddressBook.data) File "/usr/local/lib/python3.10/json/init.py", line 346, in loads return _default_decoder.decode(s) File "/usr/local/lib/python3.10/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/local/lib/python3.10/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

M31Galaxy15287 commented 1 year ago

I'm experiencing the same problem. Usually it happens a few times a day, every day. Very annoying because I have a couple of utility meters that depend on the data that I have to manually calibrate each day now. Sometimes I only loose a couple of readings of the sensor.battery_soc entity.

Here is my log:

Logger: custom_components.foxess.sensor Source: custom_components/foxess/sensor.py:305 Integration: foxess (documentation, issues) First occurred: 15:54:33 (1 occurrences) Last logged: 15:54:33

Unexpected error fetching FoxESS data: Expecting value: line 1 column 1 (char 0) Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 258, in _async_refresh self.data = await self._async_update_data() File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 217, in _async_update_data return await self.update_method() File "/config/custom_components/foxess/sensor.py", line 147, in async_update_data await getReport(hass, headersData, allData, deviceID) File "/config/custom_components/foxess/sensor.py", line 305, in getReport for item in json.loads(restReport.data)['result']: File "/usr/local/lib/python3.10/json/init.py", line 346, in loads return _default_decoder.decode(s) File "/usr/local/lib/python3.10/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/local/lib/python3.10/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

guba91 commented 1 year ago

at least i'm not alone <3

RubenCoppensOnGit commented 1 year ago

i created a fix. I forked the code .. and requested for a pullrequest to get it back into here. No errors anymore.. NONE. I added a lot of optimizations in it. works without hangs.. already for 2 days now. The real issue was a problem in Hass. helper method for api is not stable. I created a workaround Also the adressbook issue is solved. if you want you can try the version in the fork from : https://github.com/RubenCoppensOnGit/foxess-ha/tree/Fixing-HA-hang-key-error

i assume it will be merged soon here.

Enjoy

M31Galaxy15287 commented 1 year ago

Thank you for your work! I copied over your fix. I will give it a few days and then I will reply again with my findings. Hope this fixes my problem indeed.

guba91 commented 1 year ago

i created a fix. I forked the code .. and requested for a pullrequest to get it back into here. No errors anymore.. NONE. I added a lot of optimizations in it. works without hangs.. already for 2 days now. The real issue was a problem in Hass. helper method for api is not stable. I created a workaround Also the adressbook issue is solved. if you want you can try the version in the fork from : https://github.com/RubenCoppensOnGit/foxess-ha/tree/Fixing-HA-hang-key-error

i assume it will be merged soon here.

Enjoy

I'm going to test it now! Thanks!

guba91 commented 1 year ago

i created a fix. I forked the code .. and requested for a pullrequest to get it back into here. No errors anymore.. NONE. I added a lot of optimizations in it. works without hangs.. already for 2 days now. The real issue was a problem in Hass. helper method for api is not stable. I created a workaround Also the adressbook issue is solved. if you want you can try the version in the fork from : https://github.com/RubenCoppensOnGit/foxess-ha/tree/Fixing-HA-hang-key-error

i assume it will be merged soon here.

Enjoy triyed your repo but i got this error in the logs:

2023-06-25 22:03:46.756 ERROR (MainThread) [homeassistant.components.sensor] Error adding entities for domain sensor with platform foxess Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 471, in async_add_entities await asyncio.gather(*tasks) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 749, in _async_add_entity await entity.add_to_platform_finish() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 850, in add_to_platform_finish self.async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 590, in async_write_ha_state self._async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 654, in _async_write_ha_state state = self._stringify_state(available) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 596, in _stringify_state if (state := self.state) is None: ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/sensor/init.py", line 469, in state value = self.native_value ^^^^^^^^^^^^^^^^^ File "/config/custom_components/foxess/sensor.py", line 1252, in native_value if self.coordinator.data["reportDailyGeneration"]["value"] == 0:


KeyError: 'value'
2023-06-25 22:03:46.762 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up foxess platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 328, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 471, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 749, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 850, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 590, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 654, in _async_write_ha_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 596, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 469, in state
    value = self.native_value
            ^^^^^^^^^^^^^^^^^
  File "/config/custom_components/foxess/sensor.py", line 1252, in native_value
    if self.coordinator.data["reportDailyGeneration"]["value"] == 0:
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
KeyError: 'value'
essenemari commented 1 year ago

Thanks! Actually it looks very promising for me, as issue #156 does NOT persist with your changes!

Before it was like below and counters were raising up during the time:

Tue 06 Jun 2023 09:51:30 PM CEST

lsof for homeassistant user: 920
lsof for homeassistant user and  8.209.116.72: 506
lsof only for 8.209.116.72: 4554
lsof for hass: 8286

Now, after few hour of testing

Mon 26 Jun 2023 09:53:38 PM CEST

lsof for homeassistant user: 344
lsof for homeassistant user and  8.209.116.72: 0
lsof only for 8.209.116.72: 0
lsof for hass: 4803

Looks awesome!

xrad commented 8 months ago

Seeing this error as of last night around ~ 0200 UTC. Rebooted HA but still no dice:

Logger: custom_components.foxess.sensor
Source: helpers/update_coordinator.py:313
Integration: foxess ([documentation](https://github.com/macxq/foxess-ha), [issues](https://github.com/macxq/foxess-ha/issues))
First occurred: 09:18:08 (1 occurrences)
Last logged: 09:18:08
Unexpected error fetching FoxESS data: Expecting value: line 1 column 1 (char 0)

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 313, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 269, in _async_update_data
    return await self.update_method()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/foxess/sensor.py", line 125, in async_update_data
    token = await authAndgetToken(hass, username, hashedPassword)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/foxess/sensor.py", line 251, in authAndgetToken
    response = json.loads(restAuth.data)
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I didn't change any of the creditials recently. I had updated to the latest HA core and HAOS but the system had worked fine after this for about a day, so I don't think it's related.

FozzieUK commented 8 months ago

FoxESS appear to have disabled private access to their cloud again, this was always going to happen but the timing of it seems to have taken everyone by surprise, so I suspect once FoxESS UK support get involved with their opposite numbers in China that change will be reversed.

The OpenAPI version is written and working, it needs a personal_api_key to operate and you get that from the FoxESS cloud platform - but at the moment the request a key isn't working either, if you have a personal api key already their openAPI will work, but until they get that request screen working again there's not much to do - i've just given FoxESS UK support a nudge.

I'll post more when I have updates

xrad commented 8 months ago

I see. Couldn't obtain the API key either. Let me know if there is anything I can help with.

xrad commented 8 months ago

API key generation is back online and 0.33 appears to work fine! Thanks a lot!

MartinBlackburn commented 8 months ago

Can also confirm I've been able to update to the open API version and generate an API key which seems to be working so far. Thanks for fixing this @FozzieUK

xrad commented 8 months ago

Thanks again, I have not seen any issues since the switch.

Since the OpenAPI server limits the number of accesses - could it be an interesting feature to do the queries in a non-linear way, for example do less queries during the night and more during daytime?

FozzieUK commented 8 months ago

@xrad i’ve been working on improving the pacing mechanism for api calls. It is currently running at ~ 35api calls per hour, i’m testing a version that runs at ~25 api (next release) but as the openapi only returns the last ‘real time’ variables data you have to poll at the datalogger interval speed or risk losing data. I think there is some mileage in slowing down the daily totals (feedin, generation, loads etc..), the battery parameters, and daily generation but once you get below 25 api calls they are only small improvements - if I can get it reliable at 20 api calls per hour, i’ll be happy 😊

xrad commented 8 months ago

Makes sense. I totally ignored the datalogger invervall in my speculation. Cheers!

blackequine commented 1 month ago

It looks like this problem is back. The integration was working well (thank you), but after restarting Home Assistant, it now fails to start:

Traceback (most recent call last): File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/helpers/update_coordinator.py", line 354, in _async_refresh self.data = await self._async_update_data() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/helpers/update_coordinator.py", line 271, in _async_update_data return await self.update_method() ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/homeassistant/.homeassistant/custom_components/foxess/sensor.py", line 169, in async_update_data getError = await getOADeviceDetail(hass, allData, deviceSN, apiKey) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/homeassistant/.homeassistant/custom_components/foxess/sensor.py", line 441, in getOADeviceDetail response = json.loads(restOADeviceDetail.data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/json/init.py", line 346, in loads return _default_decoder.decode(s) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) 2024-10-14 18:12:11.185 DEBUG (MainThread) [custom_components.foxess.sensor] Finished fetching FoxESS data in 0.797 seconds (success: False)

blackequine commented 1 month ago

Oops, I should have mentioned that I’m using version 0.43 of the integration, installed using HACs on Hass 2024.10.2.

FozzieUK commented 1 month ago

It’s the Fox OpenAPI that is currently down for all users - hopefully they’ll get it sorted soon 👍

FozzieUK commented 1 month ago

It came back approx 2.25am this morning - working normally now.

mt104 commented 1 month ago

My Home Assistant needed a restart just now as the integration didn’t recover by itself.

Cheers,

Mark.

On 15 Oct 2024, at 09:04, Dave Foster @.***> wrote:



It came back approx 2.25am this morning - working normally now.

— Reply to this email directly, view it on GitHubhttps://github.com/macxq/foxess-ha/issues/177#issuecomment-2413174135, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABYNACO7WYYDW6UL7UHOO73Z3TEBBAVCNFSM6AAAAABP5N75XKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMJTGE3TIMJTGU. You are receiving this because you are subscribed to this thread.Message ID: @.***>

FozzieUK commented 1 month ago

@mt104 if you hadn't restarted HA yesterday after the error, there's a chance it would have re-connected ok, but the best advice is to restart your HA to be sure.

mt104 commented 1 month ago

Yes, I had restarted HA while the API was down to fix an unrelated problem. Next time I notice the API down I’ll try to leave HA alone to see if it recovers by itself.

Thanks,

Mark.

On 15 Oct 2024, at 09:26, Dave Foster @.***> wrote:



@mt104https://github.com/mt104 if you hadn't restarted HA yesterday after the error, there's a chance it would have re-connected ok, but the best advice is to restart your HA to be sure.

— Reply to this email directly, view it on GitHubhttps://github.com/macxq/foxess-ha/issues/177#issuecomment-2413221965, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABYNACMUXCFCW54UOCILOATZ3TGTJAVCNFSM6AAAAABP5N75XKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMJTGIZDCOJWGU. You are receiving this because you were mentioned.Message ID: @.***>

ssherlock commented 1 month ago

Daft question but is there a simple way of knowing it is down, or just the fact we get no reply to an API request? My separate calls (i.e. not via Home Assistant) were getting a 502 response.

Simon

On Tue, 15 Oct 2024, 09:04 Dave Foster, @.***> wrote:

It came back approx 2.25am this morning - working normally now.

— Reply to this email directly, view it on GitHub https://github.com/macxq/foxess-ha/issues/177#issuecomment-2413174135, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAD2M5DMCDCHOQNCG3JMJU3Z3TEA7AVCNFSM6AAAAABP5N75XKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMJTGE3TIMJTGU . You are receiving this because you are subscribed to this thread.Message ID: @.***>

FozzieUK commented 1 month ago

@ssherlock no there’s no other way of knowing, 503 is a fatal error and so you don’t get any supplemental status - I have an automation that watches my rvolt sensor and if it goes unavailable for 15 minutes it notifies me.