spacemanspiff2007/sml2mqtt

Case-sensitive OBIS ID and device assignment

Closed this issue · 4 comments

Part 1:
Case-sensitive:

I noticed that the OBIS assignment must be case-sensitive. However, this is not described.
Example:
I first used the OBIS ID 0100100700FF and didn't get any of it transferred. Only when I changed the identifier to 0100100700ff did the data come. ONLY lower case has worked!

Part 2:
Background info:
I have two Landis Gyr electronic meters. These are each read out with a reading head (USB connection) and pluged into a Raspberry Pi.

As described in the readme, I looked for the server ID for the respective meter from the analysis and entered it in the config.yml.
Here I got a completely strange view in the MQTT.

mqtt

Only much later did I notice that the program only looks at the OBIS ID "0100000009ff". However, since I have a Landis Gyr where this ID can be found under "0100600100ff" I have to use the url -> /dev/ttyUSB0 or ​​/dev/ttyUSB1. Now I got a nice MQTT data stream.
mqtt-2

Until the next reboot of the Raspberry Pi. Here the read heads were initialized in a different order by the OS. So I received the meter reading from the other meter in the MQTT.

so i found the place of wonder.

in the location:
/opt/sml2mqtt/venv/lib/python3.9/site-packages/sml2mqtt/device

in the file:
sml_device.py

i overwrite the old obis-id "0100000009ff" by my energy meter by Landis-Gyr OBIS-ID "0100600100ff".

obis-id-energymeter-landis-gyr

and then i replaced the url for the USB-Connection by the Server-ID from each energy meter - and it works.

Thank you for reporting the issue.
I've created an additional config option in 1.2.1 under general -> device id obis where you can configure an additional serial number that needs to be checked.
Can you verify if that fixes your issue?

Hi spacemanspiff2007,

Today I had the opportunity to test your new version 1.2.1.
I can definitely tell you that it works.

Unfortunately, the entry "device id obis" was not created when the config.yml was automatically created. I had to add this manually afterwards.
How do you have to enter the OBIS ID if you have 2 different meters?

general:
   device id obis: ID#1, ID#2

The OBIS ID 010060320101 should show the manufacturer (in my case) LGZ (stand for Landis+Gyr).
010060320101 is not converted to the corresponding topic (mqtt).
in the config.yml

010060320101:
  mqtt:
    topic: manufacturer

mqtt-sml2mqtt1-2-1

Since I completely deleted the old version and installed the new version, I would like to take the opportunity here and describe the installation routine from my side for a Raspberry Pi.

The first steps are same to your instructions

1. Create working folder
sudo mkdir /opt/sml2mqtt

2. switch to the working folder
cd /opt/sml2mqtt

3. Create virtual environment
sudo python3 -m venv venv

4. Go into folder of virtual environment
cd venv

5. Activate the virtual environment
source bin/activate

6. Installing SML2MQTT
with the commands i had some troubles
python3 -m pip install --upgrade pip sml2mqtt
-> ERROR: Could not install packages due to an EnvironmentError: [Errno 13]

sudo python3 -m pip install --upgrade pip sml2mqtt
-> WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behavior with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

my recommendation
in the folder /opt the command chown
cd /opt/
sudo chown -R pi sml2mqtt

then run the command from the /opt/sml2mqtt/venv directory
cd /opt/sml2mqtt/venv
python3 -m pip install --upgrade pip sml2mqtt

7. default configuration create
sudo sml2mqtt -c /opt/sml2mqtt/config.yml

8. set the configuration of the connection -> configure config.yml

mqtt:
  connections:
    host: Enter the IP address of the MQTT broker*
ports:
- url: /dev/ttyUSB3*
   timeout: 3
- url: /dev/ttyUSB4*
   timeout: 3
  • These are parameters that can be different for each user.
    Let's leave out the other settings for now.

9. Pick up a telegram
i got some Errors when using the command -
sudo sml2mqtt --config /opt/sml2mqtt/ -a
This creates 2 files in the /opt directory and not in /opt/sml2mqtt as desired

So I prefer this command -
sudo sml2mqtt -c /opt/sml2mqtt/config.yml -a
The sml2mqtt.log file is updated now.

