Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add and reuse values in config files? #335

Open
novski opened this issue Nov 5, 2023 · 1 comment
Open

How to add and reuse values in config files? #335

novski opened this issue Nov 5, 2023 · 1 comment

Comments

@novski
Copy link

novski commented Nov 5, 2023

I am trying to setup a value that I can reuse in config.
I have multiple sensors and would like them all to have the same interval value.
So I tried to use Jinja2, but the config does not load.
This is my line of code: {% set myinterval = 60 %} and reuse like this {{ myinterval }}.
How can I make a variable available over all config sensor entries?

mqtt:
  host: mypizero2
  port: 1883
  user: ""
  password: ""
  topic_prefix: test
  keepalive: 600
  status_topic: status
  status_payload_running: running
  status_payload_stopped: stopped
  status_payload_dead: dead

{% set interval = 60 %}

sensor_modules:
  - name: a
    module: ds18b
    type: DS18B20
    address: 01131b6c22e4

sensor_modules:
  - name: b
    module: ds18b
    type: DS18B20
    address: 01131b711e04

sensor_inputs:
  - name: a
    module: a
    interval: {{ interval }}
    digits: 2

sensor_inputs:
  - name: b
    module: b
    interval: {{ interval }}
    digits: 2

@novski
Copy link
Author

novski commented Nov 5, 2023

Found this: #209
added this to my supervisor config and then it worked:
command = /home/myuser/mqtt-io/.venv/bin/python -m mqtt_io mqtt-io_config.yaml --render render.yaml

cat ~/mqtt-io/render.yaml
backends:
  my_env:
     type: env

Seams like the pullrequest was integrated, but jinja2 doesn't work by default on my side.
How can I provide more help to debug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant