Getting started

1. Installation

First install sml2mqtt e.g in a virtual environment.

2. Create default configuration

Run sml2mqtt with a path to a configuration file. A new default configuration file will be created.

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

3. Edit inputs and mqtt

Edit the configuration file and configure the appropriate inputs for serial or http (e.g. for tibber) and edit the mqtt settings.

 1 logging:
 2   level: INFO         # Log level
 3   file: sml2mqtt.log  # Log file path (absolute or relative to config file) or stdout
 4
 5 mqtt:
 6   connection:
 7     identifier: sml2mqtt-ZqlFvhSBdDGvJ
 8     host: localhost
 9     port: 1883
10     user: ''
11     password: ''
12   topic prefix: sml2mqtt
13   defaults:
14     qos: 0         # Default value for QOS if no other QOS value in the config entry is set
15     retain: false  # Default value for retain if no other retain value in the config entry is set
16   last will:
17     topic: status   # Topic fragment for building this topic with the parent topic
18
19 general:
20   Wh in kWh: true       # Automatically convert Wh to kWh
21   republish after: 120  # Republish automatically after this time (if no other filter configured)
22
23 inputs:
24 - type: serial
25   url: COM1   # Device path
26   timeout: 3  # Seconds after which a timeout will be detected (default=3)
27 - type: serial
28   url: /dev/ttyS0   # Device path
29   timeout: 3        # Seconds after which a timeout will be detected (default=3)
30
31 devices:
32   # Device configuration by reported id
33   device_id_hex:
34
35     mqtt:                           # Optional MQTT configuration for this meter.
36       topic: DEVICE_BASE_TOPIC      # Topic fragment for building this topic with the parent topic
37
38     status:                         # Optional MQTT status topic configuration for this meter
39       topic: status                 # Topic fragment for building this topic with the parent topic
40
41     skip:                           # OBIS codes (HEX) of values that will not be published (optional)
42     - '00112233445566'
43
44     # Configurations for each of the values (optional)
45     values:
46
47     - obis: '00112233445566'        # Obis code for this value
48       mqtt:                         # Mqtt config for this value (optional)
49         topic: OBIS_VALUE_TOPIC     # Topic fragment for building this topic with the topic prefix
50       # A sequence of operations that will be evaluated one after another.
51       # If one operation blocks nothing will be reported for this frame
52       operations:
53       - 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
54       - factor: 3               # Factor with which the value gets multiplied
55       - offset: 100             # Offset that gets added on the value
56       - round: 2                # Round to the specified digits
57       - refresh action: 300     # Republish value every 300s

4. Run with analyze

Now run sml2mqtt with the path to the configuration file and the --analyze option. (see command line interface). This will process one sml frame from the meter and report the output. It’s a convenient way to check what values will be reported. It will also show how the configuration changes the reported values when you add an operation.

Check if the meter reports the serial number unter obis 0100000009ff. Example output for the meter data:

 SmlMessage
     transaction_id: 17c77d6b
     group_no      : 0
     abort_on_error: 0
     message_body <SmlOpenResponse>
         codepage   : None
         client_id  : None
         req_file_id: 07ed29cd
         server_id  : 11111111111111111111
         ref_time   : None
         sml_version: None
     crc16         : 25375
 SmlMessage
     transaction_id: 17c77d6c
     group_no      : 0
     abort_on_error: 0
     message_body <SmlGetListResponse>
         client_id       : None
         sever_id        : 11111111111111111111
         list_name       : 0100620affff
         act_sensor_time : 226361515
         val_list: list
             <SmlListEntry>
                 obis           : 8181c78203ff
                 status         : None
                 val_time       : None
                 unit           : None
                 scaler         : None
                 value          : ISK
                 value_signature: None
                 -> (Hersteller-Identifikation)
             <SmlListEntry>
                 obis           : 0100000009ff
                 status         : None
                 val_time       : None
                 unit           : None
                 scaler         : None
                 value          : 11111111111111111111
                 value_signature: None
                 -> (Geräteeinzelidentifikation)
             <SmlListEntry>
                 obis           : 0100010800ff
                 status         : 386
                 val_time       : None
                 unit           : 30
                 scaler         : -1
                 value          : 123456789
                 value_signature: None
                 -> 12345678.9Wh (Zählerstand Total)
             <SmlListEntry>
                 obis           : 0100010801ff
                 status         : None
                 val_time       : None
                 unit           : 30
                 scaler         : -1
                 value          : 123456789
                 value_signature: None
                 -> 12345678.9Wh (Zählerstand Tarif 1)
             <SmlListEntry>
                 obis           : 0100010802ff
                 status         : None
                 val_time       : None
                 unit           : 30
                 scaler         : -1
                 value          : 0
                 value_signature: None
                 -> 0.0Wh (Zählerstand Tarif 2)
             <SmlListEntry>
                 obis           : 0100100700ff
                 status         : None
                 val_time       : None
                 unit           : 27
                 scaler         : 0
                 value          : 555
                 value_signature: None
                 -> 555W (aktuelle Wirkleistung)
             <SmlListEntry>
                 obis           : 8181c78205ff
                 status         : None
                 val_time       : None
                 unit           : None
                 scaler         : None
                 value          : XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
                 value_signature: None
                 -> (Öffentlicher Schlüssel)
         list_signature  : None
         act_gateway_time: None
     crc16         : 22117
 SmlMessage
     transaction_id: 17c77d6d
     group_no      : 0
     abort_on_error: 0
     message_body <SmlCloseResponse>
         global_signature: None
     crc16         : 56696