10. Analysis of the telegram
Excerpt from the sml2mqtt.log, I have an energy meter from Landis+Gyr e220
...
[2022-10-23 11:52:29,122] [sml.ttyUSB3 ] INFO | val_list:
[2022-10-23 11:52:29,123] [sml.ttyUSB3 ] INFO |
[2022-10-23 11:52:29,125] [sml.ttyUSB3 ] INFO | obis : 010060320101 (1-0:96.50.11)
[2022-10-23 11:52:29,126] [sml.ttyUSB3 ] INFO | status : None
[2022-10-23 11:52:29,127] [sml.ttyUSB3 ] INFO | val_time : None
[2022-10-23 11:52:29,128] [sml.ttyUSB3 ] INFO | unit : None
[2022-10-23 11:52:29,129] [sml.ttyUSB3 ] INFO | scaler : None
[2022-10-23 11:52:29,131] [sml.ttyUSB3 ] INFO | value : LGZ
[2022-10-23 11:52:29,132] [sml.ttyUSB3 ] INFO | value_signature: None
[2022-10-23 11:52:29,133] [sml.ttyUSB3 ] INFO |
[2022-10-23 11:52:29,135] [sml.ttyUSB3 ] INFO | obis : 0100600100ff (1-0:96.1.0
255)
[2022-10-23 11:52:29,136] [sml.ttyUSB3 ] INFO | status : None
[2022-10-23 11:52:29,137] [sml.ttyUSB3 ] INFO | val_time : None
[2022-10-23 11:52:29,138] [sml.ttyUSB3 ] INFO | unit : None
[2022-10-23 11:52:29,140] [sml.ttyUSB3 ] INFO | scaler : None
[2022-10-23 11:52:29,141] [sml.ttyUSB3 ] INFO | value : here is my Energy Meter ID
[2022-10-23 11:52:29,142] [sml.ttyUSB3 ] INFO | value_signature: None
[2022-10-23 11:52:29,143] [sml.ttyUSB3 ] INFO |
[2022-10-23 11:52:29,145] [sml.ttyUSB3 ] INFO | obis : 0100010800ff (1-0:1.8.0255)
[2022-10-23 11:52:29,146] [sml.ttyUSB3 ] INFO | status : 1835268
[2022-10-23 11:52:29,147] [sml.ttyUSB3 ] INFO | val_time : 105346528
[2022-10-23 11:52:29,148] [sml.ttyUSB3 ] INFO | unit : 30
[2022-10-23 11:52:29,149] [sml.ttyUSB3 ] INFO | scaler : -1
[2022-10-23 11:52:29,151] [sml.ttyUSB3 ] INFO | value : 95728959
[2022-10-23 11:52:29,152] [sml.ttyUSB3 ] INFO | value_signature: None
[2022-10-23 11:52:29,153] [sml.ttyUSB3 ] INFO | -> 9572895.9Wh (Zählerstand Total)
[2022-10-23 11:52:29,154] [sml.ttyUSB3 ] INFO |
[2022-10-23 11:52:29,156] [sml.ttyUSB3 ] INFO | obis : 0100020800ff (1-0:2.8.0
255)
[2022-10-23 11:52:29,157] [sml.ttyUSB3 ] INFO | status : None
[2022-10-23 11:52:29,158] [sml.ttyUSB3 ] INFO | val_time : 105346528
[2022-10-23 11:52:29,159] [sml.ttyUSB3 ] INFO | unit : 30
[2022-10-23 11:52:29,161] [sml.ttyUSB3 ] INFO | scaler : -1
[2022-10-23 11:52:29,162] [sml.ttyUSB3 ] INFO | value : 92750
[2022-10-23 11:52:29,163] [sml.ttyUSB3 ] INFO | value_signature: None
[2022-10-23 11:52:29,164] [sml.ttyUSB3 ] INFO | -> 9275.0Wh (Wirkenergie Total)
[2022-10-23 11:52:29,166] [sml.ttyUSB3 ] INFO |
[2022-10-23 11:52:29,167] [sml.ttyUSB3 ] INFO | obis : 0100100700ff (1-0:16.7.0*255)
[2022-10-23 11:52:29,168] [sml.ttyUSB3 ] INFO | status : None
[2022-10-23 11:52:29,169] [sml.ttyUSB3 ] INFO | val_time : None
[2022-10-23 11:52:29,170] [sml.ttyUSB3 ] INFO | unit : 27
[2022-10-23 11:52:29,172] [sml.ttyUSB3 ] INFO | scaler : 0
[2022-10-23 11:52:29,173] [sml.ttyUSB3 ] INFO | value : 161
[2022-10-23 11:52:29,174] [sml.ttyUSB3 ] INFO | value_signature: None
[2022-10-23 11:52:29,176] [sml.ttyUSB3 ] INFO | -> 161W (aktuelle Wirkleistung)
...

