Stock sensor stopped updating
Sensor updating stopped working, apparently for no reason. No change in configuration for was applied. It looks like the connection is forcibly corded
Logger: homeassistant.helpers.entity
Source: helpers/entity.py:942
First occurred: November 3, 2024 at 10:11:21 AM (295 occurrences)
Last logged: 8:11:21 PM
Update for sensor.alphabet fails
Update for sensor.apple fails
Update for sensor.robo_global fails
Update for sensor.health fails
Update for sensor.world_it fails
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 942, in async_update_ha_state
await self.async_device_update()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1300, in async_device_update
await self.async_update()
File "/config/custom_components/avanza_stock/sensor.py", line 250, in async_update
data = await pyavanza.get_stock_async(self._session, self._stock)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/pyavanza/__init__.py", line 87, in get_stock_async
return await request_url_async(session, url)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/pyavanza/__init__.py", line 67, in request_url_async
async with session.get(url, raise_for_status=True) as resp:
File "/usr/local/lib/python3.12/site-packages/aiohttp/client.py", line 1355, in __aenter__
self._resp: _RetType = await self._coro
^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/aiohttp/client.py", line 492, in _request
raise RuntimeError("Session is closed")
RuntimeError: Session is closed
I decided to restart home assistant and that fixed the issue. Before I close the issue is there anything I could test and report in future just in case the issue pops up again?
One thing to check is if the api is down, you can do that by visiting this url in your browser:
https://www.avanza.se/_api/market-guide/stock/{orderbook_id}
Change "{orderbook_id}" to the id you have for your stock.
I dont think that was the issue here, did any other cloud-based sensors of yours fail too?
Thanks for reporting :)
No other web sensor failed in the whole HA. I'll check if it will ever happen again. Of course I can say that restarting HA fixed it immediately... Though I never like "restarting" as a solution, but since everything else was up, that was the last thing to try.
Closing the issue and thanks for the feedback.
It did happen again and API was correctly responding from the browser. If you suggest anything I could check or debug I would be happy to help. Restarting made an immediate sensor update. To be clear the stock price was frozen to the day before during opening hours, no update at all, I am not talking about delays. Happy to help if I can.
I guess the error is the same as before, I'll try and find out why/when "Session is closed" happens and how to handle that
Happy to help, if you need anything just let me know.
That's right for me. I installed the addin for the first time yesterday. No update since then.
That's right for me. I installed the addin for the first time yesterday. No update since then.
Any errors? What is your config?
That's right for me. I installed the addin for the first time yesterday. No update since then.
Any errors? What is your config?
Same here (trying to prevent the 'same here!' only reply ;-) No config changes, only updates once after a HA restart and that's it. I turned on Debug logging which only shows one line after the restart and then goes silent:
2024-12-16 18:54:56.245 DEBUG (MainThread) [custom_components.avanza_stock.sensor] Tracking Tesla [238449] using Avanza
my config (in sensors.yaml):
- platform: avanza_stock
stock: 238449
name: Tesla
If I can help in providing more info or such, let me know.
cheers
Same for me. Sensors didnt fetch new state for 21 Minutes now. I am tracking the last updated timesstamp (as the built-in attribute is never populated)
Same for me. Sensors didnt fetch new state for 21 Minutes now. I am tracking the last updated timesstamp (as the built-in attribute is never populated)
60minutes is the default update interval, unless you configured something else. I just checked my stocks and they updated 5min ago
Same for me. Sensors didnt fetch new state for 21 Minutes now. I am tracking the last updated timesstamp (as the built-in attribute is never populated)
60minutes is the default update interval, unless you configured something else. I just checked my stocks and they updated 5min ago
Hold on, thats configurable? I thought it was fixed at 15 minute intervalls... how did I not see that!?
Okay, found the 60 minutes in the source code. Is there any limit they are enforcing? Whats the lowest I could go?
You can do
- platform: avanza_stock
scan_interval: 60
I guess 1,1min is the lowest. This is builtin (somehow) since this is a yaml only integraton.
Not sure if avanza could ip block you though, bit never happened what Ive heard 😃
Interestingly I got hit with the "Session is closed" today too. If it happens again, I'll try to get some debug logs etc.