Evok configuration
Evok configuration is located in /etc/evok/config.yaml. The default configuration is installed by the debian package. To apply the configuration, it is necessary to restart Evok with the command systemctl restart evok.
The configuration directory (with config.yaml, hw_definitions/ and optional autogen.yaml) can be changed with the command line option --config-dir or the environment variable EVOK_CONFIG_DIR, the aliases file with --alias-file or EVOK_ALIAS_FILE. Evok exits with an error if config.yaml is not found.
evok --config-dir ./my-config --alias-file ./alias.yaml
Logging
level- minimum severity of the logged messages (CRITICAL,ERROR,WARNING,INFO,DEBUG, defaultINFO), the option-don the command line setsDEBUGfile- an optional log file, it is rotated daily and 7 old files are kept. Without itGET /logreturns404.
logging:
level: WARNING
file: /var/log/evok.log
API settings
In this section you can configure address and port for API listening. These settings will be applied to protocols REST, JSON, BULK, RPC, WebSocket. The Webhook sends requests to its address and the MQTT API connects to a broker, see their sections.
port- port for API listening (default8080), needs to be changed in/etc/nginx/sites-available/evoktooaddress- address of the interface for API listening,127.0.0.1if the parameter is missing, set it to an empty value to listen on all interfacestoken- an optional token required by all APIs except/version, a long random string, e.g. made byopenssl rand -hex 32. Without it the APIs are not authenticated, use it with an address of the network. See Security for how the clients send it.read_token- an optional second token which allows only reading, it requirestokenand must differ from it. A change of a device with it is refused with the status403.allowed_origins- an optional list of the origins of the web applications on other addresses which use the API from a browser, e.g.["http://192.168.1.10:1880"]. Only they get the CORS headers and can connect to the WebSocket from a browser, a web page of the same address as the API needs no entry.trusted_downstream- an optional list of the addresses or networks of the reverse proxies in front of the API, e.g.["127.0.0.1"]for the nginx of evok-web on the controller. Only the requests from them use the address of the client of their headersX-Forwarded-For(elseX-Real-IP) in the log of Evok, e.g. of a request without the token; another client could forge the headers, they are ignored by default. Evok does not start with an invalidtoken,allowed_originsortrusted_downstream.
RPC
enabled- enables RPC API (true/false), enabled if the section is missing
Websocket
enabled- enables websocket API (true/false, defaultfalse)all_filtered- all WebSocket requests will be subject to the filtering set by 'filter' (true/false, defaultfalse)
Webhook
enabled- enables webhook notifications (true/false, defaultfalse)address- address (with port) to which notifications should be sent (defaulthttp://127.0.0.1:80/index.html)device_mask- list of the device types to notify on, e.g.["di", "wd"](default["di", "sensor", "watchdog"]); the alternative names asinput,wdortempare acceptedcomplex_events- Evok will send POST requests with the same data as WebSocket, rather than an empty GET request without the states (true/false, defaultfalse)min_interval- minimum time between two requests in seconds (default1.0). The changes in the meantime are merged into one request with the last state of each device, only one request is sent at a time. A failed request is not repeated, the next change is sent.
MQTT
The MQTT API, a client of a broker. The options are checked only if it is enabled, Evok does not start with an invalid or unknown option.
enabled- enables the MQTT API (true/false, defaultfalse)hostname- hostname of the broker (default127.0.0.1)port- port of the broker (default1883,8883with TLS)username,password- an optional user of the broker,passwordrequiresusername. Withoutusernameandread_onlyEvok logs a warning that the commands are accepted from any client of the broker.tls- connects by TLS with the certificates of the system (true/false, defaultfalse)ca_file- an optional file of the certificate authority of the broker, it enables TLScert_file,key_file- an optional certificate and key of the client, they enable TLS,key_filerequirescert_fileclient_id- client identifier (defaultevok-<hostname of the unit>), it must be unique on the brokerprefix- the first part of the topics (defaultevok), e.g.evok/boiler-roomfor more units on one broker; it must not contain+or#and must not start or end with/qos- QoS of the published states and the commands (0,1,2, default0)keepalive- keepalive interval in seconds (default60), a lost connection is detected after 1.5 times itdevice_mask- list of the published device types (default all), e.g.["di", "ro", "sensor"], an unknown device type is an errorread_only- Evok does not receive the commands (true/false, defaultfalse)ha_discovery- announces the devices to Home Assistant by the MQTT discovery (true/false, defaultfalse), see Home Assistantha_prefix- the discovery prefix of Home Assistant (defaulthomeassistant), the same rules asprefix
Example
All the sections of the APIs are in apis. Without a section its defaults are used.
apis:
port: 8080
address: '' # all interfaces, 127.0.0.1 if the option is missing
token: 3f6c2a8e5b1d4f7a9c0e2b4d6f8a1c3e5b7d9f0a2c4e6b8d0f1a3c5e7b9d2f4a
read_token: 9a8b7c6d5e4f3a2b1c0d9e8f7a6b5c4d3e2f1a0b9c8d7e6f5a4b3c2d1e0f9a8b
allowed_origins: ["http://192.168.1.10:1880"]
trusted_downstream: ["127.0.0.1"] # nginx of evok-web passes the address of the client
rpc:
enabled: true # default true
websocket:
enabled: true # default false
all_filtered: false
webhook:
enabled: true # default false
address: http://192.168.1.20:8181
device_mask: ["di", "ro", "sensor"]
complex_events: true
min_interval: 1.0
mqtt:
enabled: true
hostname: 192.168.1.10
username: evok
password: secret
prefix: evok/boiler-room
Warning
The tokens and the password above are only examples, make your own tokens, e.g. by openssl rand -hex 32,
and use the password of the user of your broker.
Hardware configuration
The hardware configuration is represented by a device tree with this structure:
comm_channels:
<bus_name>:
type: <bus_type>
<bus specific settings>: <specific parameters>
devices:
<device_name>:
slave-id: <slave_id>
model: <model>
scan_frequency: <scan_frequency>
Bus configuration
- <bus_name> - Your choice, but has to be unique
enabled- an optional parameter, the bus is skipped if it isfalse(Default value istrue)device_info- an optional parameter, describes the controller:family,model,sn,board_count-
typeoptions:MODBUSTCPhostname- hostname of the Modbus server (Default value is127.0.0.1)port- port of the Modbus server (Default value is502)timeout- timeout of a response in seconds (Default value is0.5)connect_timeout- timeout of connecting to the Modbus server in seconds (Default value is1.0)retries- count of retries of a request after a lost connection or a busy unit, an integer>= 0(Default value is1). The bus waits for the retries, a unit which does not respond is scanned less often by Evok.probe_timeout- timeout in seconds of a request to a unit which does not respond, it is sent once without the retries (Default value istimeout)
MODBUSRTUport- path to the Modbus device, required. Only one bus can use a serial port (also by a symlink), the second bus is not created and the error is logged.baudrate- baudrate of the Modbus device (Default value is19200)parity- parity of the Modbus device (N/E/O, Default value isN)stopbits- stop bits of the Modbus device (Default value is1)timeout- timeout of a response in seconds (Default value is0.5)retries- count of retries of a request after a failure of the port or a busy unit, an integer>= 0(Default value is1)probe_timeout- timeout in seconds of a request to a unit which does not respond, it is sent once without the retries (Default value is0.1, at mosttimeout). The other units of the bus wait for it, before a missing unit locked the bus for(retries + 1) * timeoutat every attempt. A longer value is needed if the response of the first register block takes longer at the baud rate, e.g. 125 registers take about 0.15 s at 19200 Bd.
OWFS(1-Wire bus, the former nameOWBUSis not supported) The bus reads the sensors by the 1-Wire subsystem of the kernel (/sys/bus/w1/devices), owserver is not used. The 1-Wire master, e.g. the DS2482 on the I2C bus of the unit, is bound by the kernel (the device tree orecho ds2482 0x18 > /sys/bus/i2c/devices/i2c-N/new_device), the sensors by the modulesw1_therm,w1_ds2438,w1_ds2408,w1_ds2413andw1_ds2406. Without the master Evok logscannot use the 1-Wire master, is its driver loaded (e.g. ds2482)?once and tries again every 10 s.master- the 1-Wire master of the kernel, e.g.w1_bus_master1(Default is the first one). Each OWFS bus needs its own master, the second bus with the same master is not created and the error is logged.interval- interval of values updating in seconds, a positive number (Default value is60). A change by the API sets the interval of all sensors of the bus.scan_interval- interval in seconds of taking the devices found by the kernel, which searches the bus every 10 s;0takes them only after the start and on request (do_scan) (Default value is300). A change by the API applies at once.
With the write access to the master
do_scanforces a search of the bus and the thermometers due at the same time (in the half of their interval) are converted at once, before each one took 750 ms. The attributes of the master are writable only by root, the udev rule60-evok-w1.rulesgives the access to the groupevok; copy it to/etc/udev/rules.d/and apply it byudevadm trigger --subsystem-match=w1 --action=add. Without itdo_scantakes the devices of the last search of the kernel and each thermometer converts alone, Evok logs it once. -owpower- Circuit of owpower device (for restarting bus; optional parameter)
Device configuration
- <device_name>: the device will be available in the API under this name. Has to be unique.
The name of a Modbus device (
MODBUSTCP,MODBUSRTU) has to be unique over all buses, it is the circuit of the device and of all its IOs, e.g.1and'1'are the same name. A device with the name of an already created Modbus device is not created and the error is logged. The name of a 1-Wire sensor has to be unique over all OWFS buses, also against the circuits of the found sensors (the address without the dots, e.g.28A1B2C3D4E5F67B). A configured sensor with the name of an already created sensor is not created and the error is logged, such a found sensor is skipped with a warning. enabled- an optional parameter, the device is skipped if it isfalse(Default value istrue)
MODBUSTCP & MODBUSRTU
model- assigns a Modbus register map (examples:xS51,xS11), see hw_definitions, required. A numeric name must be quoted, e.g.'00', YAML reads00as the number 0 and the model is not found.slave-id- slave address or unit-ID of the Modbus device,1..247on RTU,0..255on TCP (Default value is1). It has to be unique on aMODBUSRTUbus and on a Modbus TCP server (hostnameandport), also when moreMODBUSTCPbuses connect to the same server. A device with the slave-id of an already created device is not created and the error is logged, e.g. after adding a device to a bus with autogenerated devices.scan_frequency- an optional parameter, determines how often values are read from the device per second, a positive number (Default value is 50).scan_enabled- an optional parameter,trueorfalse, the device is not read periodically if it isfalse(Default value istrue). Its devices are created after the first read, their values are then changed only by the writes of Evok. The scan can be enabled or disabled at runtime byPOST /json/modbus_slave/<device_name>withscan_enabled.device_info- an optional parameter, describes the device:family,model,sn,board_count.serial_ports- an optional parameter of a device of aMODBUSTCPbus, the list of the serial ports served by the device, e.g.[/dev/ttyNS0]of the local unit 1 of a Patron M527. TheMODBUSRTUbuses of the ports send no request during the reset and the NV save of the device and 0.5 s after it, a request on the port corrupts the write of the flash of the device (a bug of the firmware). A port of noMODBUSRTUbus is skipped, e.g. a port used by another program. Only the reset and the NV save by Evok hold the buses, not the ones by another Modbus master of the unit, e.g. another client of its Modbus TCP server.autogen.yamlsets it for the boards BRAIN, E4AI4AO4DI5RO, E4AI4AO6DI5RO and E8AI4DI5RO of the controller,/dev/ttyNS0,/dev/ttyNS1... by their order.
OWFS
type- 1-Wire sensor type, required, options: [DS18B20,DS18S20,DS2438,DS2408,DS2406,DS2413]. A sensor with a missing or unknown type is not created and the error is logged. Thevalueof a DS2406 is the state of its channel flip-flops, the kernel does not give the sensed levels.address- 1-Wire device address, the family and the serial number as listed by owserver, e.g.28.4E2025090000; the CRC (28.4E2025090000.FF), the dots and the case are not significant. The name of the device in sysfs (28-00000925204e, the serial number in the reverse order) is the same address. The sensor is read after the kernel finds it, a sensor which the search of the bus has not found is reported aslost.interval- an optional parameter, interval of values updating in seconds (Default value is 15).
Note
It is better to use automatic device search, rather than defining devices manually.
Examples
Every definition must be in comm_channels section.
Modbus RTU device
RS485_1:
type: MODBUSRTU
port: /dev/ttyNS0
baudrate: 19200
parity: 'N'
devices:
xS51:
slave-id: 1
model: xS51
Unit serving a serial port
LOCAL_TCP:
type: MODBUSTCP
hostname: 127.0.0.1
port: 50200
devices:
1:
slave-id: 1
model: '00'
serial_ports: [/dev/ttyNS0] # RS485_1 is held during its reset and NV save
2:
slave-id: 2
model: '13'
serial_ports: [/dev/ttyNS1]
RS485_1:
type: MODBUSRTU
port: /dev/ttyNS0
The port of a unit is shown by sysfs, e.g. /sys/class/tty/ttyNS0/device of the M527 is in iogroup1,
the unit with the slave-id 1.
Modbus TCP device
TCP_EXT:
type: MODBUSTCP
hostname: 192.168.0.54
port: 502
devices:
myIAQ:
slave-id: 1
model: IAQ-TH
1-Wire device
TEMPM:
type: OWFS
interval: 10
scan_interval: 60
owpower: 1
Complete example
A config.yaml without autogen, e.g. prepared for a controller in advance: the local I/Os of a Patron
by its Modbus TCP server, two extensions on the RS485 bus and a thermometer on the 1-Wire bus.
The commented template is examples/config.yaml.
autogen: false
logging:
level: INFO
apis:
port: 8080
address: '' # all interfaces, the token is required
token: 3f6c2a8e5b1d4f7a9c0e2b4d6f8a1c3e5b7d9f0a2c4e6b8d0f1a3c5e7b9d2f4a
read_token: 9a8b7c6d5e4f3a2b1c0d9e8f7a6b5c4d3e2f1a0b9c8d7e6f5a4b3c2d1e0f9a8b
websocket:
enabled: true
comm_channels:
LOCAL_TCP:
type: MODBUSTCP
hostname: 127.0.0.1
port: 50200
device_info:
family: Patron
model: S167
board_count: 1
devices:
'1':
slave-id: 1
model: '00'
RS485_1:
type: MODBUSRTU
port: /dev/ttyNS0
baudrate: 19200
parity: 'N'
devices:
xS51:
slave-id: 1
model: xS51
xS11:
slave-id: 15
model: xS11
OWFS:
type: OWFS
interval: 15
scan_interval: 300
devices:
room:
type: DS18B20
address: 28.95DCD5090000.35
Warning
The tokens above are only examples, make your own, e.g. by openssl rand -hex 32.
Autogen
If the Debian package unipi-os-configurator is installed,
Evok can automatically create the hardware configuration for the running device,
but it works only for Unipi controllers.
You can enable this feature with autogen: true in config.
If this feature is enabled, Evok includes the file autogen.yaml from the configuration directory (/etc/evok/autogen.yaml by default).
This file contains the hardware configuration of the running device.
autogen.yaml is loaded first and config.yaml overrides it: the sections are merged key by key,
a value of config.yaml (also a list) replaces the value of autogen.yaml.
unipi-os-configurator generates this file if a hardware change has been detected.
You can force the creation of this file using this command:
/opt/unipi/tools/os-configurator -f
Autogen rules
- The Bus is always named
LOCAL_TCP. - A device_info section is generated to describe the device. This information is based on
unipiid. - The device name is generated based on the
slave-id. In standard Unipi controllers it is the same as the section number. - The OWFS bus
OWBUSis generated only if the device has the 1-Wire master DS2482, the device tree of the Unipi OS binds it to the driverds2482of the kernel. Evok reads the bus by the kernel, owserver is not used. An OWFS section withhostnameorportof owserver (anautogen.yamlof an older Evok) is an error, the bus is not created; generate the file again. - The
owpowerparameter is defined only if Unipi controller supports this feature. - The port of
LOCAL_TCPisLISTEN_PORTof/etc/default/unipitcp, the Modbus TCP server of the Unipi OS; without it502,50200on Unipi 1. - The boards BRAIN, E4AI4AO4DI5RO, E4AI4AO6DI5RO and E8AI4DI5RO get
serial_ports,/dev/ttyNS0,/dev/ttyNS1... by their order.
evok-autogen.py
unipi-os-configurator runs evok-autogen.py (in hw_definitions of the repository) with the product
in the environment:
UNIPI_PRODUCT_ID- the product id in hex, e.g.0407of the Patron M527, the boards by the tablehw_dataof the script; required.UNIPI_PRODUCT_NAME,UNIPI_PRODUCT_SERIAL- the model and the serial number indevice_info(UNKNOWNwithout them).HAS_DS2482-1if the controller has the 1-Wire master DS2482, the busOWBUSis generated only with it.CARDS- the cards of an Iris or the EMO-R8 of a Unipi 1, asunipi-os-configuratorgives them.
It can be run by hand too, the variables above are set by hand then:
--config-dir(-d) - the directory ofautogen.yamlandhw_definitions(the definitions of the Iris cards), e.g. of Evok in a virtual environment; it must exist (Default value is/etc/evok).--product-id(-p) - the product id in hex instead ofUNIPI_PRODUCT_ID, e.g.0407(or0x0407) of the Patron M527. An invalid id or directory is an error of the arguments, nothing is written.
UNIPI_PRODUCT_NAME=M527 UNIPI_PRODUCT_SERIAL=1234 HAS_DS2482=1 \
python3 evok-autogen.py --config-dir ~/evok/etc --product-id 0407
comm_channels:
LOCAL_TCP:
type: MODBUSTCP
hostname: 127.0.0.1
port: 50200
device_info:
family: Neuron
model: L533
sn: 0
board_count: 3
devices:
1:
slave-id: 1
model: '00'
serial_ports: [/dev/ttyNS0]
2:
slave-id: 2
model: '13'
serial_ports: [/dev/ttyNS1]
3:
slave-id: 3
model: '13'
serial_ports: [/dev/ttyNS2]
OWBUS:
type: OWFS
interval: 10
scan_interval: 60
owpower: 1