LaMetric errors

I am having some issues with the LaMetric component. Everything works fine when booting up PI and Hass, but after some time, the component stops working, and the LaMetric doesn’t display any notifications.

The log displays either “AttributeError: ‘NoneType’ object has no attribute ‘manager’” or “tokenExpired” when I try to send a notification to the LaMetric.

Anyone have an idea what could be causing this? :slight_smile:

 2017-07-23 13:15:28 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 233, in _step
    result = coro.throw(exc)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/core.py", line 1023, in _event_to_service_call
    yield from service_handler.func(service_call)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/notify/__init__.py", line 136, in async_notify_message
    yield from notify_service.async_send_message(**kwargs)
  File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
    value = future.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/notify/lametric.py", line 85, in send_message
    lmn = self.hasslametricmanager.manager()
AttributeError: 'NoneType' object has no attribute 'manager'

At other times, the log looks like this:

2017-07-22 21:20:21 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 233, in _step
    result = coro.throw(exc)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/core.py", line 1023, in _event_to_service_call
    yield from service_handler.func(service_call)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/notify/__init__.py", line 136, in async_notify_message
    yield from notify_service.async_send_message(**kwargs)
  File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
    value = future.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/notify/lametric.py", line 86, in send_message
    devices = lmn.get_devices()
  File "/home/homeassistant/.homeassistant/deps/lmnotify/lmnotify.py", line 180, in get_devices
    r = self.oauth.get(CLOUD_URLS["get_devices"][1])
  File "/srv/homeassistant/lib/python3.4/site-packages/requests/sessions.py", line 531, in get
    return self.request('GET', url, **kwargs)
  File "/home/homeassistant/.homeassistant/deps/requests_oauthlib/oauth2_session.py", line 330, in request
    http_method=method, body=data, headers=headers)
  File "/home/homeassistant/.homeassistant/deps/oauthlib/oauth2/rfc6749/clients/base.py", line 194, in add_token
    raise TokenExpiredError()
oauthlib.oauth2.rfc6749.errors.TokenExpiredError: (token_expired)

For what it’s worth, I’m getting the same problem. I’ve raised an issue about it.

1 Like

I’m getting the same error. Does anyone have a solution for the problem?

Not yet - I’ve pinged the original component author in a comment in the issue I linked to.

Neither have I. In the meantime, I am using the IFTTT component instead, and triggering LaMetric via a webhook. Sort of an ugly workaround, but hey it works :wink: one advantage is that IFTTTs LaMetric service supports notification sounds, something that I never got to work with the HA component…

Ok, solved it.

In

/opt/homeassistant/lib/python3.5/site-packages/homeassistant/components/notify/lametric.py

My installation is in /opt

the following has to be changed:

from homeassistant.components.lametric import DOMAIN

to

from homeassistant.components.lametric import DOMAIN, HassLaMetricManager

For me it works now.

Would you be able to submit that as a pull request?

If not, I’ll pick it up and run with it.

The component is working fine now. It should be available soon.

Thanks to @martinhjelmare for make it running, sound option and fetching new token after token expired.

If you want to change the code on your own, you can replace it by this:

lametric.py

notify/lametric.py

Config options:

- name: lametric1
  platform: lametric
  lifetime: 20
  icon: a7956
  cycles: 3

Sound and icon override has to be added as extra service data in automation:

...
  action:
    service: notify.lametric1
    data:
      message: 'Some message...'
      data:
        icon: 'i3153'
        sound: 'notification'
3 Likes