New USPS sensor

I was trying this new sensor and got this error in the log:

17-01-15 23:32:24 homeassistant.bootstrap: Not initializing sensor.usps because could not install dependency myusps==1.0.1

How do I get that dependency installed? I thought it would be part of the “upgrade” ??

Hi, I had the same issue. I am trying to search it in Google, but without much luck as of yet.

Okay, I feel I am getting closer to the solution, just not quite there yet…this is what I did so far.

$ sudo systemctl stop [email protected] 
$ sudo su -s /bin/bash homeassistant
$ source /srv/homeassistant/bin/activate
$ pip3 install myusps  <--- I GET AN ERROR AT THIS POINT, BUT HAVE NO IDEA WHAT IT MEANS


ERROR : " compilation terminated.
    Compile failed: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
    creating tmp
    cc -I/usr/include/libxml2 -c /tmp/xmlXPathInit4k5mo6ty.c -o tmp/xmlXPathInit4k5mo6ty.o
    /tmp/xmlXPathInit4k5mo6ty.c:1:26: fatal error: libxml/xpath.h: No such file or directory
     #include "libxml/xpath.h"
                              ^
compilation terminated.
*********************************************************************************
Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
*********************************************************************************
error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1

----------------------------------------
Command "/srv/homeassistant/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-j69i57cc/lxml/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-81qov3v9-record/install-record.txt --single-version-externally-managed --compile --install-headers /srv/homeassistant/include/site/python3.4/lxml" failed with error code 1 in /tmp/pip-build-j69i57cc/lxml/"

The issue is a missing dependency. You need to make libxml2-dev or libxml2-devel (depending on the operating system you are using) available on your system.

I can confirm this. Do this first:
sudo apt-get install libxml2-dev
sudo apt-get install libxslt1-dev

Then get on homeassistant virual env to install myusps with:
pip3 install myusps

It confirms installed. So I restarted HA, then I got this in the home-assistant.log file:

  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/myusps/__init__.py", line 108, in get_profile
    profile = _require_elem(session.get(PROFILE_URL), PROFILE_XPATH)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/myusps/__init__.py", line 62, in _require_elem
    raise USPSError('Not logged in')
myusps.USPSError: Not logged in

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 151, in _async_setup_platform
    entity_platform.add_entities, discovery_info
  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/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/sensor/usps.py", line 48, in setup_platform
    add_devices([USPSSensor(session, config.get(CONF_UPDATE_INTERVAL))])
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/sensor/usps.py", line 58, in __init__
    self._profile = myusps.get_profile(session)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/myusps/__init__.py", line 100, in wrapped
    _login(*args)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/myusps/__init__.py", line 90, in _login
    _save_cookies(session.cookies, session.auth.cookie_path)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/myusps/__init__.py", line 41, in _save_cookies
    with open(filename, 'wb') as handle:
PermissionError: [Errno 13] Permission denied: './usps_cookies.pickle'

https://github.com/home-assistant/home-assistant/issues/5357

Thanks but how do I tell usps to use absolute path? Sorry I am new at this.

@vnguyen972 you can try to download the code available at https://raw.githubusercontent.com/tchellomello/home-assistant/myusps_cookie/homeassistant/components/sensor/usps.py which worked for me here.

All you have to do is to create a directory custom_components/sensor and place this file there.

We are currently waiting for the PR to be approved and once it becomes officially supported in HA, you will be remove the custom file and upgrade HA.

Please let me know if it worked for you or if you need any extra help.

Sorry about these problems, guys.
I’ll consider switching myusps to use a XML lib that doesn’t require a system dependency.

@happyleaves, no worries. Thank you for even coming up with such a cool idea! Could you, please write the exact steps of how it should be installed for it to work on the Pi image or point me in the right direction?

@tchellomello The link you have attached does not work. Could you please double check it? I get a “404: Not Found” error.

Thanks in advance for all your help!

Hello @davidc28,

I’ve restored the link and should be working now.

You can also download it directly from https://raw.githubusercontent.com/home-assistant/home-assistant/dev/homeassistant/components/sensor/usps.py since it was merged.

Let me know if that worked for you.

