Creating Local Add-on... How to read options from config.json

Guys, i followed this tut : https://developers.home-assistant.io/docs/add-ons/tutorial

all looks well, except for the options… i want to change the options from the “configuration” page
But how can i read those values with the python script i launch ?

in my Dockerfile i have :

COPY run.sh /
COPY script.py /
COPY config.json /

in my run.sh file i launch the script.py file …, in my script.py file i have

with open("config.json", mode="r") as data_file:
    config = json.load(data_file)

it works, bit it loads the default values already stored in the config.json, not the ones i change when save/change it on the addon configuration save, quite obbvious…

How can i manage this? not sure where i need to read that options with python?, cause its reading the file from the local folder

Hi,

Have a look at the addon configuration code example:

CONFIG_PATH=/data/options.json
TARGET="$(bashio::config 'target')"

This goes in your run.sh
That /data/options.json file gets created automatically when the user sets the config options in the UI, you don’t need to create it.

In your actual addon code you can load it as such:
(i don’t know now any python so this is a javascript example)

const options = require("./options");
console.log(options); // for debugging purpose only

Ah ok, so the options.json file us for the user config? So it’s not the same as the other options.json file where you define the docker options?

Ok, then I still need to find out how i can use them in the python script that’s loaded in my run.sh

There is no options.json file for the addon/docker options. That file is called config.json. Your selfdefined options are an object/field within that file.

omg, rookie mistake :slight_smile:
ok, now gonna search for that python stuff

thnx for pointing me out