If the meter does not report 0100000009ff it’s possible to configure another number (of even multiple ones) for configuration matching (see general under config).

5. Edit device settings

Replace device_id_hex in the dummy configuration with the reported number (here 11111111111111111111). Edit the mqtt settings or remove them to use the default. Add the obis code of values that should not be reported to the skip section. Run the analyze command again to see how the reported values change.

 1 # ...
 2
 3 inputs:
 4 - type: serial
 5   url: COM1   # Device path
 6   timeout: 3  # Seconds after which a timeout will be detected (default=3)
 7 - type: serial
 8   url: /dev/ttyS0   # Device path
 9   timeout: 3        # Seconds after which a timeout will be detected (default=3)
10
11 devices:
12   # Device configuration by reported id
13   '11111111111111111111':
14
15     mqtt:                           # Optional MQTT configuration for this meter.
16       topic: meter_light            # Topic fragment for building this topic with the parent topic
17
18     status:                         # Optional MQTT status topic configuration for this meter
19       topic: status                 # Topic fragment for building this topic with the parent topic
20
21     skip:                           # OBIS codes (HEX) of values that will not be published (optional)
22     - '8181c78205ff'
23
24     # Configurations for each of the values (optional)
25     values:
26
27     - obis: '00112233445566'        # Obis code for this value
28       mqtt:                         # Mqtt config for this value (optional)
29         topic: OBIS_VALUE_TOPIC     # Topic fragment for building this topic with the topic prefix
30       # A sequence of operations that will be evaluated one after another.
31       # If one operation blocks nothing will be reported for this frame
32       operations:
33       - 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
34       - factor: 3               # Factor with which the value gets multiplied
35       - offset: 100             # Offset that gets added on the value
36       - round: 2                # Round to the specified digits
37       - refresh action: 300     # Republish value every 300s

6. Edit value settings

It’s possible to further configure how values will be reported. For every value there are multiple operations that can be applied. Each sml value can also be processed multiple times.

Run the analyze command again to see how the reported values change.

 1 # ...
 2
 3 inputs:
 4 - type: serial
 5   url: COM1   # Device path
 6   timeout: 3  # Seconds after which a timeout will be detected (default=3)
 7 - type: serial
 8   url: /dev/ttyS0   # Device path
 9   timeout: 3        # Seconds after which a timeout will be detected (default=3)
10
11 devices:
12   # Device configuration by reported id
13   '11111111111111111111':
14
15     mqtt:                           # Optional MQTT configuration for this meter.
16       topic: meter_light            # Topic fragment for building this topic with the parent topic
17
18     status:                         # Optional MQTT status topic configuration for this meter
19       topic: status                 # Topic fragment for building this topic with the parent topic
20
21     skip:                           # OBIS codes (HEX) of values that will not be published (optional)
22     - '8181c78205ff'
23
24     # Configurations for each of the values (optional)
25     values:
26
27     -  obis: '0100010800ff'    # Obis code for the energy value
28        mqtt:
29          topic: energy_today
30        operations:
31        - type: meter           # A virtual meter
32          start now: true       # Start immediately
33          reset times:          # Reset at midnight
34            - 00:00
35        - round: 1
36        - type: change filter      # Only report on changes
37        - refresh action: 01:00    # ... but refresh every hour
38
39     -  obis: '0100010800ff'  # Obis code for the energy value
40        mqtt:
41          topic: energy_total
42        operations:
43        - round: 1
44        - type: change filter
45        - refresh action: 01:00
46
47     -  obis: '0100100700ff'  # Obis code for the power value
48        mqtt:
49          topic: power
50        operations:
51        - type: delta filter
52          min: 10
53          min %: 5
54        - refresh action: 01:00

Output from the analyze command that shows what values will be reported

...
sml2mqtt/meter_light/energy_today: 0 (QOS: 0, retain: False)
sml2mqtt/meter_light/energy_total: 12345.7 (QOS: 0, retain: False)
sml2mqtt/meter_light/power: 555 (QOS: 0, retain: False)
sml2mqtt/meter_light/status: OK (QOS: 0, retain: False)
...