Configuration
Configuration of sml2mqtt is done through a yaml file.
The path to the file can be specified with -c PATH
or --config PATH
.
If nothing is specified a file with the name config.yml
is searched in the subdirectory sml2mqtt
in
the current working directory
the venv directory
the user home
If a config file is specified and it does not yet exist a default configuration file will be created.
Example
logging:
level: INFO # Log level
file: sml2mqtt.log # Log file path (absolute or relative to config file) or stdout
mqtt:
connection:
identifier: sml2mqtt-ZqlFvhSBdDGvJ
host: localhost
port: 1883
user: ''
password: ''
topic prefix: sml2mqtt
defaults:
qos: 0 # Default value for QOS if no other QOS value in the config entry is set
retain: false # Default value for retain if no other retain value in the config entry is set
last will:
topic: status # Topic fragment for building this topic with the parent topic
general:
Wh in kWh: true # Automatically convert Wh to kWh
republish after: 120 # Republish automatically after this time (if no other filter configured)
inputs:
- type: serial
url: COM1 # Device path
timeout: 3 # Seconds after which a timeout will be detected (default=3)
- type: serial
url: /dev/ttyS0 # Device path
timeout: 3 # Seconds after which a timeout will be detected (default=3)
devices:
# Device configuration by reported id
device_id_hex:
mqtt: # Optional MQTT configuration for this meter.
topic: DEVICE_BASE_TOPIC # Topic fragment for building this topic with the parent topic
status: # Optional MQTT status topic configuration for this meter
topic: status # Topic fragment for building this topic with the parent topic
skip: # OBIS codes (HEX) of values that will not be published (optional)
- '00112233445566'
# Configurations for each of the values (optional)
values:
- obis: '00112233445566' # Obis code for this value
mqtt: # Mqtt config for this value (optional)
topic: OBIS_VALUE_TOPIC # Topic fragment for building this topic with the topic prefix
# A sequence of operations that will be evaluated one after another.
# If one operation blocks nothing will be reported for this frame
operations:
- negative on energy meter status: true # Make value negative based on an energy meter status. Set to "true" to enable or to "false" to disable workaround. If the default obis code for the energy meter is wrong set to the appropriate meter obis code instead
- factor: 3 # Factor with which the value gets multiplied
- offset: 100 # Offset that gets added on the value
- round: 2 # Round to the specified digits
- refresh action: 300 # Republish value every 300s
Example input Tibber bridge
These input settings can be used to poll data from a Tibber bridge:
inputs:
- type: http
url: http://IP_OR_HOSTNAME_OF_TIBBER_BRIDGE/data.json?node_id=1
interval: 3 # Poll interval secs
timeout: 10 # After which time the input will change to TIMEOUT
user: "admin"
password: "printed on bridge socket"
Example mqtt config
MQTT topics can be configured either by providing a full topic or a topic fragment.
With a topic fragment the resulting topic is build with the parent topic.
The structure is topic prefix
/ device
/ value
.
Providing a full topic will ignore the fragments.
The entries for qos and retain are optional.
full topic: my/full/topic
qos: 1
Configuration Reference
All possible configuration options are described here. Not all entries are created by default in the config file and one should take extra care when changing those entries.
- settings Settings
-
field logging:
LoggingSettings
[Optional]
-
field mqtt:
MqttConfig
[Optional]
-
field general:
GeneralSettings
[Optional]
-
field inputs:
list
[HttpSourceSettings
|SerialSourceSettings
] = []
-
field devices:
dict
[Annotated
[str
],SmlDeviceConfig
] = {} Device configuration by ID or url
-
field logging:
logging
general
inputs
- settings SerialSourceSettings
-
-
field url:
Annotated
[str
] [Required] Device path
- Constraints:
strip_whitespace = True
strict = True
min_length = 1
-
field url:
Example:
type: serial
url: COM3
- settings HttpSourceSettings
-
-
field url:
Annotated
[Url
] [Required] Url
- Constraints:
allowed_schemes = [‘http’, ‘https’]
-
field timeout:
Union
[Annotated
[int
],Annotated
[float
]] = 6 Seconds after which a timeout will be detected (default=6)
-
field url:
Example:
type: http
url: http://localhost:8080/sml
interval: 3
timeout: 10
mqtt
- settings MqttConfig
-
field connection:
MqttConnection
[Optional]
-
field topic prefix:
Annotated
[str
] = 'sml2mqtt' Prefix for all topics. Set to empty string to disable
- Constraints:
strict = True
strip_whitespace = True
-
field defaults:
MqttDefaultPublishConfig
[Optional]
-
field last will:
OptionalMqttPublishConfig
[Optional]
-
field connection:
- settings MqttConnection
-
field identifier:
Annotated
[str
] = 'sml2mqtt-tNeMNZrhuwjSQ' - Constraints:
strict = True
strip_whitespace = True
-
field tls:
MqttTlsOptions
|None
= None
-
field identifier:
- settings OptionalMqttPublishConfig
-
field topic:
Optional
[Annotated
[str
]] = None Topic fragment for building this topic with the parent topic
-
field topic:
- settings MqttDefaultPublishConfig
- settings MqttTlsOptions
-
-
field ca certificates:
str
|None
= None Path to Certificate Authority (CA) certificate file in PEM or DER format
-
field certificate requirement:
Optional
[Literal
['NONE'
,'OPTIONAL'
,'REQUIRED'
]] = None Certificate requirement that the client imposes on the broker.
-
field ca certificates:
devices
- settings SmlDeviceConfig
Configuration for a sml device
-
field mqtt:
OptionalMqttPublishConfig
|None
= None Optional MQTT configuration for this meter.
-
field status:
OptionalMqttPublishConfig
= OptionalMqttPublishConfig(topic='status', full_topic=None, qos=None, retain=None) Optional MQTT status topic configuration for this meter
-
field skip:
set
[Annotated
[str
]] [Optional] OBIS codes (HEX) of values that will not be published (optional)
-
field values:
list
[SmlValueConfig
] = [] Configurations for each of the values (optional)
-
field mqtt:
- settings SmlValueConfig
-
field obis:
Annotated
[str
] [Required] Obis code for this value
- Constraints:
strip_whitespace = True
to_lower = True
strict = True
pattern = [0-9a-fA-F]{12}
-
field mqtt:
OptionalMqttPublishConfig
|None
= None Mqtt config for this value (optional)
-
field operations:
Annotated
[list
[Annotated
[Union
[Annotated
[OnChangeFilter
],Annotated
[DeltaFilter
],Annotated
[HeartbeatAction
],Annotated
[RangeFilter
],Annotated
[RefreshAction
],Annotated
[ThrottleFilter
],Annotated
[Factor
],Annotated
[Offset
],Annotated
[Round
],Annotated
[NegativeOnEnergyMeterWorkaround
],Annotated
[Or
],Annotated
[Sequence
],Annotated
[VirtualMeter
],Annotated
[MaxValue
],Annotated
[MinValue
],Annotated
[MaxOfInterval
],Annotated
[MinOfInterval
],Annotated
[MeanOfInterval
]]]]] = [] A sequence of operations that will be evaluated one after another. If one operation blocks this will return nothing.
- Constraints:
min_length = 1
-
field obis: