heyajohnny / cryptoinfo

Provides Home Assistant sensors for all cryptocurrencies supported by CoinGecko
GNU General Public License v3.0
48 stars 13 forks source link

Error getting values #32

Closed Shaun-Harrison closed 1 year ago

Shaun-Harrison commented 2 years ago

Noticed I'm getting this today in my logs

2022-08-10 08:20:24.735 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.cryptoinfo_acala_usd fails Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 514, in async_update_ha_state await self.async_device_update() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 709, in async_device_update raise exc File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) File "/usr/src/homeassistant/homeassistant/util/__init__.py", line 192, in wrapper result = method(*args, **kwargs) File "/config/custom_components/cryptoinfo/sensor.py", line 137, in _update self.data = r.json()[self.cryptocurrency_name][self.currency_name] KeyError: 'acala'

First noticed after updating to 2022.8.3 but went back to 2022.8.2 where it had been working but same error, maybe something has changed on api side?

heyajohnny commented 2 years ago

Do you still have this problem?

Shaun-Harrison commented 2 years ago

Hello

Yes still getting some errors in the log, although the sensors do appear to be updating;

2022-08-30 10:33:43.054 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.cryptoinfo_banano_usd fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 514, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 709, in async_device_update
    raise exc
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/util/__init__.py", line 192, in wrapper
    result = method(*args, **kwargs)
  File "/config/custom_components/cryptoinfo/sensor.py", line 152, in _update
    self.data = r.json()[0]
KeyError: 0

2022-08-30 10:33:43.151 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.cryptoinfo_moonbeam_usd fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 514, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 709, in async_device_update
    raise exc
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/util/__init__.py", line 192, in wrapper
    result = method(*args, **kwargs)
  File "/config/custom_components/cryptoinfo/sensor.py", line 152, in _update
    self.data = r.json()[0]
KeyError: 0

2022-08-30 10:33:43.357 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.cryptoinfo_acala_usd fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 514, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 709, in async_device_update
    raise exc
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/util/__init__.py", line 192, in wrapper
    result = method(*args, **kwargs)
  File "/config/custom_components/cryptoinfo/sensor.py", line 152, in _update
    self.data = r.json()[0]
KeyError: 0
heyajohnny commented 2 years ago

Very strange... I can't seem to reproduce this issue. Maybe it has something to do with your local network / firewall or a router that's rebooting at a certain time.

Shaun-Harrison commented 1 year ago

Hello

Sorry for the delay in getting back to you, just had a thought

You are using the coingecko API for this right, I use the same API for a crypto graph ticket I have running on my RPI0 with eink, I've noticed it hasnt alway been updating and while looking at the logs it says the API Limit has been reached

Assuming the limit is set by IP address, could it be that together with this integration and my other project, I'm hitting the limit and causing the error, as no results are being returned?

heyajohnny commented 1 year ago

For the Free plan the limit is set by IP address.

You must be doing a lot requests on the graph ticker. According to CoinGecko you can make 10~50 request per minute as you can see here. (under the Free plan)

If you set the 'update_frequency' to 1 (default is 60) for this integration you should still have 9~49 over for the graph ticker.

I should look at the graph ticker on how many requests it's doing. If it's doing a lot of requests, make it do less requests. It's also defeating the purpose of the e-ink screen, because it probably can't keep up with that many screen refreshes.

Shaun-Harrison commented 1 year ago

I was only doing 2 calls every 30 seconds, but changed that now to 5 minutes on grpytograph

I'm asking for 12 different tokens details from cryptoinfo every 1 minute, and a further 12 every 5 minutes (GDP every 5 and USD every 1)

Maybe it's nothing to do with the request rate, but thought it may be linked seeing as I'm having issues in cryptograph and you haven't seen this issue before

heyajohnny commented 1 year ago

I was only doing 2 calls every 30 seconds, but changed that now to 5 minutes on grpytograph

= 4 requests p/m. Now 2 / 5 = 0.4 requests p/m

I'm asking for 12 different tokens details from cryptoinfo every 1 minute

12 requests p/m (you could already hitting the limit with this one)

and a further 12 every 5 minutes (GDP every 5 and USD every 1)

12 / 5 = 2.4 requests p/m

So yeah, it's certainly possible that you are hitting the limit for the CoinGecko Free plan

Shaun-Harrison commented 1 year ago

So after tweeking the requests I'm now not seeing the errors in the logs, thanks for your help with this and closing the issue