Mail and Packages: Custom component for UPS, FEDEX, and USPS

I removed your sys.exit(0) from the code that was causing it to stop.
Problem I am getting is something to do with sockets and getaddrinfo :neutral_face:

I am thinking some variables are not getting transmitted correctly or something.

1 Like

Where was that at? I see sys.exit(1) under the login function.

1 Like

Thatā€™s the one, that one was killing HA.

1 Like

Ya I just tossed in some debug code and it looks like the data is getting Noneā€™ed second go around:

2019-07-07 12:45:39 INFO (MainThread) [custom_components.mail_and_packages.sensor] version 0.0.1 is starting, if you have any issues please report them here: http://github.com/moralmunky/Home-Assistant-Mail-And-Packages
2019-07-07 12:45:39 DEBUG (MainThread) [custom_components.mail_and_packages.sensor] Debug:
 Host: None
 Port: None
 Folder: None
 User: None
 Path: None

First go around thereā€™s data in there:

2019-07-07 12:45:25 INFO (MainThread) [custom_components.mail_and_packages.sensor] version 0.0.1 is starting, if you have any issues please report them here: http://github.com/moralmunky/Home-Assistant-Mail-And-Packages
2019-07-07 12:45:25 DEBUG (MainThread) [custom_components.mail_and_packages.sensor] Debug:
 Host: imap.gmail.com
 Port: 993
 Folder: Inbox
 User: **[REDACTED]**
 Path: /home/homeassistant/.homeassistant/www/mail_card/

2019-07-07 12:45:25 DEBUG (MainThread) [custom_components.mail_and_packages.sensor] Attempting to connect to imap.gmail.com 993
2019-07-07 12:45:25 DEBUG (MainThread) [custom_components.mail_and_packages.sensor] Login successful!

Iā€™ll keep plugging away at it.

Seems like my latest commit on my fork mostly works. Needs more testing.

@ralfaro or @codypet2002 maybe even @jaaem want to give it a shot?

Branch: add_config
Add to one of your sensors yaml:

- platform: mail_and_packages
  host: !secret mail_host
  # port: !secret mail_port (default 993)
  username: !secret mail_user
  password: !secret mail_pwd
  folder: !secret mail_folder
  image_path: !secret mail_image_path

I received a new set of errors this morning. Is this still related to the problem I was having before? These seem like different errors.

File "/usr/lib/python3.7/socket.py", line 748, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution

Iā€™ll be happy to help. Maybe this will straighten out what I seem to be doing wrong when I tried it the other way. I should be able to tackle it middle of this week.

Iā€™m getting the following

Tue Jul 09 2019 13:24:49 GMT-0400 (EDT)

Updating mail_and_packages sensor took longer than the scheduled update interval 0:00:30

I still have my information hard coded in the python script. The script in my HASS is a bit different from what I have published on GitHub. I removed the repeated email checking function from each sensor to itā€™s own function that received the email address and subject line to make more efficient code.

I added your updates from the add_config branch and continued to try and get the variables passed in without defining it under the sensors section.

Iā€™ve been running my changes on add_config branch and they seem to be working properly. I did another commit last night, but it seems to be working as intended, at least for me.

sorry, been out of town. Iā€™ll try to test soon

1 Like

I got everything updated in my repository based on your code and the consolidation of functions from the code on my HASS instal that. I never published. Everything is appears to be functioning as intended using the sensor platform to pull in the configuration.

Barring any code changes to make it HASS proper, the next thing would be to fold in the template sensors logic as entities to lesson the configuration.

From the package yaml? That should be easy.

Added the sensors for ā€œin transitā€ and ā€œdeliveredā€, also working on camera component :wink:

https://github.com/firstof9/Home-Assistant-Mail-And-Packages/tree/add_config

Threw this on a test instance, seems to be working but no mail today. Will update when I get mail (hopefully Monday). Was having issues getting the old setup working so excited for this option!

Iā€™ve fixed a few typos on the version in my repo, anyone testing may want to grab the latest version.

I just got a second ā€œpingā€ saying there was new mail but it was exactly the same as the previous message/nothing was updated. Not sure if thatā€™s an error in the way I have things set up or what.

Yup, more information will be needed. Whose repository did you get the code from and what is your configuration. Also, when you say nothing was updated, was the text and image incorrect in the message? Does it display correctly in the card?

@firstof9, Are you still working off the original expanded version or the last update I made condensing the functions and incorporating your configuration code? I havenā€™t worked much in GitHub so I may need more instructions to work with merging properly but I want to make sure our codes are in sync and it doesnā€™t create confusion.

Iā€™m using firstof9ā€™s code.

I think the only ā€œoddā€ change (other than fixing host/port/setting username/pw) was to the path. I run in docker, so everything is in the /config directory. Hereā€™s the config part:

DEFAULT_PORT = '993'
DEFAULT_FOLDER = 'Tracking'
DEFAULT_PATH = '/config/www/mail_and_packages/'

And I modified the notification bit to work with TG. hereā€™s what I have:

    - service: notify.tg_pm
      data_template:
        title: "*Today's Mail and Packages*"
        message: "{{ states('sensor.mail_deliveries_message')}}"
    - service: notify.tg_pm
      data:
        message: "Here is the mail"
        data:
          document:
            file: "/config/www/mail_and_packages/mail_today.gif"

By this I mean that i got the same exact message/image 2 times about 3 hours apart. I think this may have happened once or twice on the old setup. Iā€™ll see if it repeats again tomorrow (presuming I have mail).

I merged your changes into the version Iā€™ve been working on :slight_smile: