USPS Sensor 'myusps.USPSError: Not logged in'

Maybe @happyleaves has a better idea of what’s going on, but what do you see when you go to this URL (make sure you login and the paste the URL in the browser again) :
https://my.usps.com/mobileWeb/pages/myusps/HomeAction_input

Can you attach a screen shot?

It should either say : “You currently have no scheduled deliveries.” or have packages information. I don’t have any package coming right now, but maybe something has changed again…

@J-CMartin & @happyleaves

When I go to https://my.usps.com/mobileWeb/pages/myusps/HomeAction_input I see the two packages in my USPS dashboard, both of which have valid tracking scans (one of which is out for delivery).

Is there a way I can delete all of the myusps code and have Home Assistant re-install it upon a new restart?

Hi everyone:
I’m having a similar authentication issue:

2017-06-06 01:36:38 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up platform usps
Traceback (most recent call last):
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 160, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=self.hass.loop)
  File "/usr/lib/python3.4/asyncio/tasks.py", line 372, in wait_for
    return fut.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 45, in setup_platform
    cookie_path=cookie)
  File "/home/homeassistant/.homeassistant/deps/myusps/__init__.py", line 237, in get_session
    _login(session)
  File "/home/homeassistant/.homeassistant/deps/myusps/__init__.py", line 137, in _login
    if resp.json()['rs'] != 'success':
KeyError: 'rs'

I’m certain the password is correct. I changed it several times to be sure, and I tried changing to a password without special characters, in case that was the issue. I tried deleting the myusps_cookies.pickle file. I tried updating the init.py file in the virtual environment and in the main filesystem. I have version 1.1.1 of myusps and version 0.46.0 of home assistant running on a raspberry pi 3 from the all-in-one installer. Python is version 3.4.2.

Do y’all think the problem is my version of python? Is there a workaround?

Thanks sincerely to this community and to @happyleaves 's work on home assistant and the USPS python program.

@pjmsullivan I’m having the same problem right now. Trying to fix.

The problem with this sensor is that whenever USPS changes their website, the sensor has to be updated as well, since they don’t offer an API.

Is USPS Sensor still not working?

I’m getting the following error.

2017-06-07 14:51:16 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up platform usps
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py”, line 155, in _async_setup_platform
entity_platform.schedule_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/lib/python3.4/site-packages/homeassistant/components/sensor/usps.py”, line 45, in setup_platform
cookie_path=cookie)
File “/srv/homeassistant/lib/python3.4/site-packages/myusps/init.py”, line 237, in get_session
_login(session)
File “/srv/homeassistant/lib/python3.4/site-packages/myusps/init.py”, line 137, in _login
if resp.json()[‘rs’] != ‘success’:
KeyError: ‘rs’

@happyleaves - I can confirm that python-myusps 1.1.2 is working for me too.
@Coolie1101 - to implement the new version, I replaced the contents of the following file:

/home/homeassistant/.homeassistant/deps/myusps/init.py

with the contents of the new version here: https://raw.githubusercontent.com/happyleavesaoc/python-myusps/master/myusps/__init__.py
And then rebooted.
Works like a charm!

Worked for me as well. Thanks @happyleaves

I don’t have a myusps folder in the deps directory.

Any ideas?

This is the one that needs updating

That worked :+1:

Is it the same situation with the ups sensor?

I’m getting the following error after reboot but, USPS package info is displayed in the front end.

2017-06-08 00:17:08 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.4/site-packages/myusps/init.py”, line 176, in wrapped
return function(*args)
File “/srv/homeassistant/lib/python3.4/site-packages/myusps/init.py”, line 229, in get_mail
container = _require_elem(response, INFORMED_DELIVERY_TAG, INFORMED_DELIVERY_ATTRS)
File “/srv/homeassistant/lib/python3.4/site-packages/myusps/init.py”, line 86, 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 “/usr/lib/python3.4/asyncio/tasks.py”, line 233, in _step
result = coro.throw(exc)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py”, line 361, in async_process_entity
new_entity, self, update_before_add=update_before_add
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py”, line 191, in async_add_entity
yield from self.hass.loop.run_in_executor(None, entity.update)
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/sensor/usps.py”, line 124, in update
self._state = len(myusps.get_mail(self._session))
File “/srv/homeassistant/lib/python3.4/site-packages/myusps/init.py”, line 179, in wrapped
_login(args[0])
File “/srv/homeassistant/lib/python3.4/site-packages/myusps/init.py”, line 156, in _login
raise USPSError(‘authentication failed’)
myusps.USPSError: authentication failed

I also tried to customize the name, which took no effect.

 sensor.ups:
   name: UPS

USPS is now divided into two sensors. One for packages and the other for mail. It looks like you are signed up for the Package dashboard service but not the Informed Delivery that shows how many pieces of mail are coming.
https://home-assistant.io/components/sensor.usps/

For the name, you can set it up on configuration.yaml:

  • platform: ups
    name: UPS

or customize.yaml:
sensor.ups:
#icon: mdi:package-variant-closed
friendly_name: UPS

Got it, missed the friendly part.

Any way to display the “in_transit” attribute in the same card?

Thanks again, appreciate it.

@J-CMartin
Available attribute for USPS:
USPS packages
4 minutes ago
2
departed usps origin facility
1
arrived at post office
1

Available attributes for UPS:
UPS
5 minutes ago
1
in transit
1

“Today’s deliveries” and “Packages in Transit” count are based on @happyleaves configuration that he shared earlier:
https://github.com/happyleavesaoc/my-home-automation/blob/master/homeassistant/packages/deliveries.yaml

What I’m asking, is can I display that info in the same card under UPS and USPS?

So it would look something like:

UPS 1
Status in transit

Or

UPS 1 in transit

Yes, use a template sensor

I receive the below error for Packages in Transit:

[homeassistant.components.sensor.template] Could not render template Packages in Transit, the state is unknown.