flyte / mqtt-io

Expose GPIO modules (Raspberry Pi, Beaglebone, PCF8754, PiFace2 etc.) and digital sensors (LM75 etc.) to an MQTT server for remote control and monitoring.
MIT License
468 stars 157 forks source link

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

Open novski opened 11 months ago

novski commented 11 months ago

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 commented 11 months ago

Found this: https://github.com/flyte/mqtt-io/issues/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?