Config issues (after possibly configuring Mail and Packages Integration?)

Hi Everyone,

So i just installed the Mail & Packages integration and it’s great and everything is working fine. That said, HA is now throwing me a whole bunch of errors even though my config is claiming to be okay. I noticed this issue when I went to restart HA through server controls… it wouldn’t let me do that OR validate my configuration. I think it has something to do with the fact that I am running two instances of Mail & Packages and that maybe I setup the platform templates incorrectly, but I can’t pin it down with the limited amount of HA knowledge that I have. Any help here from someone who actually knows what they’re doing would be greatly appreciated! Thanks.

Here is my config.yaml:

##DUCKDNS.ORG##
http: 
 ssl_certificate: /ssl/fullchain.pem
 ssl_key: /ssl/privkey.pem

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

##THEMES##
frontend:
    themes: !include_dir_merge_named themes

##LIGHTS##
lutron_caseta:
  host: xxxxxxx
  keyfile: /ssl/lutron/caseta.key
  certfile: /ssl/lutron/caseta.crt
  ca_certs: /ssl/lutron/caseta-bridge.crt

###Sensors###
#Waze#
sensor:
  - platform: waze_travel_time
    name: "Seth to Home"
    origin: device_tracker.seth_iphone
    destination: 'xxxx'
    region: 'US'
  - platform: waze_travel_time
    name: "Amanda to Home"
    origin: device_tracker.amanda_iphone
    destination: 'xxxxx'
    region: 'US'
  - platform: waze_travel_time
    name: "Old Navy"
    origin: 'xxxxx'
    destination: 'xxxxx'
    region: 'US'
  - platform: waze_travel_time
    name: "Ariat"
    origin: 'xxxxx'
    destination: 'xxxxx'
    region: 'US'
  - platform: waze_travel_time
    name: "Rocklin"
    origin: 'xxxxx
    destination: 'xxxxx'
    region: 'US'
  - platform: waze_travel_time
    name: "Heber, UT"
    origin: 'xxxxx'
    destination: 'xxxxx'
    region: 'US'
