Including variables in configuration

Can someone help me, as I’m losing my mind. I’m trying to add a file “variables” which is in the config folder to my “configuration.yaml” file, using “variables: !include variables.yaml” but all I get is error: Configuration warnings Integration error: variables - Integration ‘variables’ not found. when I “check configuration”, any help much appreciated.

At around 11 minutes in the include talks starts.

If that does not help you, then post you configuration.yaml and the variables.yaml
Remember to format it properly (point 11 on How to help us help you - or How to ask a good question)

Please link to the documentation that shows a top-level variables: as being allowed in configuration.yaml.

2 Likes

Good catch!

I’ve installed variables from HACs, and will have an expanding list of variables, but don’t want to fill my configuration.yaml with them, would like to have a file variables.yaml with the variable list, as below

var:
mode:
friendly_name: ‘Mode’
initial_value: ‘Non’
activity:
friendly_name: ‘Activity’
initial_value: ‘Active’
heaterwc:
friendly_name: ‘HeaterWC’
initial_value: ‘Off’

and it run with HA boots up.

Not sure what integration you are using but the one I looked at only had var: as the map entry, so if your variables.yaml start with var: then the entry in configuration should just start with !include

OK, fair.

It’s variable: not variables: you want. The include line would be:

variable: !include variables.yaml

and variables.yaml would start with the name of the first variable.

Hmm, I found two other integrations doing the same, so if the suggestions here does not work, then we better have what version he is using. :slight_smile:

1 Like

Yeah, I see that now. Basically, you’re replacing:

my_heading:
   entry 1
   ...

with

my_heading: !include my_file.yaml

and my_file.yaml starts with

entry1

If I use:

var: !include variables.yaml

get error:

Configuration warnings
Invalid config for ‘var’ at variables.yaml, line 2: ‘x’ is an invalid option for ‘var’, check: var->var->x
Invalid config for ‘var’ at variables.yaml, line 3: ‘mode’ is an invalid option for ‘var’, check: var->var->mode
Invalid config for ‘var’ at variables.yaml, line 6: ‘activity’ is an invalid option for ‘var’, check: var->var->activity
Invalid config for ‘var’ at variables.yaml, line 9: ‘heaterwc’ is an invalid option for ‘var’, check: var->var->heaterwc

It’s like it’s reading the file and doesn’t like the assigned variables, but if I put the same veriable in to the configuration.yaml, don’t get any error

Read my response more carefully. Your included file must not start with var:, because that heading is already in the configuration.yaml file.

var: is not in my configuration.yaml file, I delete that reference before adding the !include statement.

Please update your configuration.yaml with:

var: !include variables.yaml

and make sure your variables.yaml starts with

mode:
  friendly_name: 'Mode'

If that doesn’t pass configuration check, paste the start of configuration.yaml and the start of variables.yaml here, making sure they are correctly-formatted. Use the </> button (might be under the cog) for a code block or surround with three backticks like this:

```
code here
```

that worked, I started mode: with 2 spaces before, as is on configuration.yaml without var:

Thanks for being patient with me, thank you for your time much appreciated

1 Like