How to have access to /config from a custom add-on

Hi everyone,

I’m creating a custom HAOS add-on to import water meter readings into Home Assistant. My add-on’s Python script needs to access the Home Assistant SQLite database located at /config/home-assistant_v2.db.

Here’s what I’ve tried so far:

  1. My add-on folder structure:
/config
/addons
    /water_importer
        importer.py
        Dockerfile
        config.yaml
  1. In config.yaml I have:
name: Water importer
slug: water_importer
version: "1.0"
description: ""
hassio_api: true
hassio_role: admin
arch:
  - amd64
  - armv7
  - aarch64
map:
  - config
  1. In importer.py, I test access to the DB:
import os
db_path = "/config/home-assistant_v2.db"
print("Exists?", os.path.exists(db_path))
  1. Output from the add-on logs:
Exists? False

So even though /config/home-assistant_v2.db exists in my Home Assistant host, my add-on cannot see it, and I get sqlite3.OperationalError: unable to open database file when trying to connect.

I have already tried:

  • Restarting the add-on (stop/start)
  • Correcting indentation in config.yaml
  • Using relative paths like ../../config/home-assistant_v2.db

Questions:

  1. How do I correctly mount /config into my HAOS add-on so that Python can access it?
  2. Is there a proper way to reference the Home Assistant DB from inside an add-on?
  3. Are there common pitfalls with map: in HAOS custom add-ons that could cause the folder not to appear?

Any help or examples would be greatly appreciated!

Thanks in advance!

I didn’t find a proper solution to my problem but I’m now using Python Scripts like it is described in this post.

I’m still searching for a solution to create a custom add-on!