##Mail and Packages##
  - platform: template
    sensors:
      mail_deliveries_message:
      name: "Deliveries Summary Amanda"
      value_template: > 
        {# Deliveries Sentence #}
          {% macro deliveries_sentence() -%}
                {%- if states("sensor.mail_usps_mail_2")|int == 0 -%}
                  No
                {%- else -%}
                  {{states("sensor.mail_usps_mail_2")|int}}
                {%- endif -%}
              {{' '}} 
                {%- if states("sensor.mail_usps_mail_2")|int <= 1 -%}
                  pieces of mail
                {%- else -%}
                  pieces of mail
                {%- endif -%}
              {{' '}}will be delivered.{{' '}} 
                {%- if states("sensor.mail_usps_delivering_2")|int == 0 -%}
                  No
                {%- else -%}
                  {{states("sensor.mail_usps_delivering_2")|int}}
                {%- endif -%}
              {{' '}} 
                {%- if states("sensor.mail_usps_delivering_2")|int == 1 -%}
                  USPS package is
                {%- else -%}
                  USPS packages are
                {%- endif -%}
              {{' '}}in transit.{{' '}}
                {%- if states("sensor.mail_fedex_delivering_2")|int == 0 -%}
                  No
                {%- else -%}
                  {{states("sensor.mail_fedex_delivering_2")|int}}
                {%- endif -%}
              {{' '}} 
                {%- if states("sensor.mail_fedex_delivering_2")|int == 1 -%}
                  FedEx package is
                {%- else -%}
                  Fedex packages are
                {%- endif -%}
              {{' '}}in transit.{{' '}}
              {%- if states("sensor.mail_ups_delivering_2")|int == 0 -%}
                  No
                {%- else -%}
                  {{states("sensor.mail_ups_delivering_2")|int}}
                {%- endif -%}
              {{' '}} 
                {%- if states("sensor.mail_ups_delivering_2")|int == 1 -%}
                  UPS package is
                {%- else -%}
                  UPS packages are
                {%- endif -%}
              {{' '}}in transit.{{' '}}
              {%- if states("sensor.mail_amazon_packages_2")|int == 0 -%}
                  No
                {%- else -%}
                  {{states("sensor.mail_amazon_packages_2")|int}}
                {%- endif -%}
              {{' '}} 
                {%- if states("sensor.mail_amazon_packages_2")|int == 1 -%}
                  Amazon package is
                {%- else -%}
                  Amazon packages are
                {%- endif -%}
              {{' '}}in transit.{{' '}}
          {%- endmacro %}
        {{deliveries_sentence()}}
      mail_deliveries_message2:
       name: "Deliveries Summary Seth"
       value_template: > 
        {# Deliveries Sentence #}
          {% macro deliveries_sentence() -%}
                {%- if states("sensor.mail_usps_mail")|int == 0 -%}
                  No
                {%- else -%}
                  {{states("sensor.mail_usps_mail")|int}}
                {%- endif -%}
              {{' '}} 
                {%- if states("sensor.mail_usps_mail")|int <= 1 -%}
                  pieces of mail
                {%- else -%}
                  pieces of mail
                {%- endif -%}
              {{' '}}will be delivered.{{' '}} 
                {%- if states("sensor.mail_usps_delivering")|int == 0 -%}
                  No
                {%- else -%}
                  {{states("sensor.mail_usps_delivering")|int}}
                {%- endif -%}
              {{' '}} 
                {%- if states("sensor.mail_usps_delivering")|int == 1 -%}
                  USPS package is
                {%- else -%}
                  USPS packages are
                {%- endif -%}
              {{' '}}in transit.{{' '}}
                {%- if states("sensor.mail_fedex_delivering")|int == 0 -%}
                  No
                {%- else -%}
                  {{states("sensor.mail_fedex_delivering")|int}}
                {%- endif -%}
              {{' '}} 
                {%- if states("sensor.mail_fedex_delivering")|int == 1 -%}
                  FedEx package is
                {%- else -%}
                  Fedex packages are
                {%- endif -%}
              {{' '}}in transit.{{' '}}
              {%- if states("sensor.mail_ups_delivering")|int == 0 -%}
                  No
                {%- else -%}
                  {{states("sensor.mail_ups_delivering")|int}}
                {%- endif -%}
              {{' '}} 
                {%- if states("sensor.mail_ups_delivering")|int == 1 -%}
                  UPS package is
                {%- else -%}
                  UPS packages are
                {%- endif -%}
              {{' '}}in transit.{{' '}}
              {%- if states("sensor.mail_amazon_packages")|int == 0 -%}
                  No
                {%- else -%}
                  {{states("sensor.mail_amazon_packages")|int}}
                {%- endif -%}
              {{' '}} 
                {%- if states("sensor.mail_amazon_packages")|int == 1 -%}
                  Amazon package is
                {%- else -%}
                  Amazon packages are
                {%- endif -%}
              {{' '}}in transit.{{' '}}
          {%- endmacro %}
        {{deliveries_sentence()}}

##SPOTIFY##
spotify:
  client_id: xxxx
  client_secret: xxxx

##SPOTCAST##
spotcast:
  sp_dc: xxx
  sp_key: xxx

##Google Calendar##
google:
  client_id: !secret google_client_id_calendar
  client_secret: !secret google_client_secret_calendar

##Stream##
stream:

##Camera##
camera:
 - platform: local_file
   file_path: /config/images/amanda/mail_and_packages/
   name: mail_usps_2
 - platform: local_file
   file_path: /config/images/mail_and_packages/
   name: mail_usps

Here are the error logs it’s throwing:

Logger: homeassistant.config
Source: helpers/config_validation.py:755
First occurred: 10:26:59 AM (1 occurrences)
Last logged: 10:26:59 AM

Unknown error validating config for template platform for sensor component with PLATFORM_SCHEMA
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/config.py”, line 831, in async_process_component_config
p_validated = platform.PLATFORM_SCHEMA(p_config) # type: ignore
File “/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py”, line 272, in call
return self._compiled([], data)
File “/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py”, line 594, in validate_dict
return base_validate(path, iteritems(data), out)
File “/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py”, line 386, in validate_mapping
cval = cvalue(key_path, value)
File “/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py”, line 817, in validate_callable
return schema(data)
File “/usr/src/homeassistant/homeassistant/helpers/config_validation.py”, line 470, in verify
return cast(Dict, schema(value))
File “/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py”, line 272, in call
return self._compiled([], data)
File “/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py”, line 594, in validate_dict
return base_validate(path, iteritems(data), out)
File “/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py”, line 386, in validate_mapping
cval = cvalue(key_path, value)
File “/usr/local/lib/python3.8/site-packages/voluptuous/validators.py”, line 215, in _run
return self._exec(self._compiled, value, path)
File “/usr/local/lib/python3.8/site-packages/voluptuous/validators.py”, line 338, in _exec
v = func(path, v)
File “/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py”, line 817, in validate_callable
return schema(data)
File “/usr/src/homeassistant/homeassistant/helpers/config_validation.py”, line 755, in validator
if key in config:
TypeError: argument of type ‘NoneType’ is not iterable

Good afternoon. Did you find out the cause of the errors and correct them?
I have errors after turning on the Maria database size count sensor.
I use Hass.io in Docker on Synology
My config.yaml

  customize: !include_dir_merge_named includes/customize
  
# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Example configuration.yaml entry
# zeroconf:

lovelace:
  mode: yaml

#  SSL
http:
  base_url: https://XXXXXXXXXX
  ssl_certificate: /ssl/fullchain.pem
  ssl_key: /ssl/privkey.pem

# Text to speech
tts:
  - platform: google_translate


#Вынос во внешние файлы
group: !include includes/groups.yaml
script: !include includes/scripts.yaml
scene: !include includes/scenes.yaml
recorder: !include includes/recorder.yaml

#Вынос во внешние папки
automation: !include_dir_merge_list includes/automation
sensor: !include_dir_merge_list includes/sensor

system.yaml

- platform: sql
  db_url: mysql://hass:hass@core-mariadb/homeassistant?charset=utf8
  queries:
    - name: maria_db_size
      query: 'SELECT table_schema "database", Round(Sum(data_length + index_length) / 1048576, 2) "value" FROM information_schema.tables WHERE table_schema="homeassistant" GROUP BY table_schema;'
      column: 'value'
      unit_of_measurement: MB

Errors:

2020-11-30 23:31:53 ERROR (MainThread) [homeassistant.config] Unknown error validating config for template platform for sensor component with PLATFORM_SCHEMA
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config.py", line 831, in async_process_component_config
    p_validated = platform.PLATFORM_SCHEMA(p_config)  # type: ignore
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 594, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 386, in validate_mapping
    cval = cvalue(key_path, value)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 817, in validate_callable
    return schema(data)
  File "/usr/src/homeassistant/homeassistant/helpers/config_validation.py", line 492, in verify
    return cast(Dict, schema(value))
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 594, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 386, in validate_mapping
    cval = cvalue(key_path, value)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/validators.py", line 215, in _run
    return self._exec(self._compiled, value, path)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/validators.py", line 338, in _exec
    v = func(path, v)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 817, in validate_callable
    return schema(data)
  File "/usr/src/homeassistant/homeassistant/helpers/config_validation.py", line 777, in validator
    if key in config:
TypeError: argument of type 'NoneType' is not iterable
2020-11-30 23:57:44 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py", line 422, in _handle_request
    resp = await self._request_handler(request)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_app.py", line 499, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_middlewares.py", line 118, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 18, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 72, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 127, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 129, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/core.py", line 29, in post
    errors = await async_check_ha_config_file(request.app["hass"])
  File "/usr/src/homeassistant/homeassistant/config.py", line 874, in async_check_ha_config_file
    res = await check_config.async_check_ha_config_file(hass)
  File "/usr/src/homeassistant/homeassistant/helpers/check_config.py", line 177, in async_check_ha_config_file
    p_validated = platform_schema(p_validated)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 594, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 386, in validate_mapping
    cval = cvalue(key_path, value)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 817, in validate_callable
    return schema(data)
  File "/usr/src/homeassistant/homeassistant/helpers/config_validation.py", line 492, in verify
    return cast(Dict, schema(value))
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 594, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 386, in validate_mapping
    cval = cvalue(key_path, value)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/validators.py", line 215, in _run
    return self._exec(self._compiled, value, path)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/validators.py", line 338, in _exec
    v = func(path, v)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 817, in validate_callable
    return schema(data)
  File "/usr/src/homeassistant/homeassistant/helpers/config_validation.py", line 777, in validator
    if key in config:
TypeError: argument of type 'NoneType' is not iterable

Please, Help Resolve the Cause of Errors