Config validation error via cli (device_regstry)

So, this is a thing I can’t figure out:

My HA config is running fine, with no errors in home-assistant.log and the UI. When I run “check configuration” in the UI, all is OK, and home assistant stops/starts OK.

Things break when I run ha core check from the CLI:

$ ha core check 
Processing... Done.

Error: Testing configuration at /config
INFO:homeassistant.util.package:Attempting install of integrationhelper>=0.2.2
INFO:homeassistant.util.package:Attempting install of aiogithubapi>=21.2.0
INFO:homeassistant.util.package:Attempting install of hacs_frontend==20210214110032
INFO:homeassistant.util.package:Attempting install of queueman==0.5
ERROR:homeassistant.helpers.check_config:Unexpected error validating config
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/check_config.py", line 147, in async_check_ha_config_file
    await config_validator.async_validate_config(  # type: ignore
  File "/usr/src/homeassistant/homeassistant/components/automation/config.py", line 103, in async_validate_config
    await asyncio.gather(
  File "/usr/src/homeassistant/homeassistant/components/automation/config.py", line 85, in _try_async_validate_config_item
    config = await async_validate_config_item(hass, config, full_config)
  File "/usr/src/homeassistant/homeassistant/components/automation/config.py", line 63, in async_validate_config_item
    config[CONF_TRIGGER] = await async_validate_trigger_config(
  File "/usr/src/homeassistant/homeassistant/helpers/trigger.py", line 49, in async_validate_trigger_config
    conf = await platform.async_validate_trigger_config(hass, conf)
  File "/usr/src/homeassistant/homeassistant/components/device_automation/trigger.py", line 21, in async_validate_trigger_config
    return await getattr(platform, "async_validate_trigger_config")(hass, config)
  File "/usr/src/homeassistant/homeassistant/components/deconz/device_trigger.py", line 412, in async_validate_trigger_config
    device_registry = await hass.helpers.device_registry.async_get_registry()
  File "/usr/src/homeassistant/homeassistant/helpers/device_registry.py", line 615, in async_get_registry
    return async_get(hass)
  File "/usr/src/homeassistant/homeassistant/helpers/device_registry.py", line 599, in async_get
    return cast(DeviceRegistry, hass.data[DATA_REGISTRY])
KeyError: 'device_registry'
Failed config
  automation: 
    - Unexpected error calling config validator: 'device_registry'

Automations are loaded as followed:

$ cat integrations/automation.yaml 
---
automation: !include ../automations.yaml
automation split: !include_dir_list ../automations

The ha core check command runs OK when I remove the automation config.

I’m on 2021.2.3 /w home assistant OS.
Clues are welcome :slight_smile:

I couldn’t make a thing from from the error messages. I knew it was ‘somewhere’ on my automations, but not clear what exactly.

The issue was resolved by running my config on an older HA version (2020.12.1 in stead of 2021.2.3), which gave me a much better to understand error message:

Testing configuration at /config/./
INFO:homeassistant.util.package:Attempting install of integrationhelper>=0.2.2
INFO:homeassistant.util.package:Attempting install of aiogithubapi>=21.2.0
INFO:homeassistant.util.package:Attempting install of awesomeversion>=21.2.2
INFO:homeassistant.util.package:Attempting install of hacs_frontend==20210214110032
INFO:homeassistant.util.package:Attempting install of queueman==0.5
ERROR:homeassistant.config:Invalid config for [automation]:  (See ?, line ?). 
ERROR:homeassistant.config:Invalid config for [automation]:  (See ?, line ?). 
ERROR:homeassistant.config:Invalid config for [automation]:  (See ?, line ?). 
ERROR:homeassistant.config:Invalid config for [automation]:  (See ?, line ?). 
ERROR:homeassistant:Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1395, in async_call
    raise ServiceNotFound(domain, service) from None
homeassistant.exceptions.ServiceNotFound: Unable to find service persistent_notification.create
ERROR:homeassistant:Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1395, in async_call
    raise ServiceNotFound(domain, service) from None
homeassistant.exceptions.ServiceNotFound: Unable to find service persistent_notification.create
ERROR:homeassistant:Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1395, in async_call
    raise ServiceNotFound(domain, service) from None
homeassistant.exceptions.ServiceNotFound: Unable to find service persistent_notification.create
ERROR:homeassistant:Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1395, in async_call
    raise ServiceNotFound(domain, service) from None
homeassistant.exceptions.ServiceNotFound: Unable to find service persistent_notification.create

Thanks Tijnski,

I’ve been using HA for more than 10 years now. I have a lot of yaml and spread out over a bunch of files. Maintaining it becomes increasingly frustrating (there are no decent error messages). Importing is also not supported. That leaves recreating the stuff.
I spent almost a full day to figure out what I did wrong in my configurations with a similar error.

G.

Glad it was useful @gobelijn!
Spot on description. Especially for longer running deployments it becomes less and less feasible to keep configuration in yaml. If things go wrong, error messages are really unclear. The trend seems to be to move stuff to the UI. Too bad for the user base who wants to keep their complete config in version control and use things like CI and automated tests.