From this I determined the most important entries
010060320101 = Manufacturer
0100600100ff = Energy Meter ID
0100010800ff = active energy total incoming
0100020800ff = active energy total outgoing
0100100700ff = current active power

11. Adjust configuration
now edit the configuration file config.yml.
here is my example

logging:
  level: INFO # Log level
  file: sml2mqtt.log # Log file path (absolute or relative to config file)
qtt:
  connections:
    client id: sml2mqtt
    host: ip address from my mqtt broker
    port: 1883
    users: ''
    password: ''
    tls:false
    tls insecure: false
  topic prefix: my/mqqt/tree
  default:
    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 wants:
    topic: status
general:
  Wh to kWh: true # Automatically convert Wh to kWh
  republish after: 3600 # Republish automatically after this time (if no other filter configured)
  device id obis: 0100600100ff
ports:
- url: /dev/ttyUSB3
  timeout: 3
- url: /dev/ttyUSB4
  timeout: 3
devices: # Device configuration by ID or url
  Energy Meter ID (where you find by the obis id 0100600100ff, in my case): #electricity meter heat pump
    mqtt:
      topic: heatpump
    status:
      topic: status
    values:
      010060320101:
        qtt:
          topic: manufacturer
        filters:
        - every: 87840 #87840 corresponds to a day, 3660 to an hour, 60 to a minute
      0100600100ff:
        mqtt:
          topic: serverid
        filters:
        - every: 87840
      0100010800ff:
        mqtt:
          topic: energytotalincoming
        transformations:
        - round: 1
        filters:
        - diff: 1
      0100020800ff:
        mqtt:
          topic: energytotaloutgoing
        transformations:
        - round: 1
        filters:
        - diff: 1
      0100100700ff: #current total active power
        mqtt:
          topic: current total active power
        filters:
        - diff: 1
  Energy Meter ID (where you find by the obis id 0100600100ff, in my case): #Household electricity meter
    mqtt:
      topic: houseelectricity
    status:
      topic: status
    values:
      010060320101:
        mqtt:
          topic: manufacturer
        filters:
        - every: 87840 #87840 corresponds to a day, 3660 to an hour, 60 to a minute
      0100600100ff:
        mqtt:
          topic: serverid
        filters:
        - every: 87840
      0100010800ff:
        mqtt:
          topic: energytotalincoming
        transformations:
        - round: 1
        filters:
        - diff: 1
      0100020800ff:
        mqtt:
          topic: energytotaloutgoing
        transformations:
        - round: 1
        filters:
        - diff: 1
      0100100700ff: #current total active power
        mqtt:
          topic: current total active power
        filters:
        - diff: 1

12. Testing
sml2mqtt -c /opt/sml2mqtt/config.yml
Now the program is running and you can read the messages with an MQTT program (e.g. MQTT Explorer).

13. Setting Up the Service
sudo nano /etc/systemd/system/sml2mqtt.service

[unit]
Description=sml2mqtt
Documentation=https://github.com/spacemanspiff2007/sml2mqtt
After=network-online.target

[Service]
type=simple
User=pi
Group=pi
Restart=on failure
RestartSec=2min
ExecStart=/opt/sml2mqtt/venv/bin/sml2mqtt -c /opt/sml2mqtt/config.yml

[Install]
WantedBy=multi-user.target

I have adapted the user and the group (to the Raspberry Pi).

14. Start service
sudo systemctl --system daemon-reload
sudo systemctl enable sml2mqtt.service

From this overview block of the possible commands, I only use the start at the beginning and then the status.
sudo systemctl start sml2mqtt.service
sudo systemctl stop sml2mqtt.service
sudo systemctl restart sml2mqtt.service
sudo systemctl status sml2mqtt.service

@Xtremdiver I've implemented case-insensitive obis in the rewrite. You can find more information here
I'd love to get feedback, too.
Since this is or will soon be obsolete I'll close this one but feel free to create a new issue.