feat(config)!: Reworked how configuration is loaded

The environment variable `AUTOMATION_CONFIG` has been renamed to
`AUTOMATION__ENTRYPOINT` and can now also be set in `automation.toml` by
specifying:
```
automation = "<path>"
```

Directly accessing the environment variables in lua in no longer
possible. To pass in configuration or secrets you can now instead make
use of the `variables` and `secrets` modules.

To set values in these modules you can either specify them in
`automation.toml`:
```
[variables]
<name> = <value>

[secrets]
<name> = <value>
```
Note that these values will get converted to a string.

You can also specify the environment variables
`AUTOMATION__VARIABLES__<name>` and `AUTOMATION__SECRETS__<name>` to
set variables and secrets respectively. By adding the suffix `__FILE` to
the environment variable name the contents of a file can be loaded into
the variable or secret.

Note that variables and secrets are identical in functionality and the
name difference exists purely to make it clear that secret values are
meant to be kept secret.
This commit is contained in:
2025-09-05 02:46:37 +02:00
parent ba37de3939
commit 8bb17e1440
9 changed files with 172 additions and 26 deletions

View File

@@ -1,16 +1,13 @@
local device_manager = require("device_manager")
local utils = require("utils")
local secrets = require("secrets")
local debug = require("variables").debug or false
print(_VERSION)
local host = utils.get_hostname()
print("Running @" .. host)
local debug, value = pcall(utils.get_env, "DEBUG")
if debug and value ~= "true" then
debug = false
end
local function mqtt_z2m(topic)
return "zigbee2mqtt/" .. topic
end
@@ -28,12 +25,12 @@ local mqtt_client = require("mqtt").new({
port = 8883,
client_name = "automation-" .. host,
username = "mqtt",
password = utils.get_env("MQTT_PASSWORD"),
password = secrets.mqtt_password,
tls = host == "zeus" or host == "hephaestus",
})
local ntfy = Ntfy.new({
topic = utils.get_env("NTFY_TOPIC"),
topic = secrets.ntfy_topic,
})
device_manager:add(ntfy)
@@ -147,7 +144,7 @@ on_light:add(function(light)
end)
local hue_ip = "10.0.0.102"
local hue_token = utils.get_env("HUE_TOKEN")
local hue_token = secrets.hue_token
local hue_bridge = HueBridge.new({
identifier = "hue_bridge",