Good news!! The fix was included on version 0.36.1 (https://home-assistant.io/blog/2017/01/14/iss-usps-images-packages/#release-0361---january-17). Just remove the file from custom_components/sensor directory and upgrade HA normally.

It should work now as expected.

Thanks everyone!

Thanks for your contributions to HA. I love the system.

I installed 36.1 just now to use newest version of USPS. I now get this error:

17-01-17 08:01:34 homeassistant.components.sensor: Error while setting up platform usps
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/entity_component.py", line 151, in _async_setup_platform
    entity_platform.add_entities, discovery_info
  File "/usr/lib/python3.5/asyncio/futures.py", line 379, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 297, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 292, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/sensor/usps.py", line 51, in setup_platform
    add_devices([USPSSensor(session, config.get(CONF_UPDATE_INTERVAL))])
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/sensor/usps.py", line 65, in __init__
    self.update()
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/util/__init__.py", line 296, in wrapper
    result = method(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/sensor/usps.py", line 81, in _update
    for package in myusps.get_packages(self._session):
  File "/home/jeff/.homeassistant/deps/myusps/__init__.py", line 98, in wrapped
    return function(*args)
  File "/home/jeff/.homeassistant/deps/myusps/__init__.py", line 118, in get_packages
    dashboard = _require_elem(session.get(DASHBOARD_URL), DASHBOARD_XPATH)
  File "/home/jeff/.homeassistant/deps/myusps/__init__.py", line 65, in _require_elem
    raise ValueError('No element found')
ValueError: No element found

Do you need anything else?

Did you opt in to My USPS? Can you view your My USPS Dashboard in your browser? Does it list any packages?

I am receiving the same error as Jaalperin. After reading your comment, I went into my USPS account and found where you actually Opt-In to the My USPS service (something we might want to make more clear on the component page). I am still getting the same error, however I do not have any pending packages at this time. I assume we should wait until we have a package listed under the “My Packages” section before setting the sensor up?

Yes. So I think there are two takeaways here:

  1. We need to improve documentation about how use the sensor (opt into My USPS, etc).
  2. For now, you have to have a least one package in your “My Packages” history.

Thanks for this.

I just made a quick edit to the USPS component page that says you need to Opt-In to the service and submitted the pull request. First time doing this, so I hope I did it right.

I returned to usps.com and discovered that I was not opted-in. Sorry, thought I was. Anyway, now I am, but I get this error:

17-01-17 12:42:37 homeassistant.components.sensor: Error while setting up platform usps
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/entity_component.py", line 151, in _async_setup_platform
    entity_platform.add_entities, discovery_info
  File "/usr/lib/python3.5/asyncio/futures.py", line 379, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 297, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 292, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/sensor/usps.py", line 51, in setup_platform
    add_devices([USPSSensor(session, config.get(CONF_UPDATE_INTERVAL))])
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/sensor/usps.py", line 65, in __init__
    self.update()
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/util/__init__.py", line 296, in wrapper
    result = method(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/sensor/usps.py", line 81, in _update
    for package in myusps.get_packages(self._session):
  File "/home/jeff/.homeassistant/deps/myusps/__init__.py", line 98, in wrapped
    return function(*args)
  File "/home/jeff/.homeassistant/deps/myusps/__init__.py", line 118, in get_packages
    dashboard = _require_elem(session.get(DASHBOARD_URL), DASHBOARD_XPATH)
  File "/home/jeff/.homeassistant/deps/myusps/__init__.py", line 65, in _require_elem
    raise ValueError('No element found')
ValueError: No element found

Thanks again for your services to HA.

1 Like

As noted above, this is likely because you don’t yet have any packages listed. It’s a bug in the component’s module dependency (when I wrote it, I already had packages listed and couldn’t test the no-package state – oops).

So once a package shows up, it should start working.

I’ve installed the dependencies and did the pip3 reinstall. But I am still having a problem.How do I troubleshoot this issue ?

Jan 17 19:13:48 ha hass[23454]: INFO:homeassistant.loader:Loaded sensor.usps from homeassistant.components.sensor.usps
Jan 17 19:13:49 ha hass[23454]: INFO:homeassistant.bootstrap:Setting up sensor
Jan 17 19:13:49 ha hass[23454]: INFO:homeassistant.components.sensor:Setting up sensor.usps
Jan 17 19:13:58 ha hass[23454]: ERROR:homeassistant.components.sensor:Error while setting up platform usps
Jan 17 19:13:58 ha hass[23454]: Traceback (most recent call last):
Jan 17 19:13:58 ha hass[23454]: File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 151, in _async_setup_platform
Jan 17 19:13:58 ha hass[23454]: entity_platform.add_entities, discovery_info
Jan 17 19:13:58 ha hass[23454]: File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
Jan 17 19:13:58 ha hass[23454]: yield self  # This tells Task to wait for completion.
Jan 17 19:13:58 ha hass[23454]: File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
Jan 17 19:13:58 ha hass[23454]: value = future.result()
Jan 17 19:13:58 ha hass[23454]: File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
Jan 17 19:13:58 ha hass[23454]: raise self._exception
Jan 17 19:13:58 ha hass[23454]: File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
Jan 17 19:13:58 ha hass[23454]: result = self.fn(*self.args, **self.kwargs)
Jan 17 19:13:58 ha hass[23454]: File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/sensor/usps.py", line 51, in setup_platform
Jan 17 19:13:58 ha hass[23454]: add_devices([USPSSensor(session, config.get(CONF_UPDATE_INTERVAL))])
Jan 17 19:13:58 ha hass[23454]: File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/sensor/usps.py", line 65, in __init__
Jan 17 19:13:58 ha hass[23454]: self.update()
Jan 17 19:13:58 ha hass[23454]: File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/util/__init__.py", line 296, in wrapper
Jan 17 19:13:58 ha hass[23454]: result = method(*args, **kwargs)
Jan 17 19:13:58 ha hass[23454]: File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/sensor/usps.py", line 81, in _update
Jan 17 19:13:58 ha hass[23454]: for package in myusps.get_packages(self._session):
Jan 17 19:13:58 ha hass[23454]: File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/myusps/__init__.py", line 98, in wrapped
Jan 17 19:13:58 ha hass[23454]: return function(*args)
Jan 17 19:13:58 ha hass[23454]: File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/myusps/__init__.py", line 127, in get_packages
Jan 17 19:13:58 ha hass[23454]: 'shipped_from': row.xpath(SHIPPED_FROM_XPATH)[1].text.strip()
Jan 17 19:13:58 ha hass[23454]: AttributeError: 'NoneType' object has no attribute 'strip'