Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Home assistant sensor stops updating #22

Closed
Hooch76 opened this issue Jun 24, 2019 · 14 comments
Closed

Home assistant sensor stops updating #22

Hooch76 opened this issue Jun 24, 2019 · 14 comments

Comments

@Hooch76
Copy link

Hooch76 commented Jun 24, 2019

The SMA sensor in Home Assistant works fine for some time (<24h) but then stops updating. Restarting Home Assistant usually fixes the issue .

This is what I get in the logs then:

2019-06-24 06:29:16 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/opt/homeassistant/lib/python3.7/site-packages/homeassistant/components/sma/sensor.py", line 128, in async_sma
    values = await sma.read(used_sensors)
  File "/opt/homeassistant/lib/python3.7/site-packages/pysma/__init__.py", line 254, in read
    if sen.extract_value(body):
  File "/opt/homeassistant/lib/python3.7/site-packages/pysma/__init__.py", line 51, in extract_value
    res = next(iter(jmespath.search(JMESPATH_BASE, json_body)))
TypeError: 'NoneType' object is not iterable

Plus

2019-06-24 06:30:11 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/opt/homeassistant/lib/python3.7/site-packages/aiohttp/connector.py", line 924, in _wrap_create_connection
    await self._loop.create_connection(*args, **kwargs))
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 959, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 946, in create_connection
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.7/asyncio/selector_events.py", line 464, in sock_connect
    return await fut
  File "/usr/local/lib/python3.7/asyncio/selector_events.py", line 494, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
OSError: [Errno 113] Connect call failed ('<SMA-IP>', 443)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/homeassistant/lib/python3.7/site-packages/homeassistant/components/sma/sensor.py", line 128, in async_sma
    values = await sma.read(used_sensors)
  File "/opt/homeassistant/lib/python3.7/site-packages/pysma/__init__.py", line 243, in read
    body = yield from self._fetch_json(URL_VALUES, payload=payload)
  File "/opt/homeassistant/lib/python3.7/site-packages/pysma/__init__.py", line 201, in _fetch_json
    self._url + url, **params)
  File "/opt/homeassistant/lib/python3.7/site-packages/aiohttp/client.py", line 476, in _request
    timeout=real_timeout
  File "/opt/homeassistant/lib/python3.7/site-packages/aiohttp/connector.py", line 522, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/opt/homeassistant/lib/python3.7/site-packages/aiohttp/connector.py", line 854, in _create_connection
    req, traces, timeout)
  File "/opt/homeassistant/lib/python3.7/site-packages/aiohttp/connector.py", line 992, in _create_direct_connection
    raise last_exc
  File "/opt/homeassistant/lib/python3.7/site-packages/aiohttp/connector.py", line 974, in _create_direct_connection
    req=req, client_error=client_error)
  File "/opt/homeassistant/lib/python3.7/site-packages/aiohttp/connector.py", line 931, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host <SMA-IP>:443 ssl:None [Connect call failed ('<SMA-IP>', 443)]
@Hooch76
Copy link
Author

Hooch76 commented Jun 27, 2019

Additional information: seems as if it might be related to WiFi connectivity of my Home Assistant box.
Connection randomly drops for a little while (<1min) and it seems that pysma does not recover then. Is this possible? (All other components are not affected though. They throw an error when no network is available but will be updated once connection is re-established).

@kellerza
Copy link
Owner

It can probably be improved by adding ClientConnectError or its base, here

            except asyncio.TimeoutError, aiohttp.client_exceptions.ClientConnectorError:

you have to also import aiohttp at the top

@kellerza
Copy link
Owner

Let me know if you still experience issues after the new version

@Hooch76
Copy link
Author

Hooch76 commented Jul 16, 2019

pysma seems now to be able to recover from network hiccups, as seen from the home assistant debug log:

WARNING (MainThread) [pysma] No 'result' in reply from SMA, got: {'err': 'Could not connect to SMA at https://x.y.z.z (timeout)'}

There's another (unrelated) issue where pysma runs into the following error

WARNING (MainThread) [pysma] 401 error detected, closing session to force another login attempt

The problem is that I cannot see any more tries of pysma connecting to the inverter once that occured (and data is not updated then).

@kellerza
Copy link
Owner

No errors after that?

try wrapping this line in try/finally

        try:
            yield from self._fetch_json(URL_LOGOUT, {})
        finally:
            self.sma_sid = None

but even that should have thrown another error after the one you shared

@Hooch76
Copy link
Author

Hooch76 commented Jul 17, 2019

Nothing at all from pysma after that ... I've updated it and let you know how it goes. Thanks

@Hooch76
Copy link
Author

Hooch76 commented Jul 19, 2019

This is how the logfile from home assistant looks like:

2019-07-19 06:00:47 WARNING (MainThread) [pysma] 401 error detected, closing session to force another login attempt
2019-07-19 06:01:48 WARNING (MainThread) [pysma] 401 error detected, closing session to force another login attempt
2019-07-19 06:02:58 WARNING (MainThread) [pysma] No 'result' in reply from SMA, got: {'err': 'Could not connect to SMA at https://x.x.x.x (timeout)'}
2019-07-19 06:09:01 WARNING (MainThread) [pysma] 401 error detected, closing session to force another login attempt
2019-07-19 06:39:22 WARNING (MainThread) [pysma] 401 error detected, closing session to force another login attempt
2019-07-19 07:40:21 WARNING (MainThread) [pysma] 401 error detected, closing session to force another login attempt
2019-07-19 08:41:17 WARNING (MainThread) [pysma] 401 error detected, closing session to force another login attempt

Also have a look at the timestamps. It is retried once an hour only.
Any chance that "closing session" somehow does not work? Restarting home assistant immediately fixes the issue.

@Human
Copy link
Contributor

Human commented Aug 4, 2019

I'm not sure why exactly this is closed. I have the same issue.

@kellerza
Copy link
Owner

kellerza commented Aug 4, 2019

@Human, the original or the new issue?

@Human
Copy link
Contributor

Human commented Aug 4, 2019

@kellerza I'm having the titular "Home assistant sensor stops updating" issue with the last-mentioned error logs:

2019-07-30 06:56:16 WARNING (MainThread) [pysma] 401 error detected, closing session to force another login attempt

@JoooostB
Copy link

JoooostB commented Aug 7, 2019

@Human It has been closed because the changes have been merged to the PySMA 0.3.2 release which is already available in home-assistant:dev

@Human
Copy link
Contributor

Human commented Aug 10, 2019

Thanks. I still have the same bug, as the title describes. Would it be best for me to a file a new bug report?

@JoooostB
Copy link

@Human Yes, please do so! I just checked and I'm experiencing it again too...

@Hooch76
Copy link
Author

Hooch76 commented Aug 19, 2019

I've created a new issue, see #25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants