Hi,
these are the steps to install vzlogger on an Orange Pi Zero by using a volkszaehler TTL device as interface to get the measures of the electricity meter. Connect the Output to the Pin 10/GPIO199/UART1_RX
First of all install Armbian .
Enable UART1. Open /boot/armbianEnv.txt and add the device tree overlay.
overlay_prefix=sun8i-h3 overlays=uart1
Reboot the PC. If the volkszaehler TTL interface is already connected you can check if data are received.
Install python serial and start python
root@debdev ~ # apt install python3-serial root@debdev ~ # python3
Enter the following code
import serial # Serielle Schnittstelle konfigurieren ser = serial.Serial('/dev/ttyS1', 9600, timeout=1) while True: data = ser.read(16) # Read 16 Bytes if data: print(data.hex()) # print Bytes as Hex
This should be shown something like this:
77070100100700ff0101621b52005900 000000000000060177070100240700ff 0101621b520059000000000000000601 77070100380700ff0101621b52005900 0000000000000001770701004c0700ff 0101621b520059000000000000000001 77070100200700ff0101622352ff6900 000000000009490177070100340700ff 0101622352ff69000000000000094a01 77070100480700ff0101622352ff6900 0000000000094701770701001f0700ff 0101622152fe69000000000000000401
Download, build and install vzlogger
root@debdev ~ #apt-get install extrace git-core cmake libtool dh-autoreconf uuid-dev libmicrohttpd-dev \ build-essential pkg-config libgnutls28-dev libssl-dev libmosquitto-dev libgcrypt20-dev libcurl3-dev \ libunistring-dev libssl-dev libsasl2-dev libcurl4-openssl-dev uuid-dev libtool libltdl-dev root@debdev ~ # mkdir ~/software root@debdev ~ # cd ~/software root@debdev ~ # export CMAKE_INSTALL_PREFIX=/usr/local root@debdev ~ # wget https://raw.github.com/volkszaehler/vzlogger/master/install.sh root@debdev ~ # bash install.sh vzlogger libjson libsml mqtt
Create a user vzlogger and add it to the dialout group to get access to the serial device(s)
root@debdev ~ # useradd -r -s /sbin/nologin vzlogger root@debdev ~ # usermod -a -G vzlogger vzlogger root@debdev ~ # usermod -a -G dialout vzlogger
Edit /etc/systemd/system/vzlogger.service and adjust as seen below
vi /etc/systemd/system/vzlogger.service [Unit] Description=vzlogger After=syslog.target network.target [Service] User=vzlogger Group=vzlogger ExecStart=/usr/local/bin/vzlogger -c /etc/vzlogger.conf ExecReload= StandardOutput=null ExecStartPre=-/usr/bin/mkdir -p /var/log/vzlogger ExecStartPre=-/usr/bin/chown vzlogger:vzlogger/var/log/vzlogger [Install] WantedBy=multi-user.target
Add als the following lines to /etc/rc.local (before exit 0 :-))
/usr/bin/mkdir -p /var/log/vzlogger /usr/bin/chown volkszaehler:volkszaehler /var/log/vzlogger
then you have to define your Smartmeter/electricity meter config. For me a EFR SGM-C8.
Create a file /etc/vzlogger.conf
{ "retry" : 0, /* how long to sleep between failed requests, in seconds */ "verbosity" : 15, /* between 0 and 15 */ "log" : "/var/log/vzlogger/vzlogger.log",/* path to logfile, optional */ "local" : { "enabled" : true, /* should we start the local HTTPd for serving live readings? */ "port" : 8081, /* the TCP port for the local HTTPd */ "index" : true, /* should we provide a index listing of available channels? */ "timeout" : 30, /* timeout for long polling comet requests, 0 disables comet, in seconds */ "buffer" : 600, /* how long to buffer readings for the local interface, in seconds */ }, // mqtt client support (if ENABLE_MQTT set at cmake generation) "mqtt": { "enabled": true, // enable mqtt client. needs host and port as well "host": "10.10.254.100", // mqtt server addr "port": 1883, // 1883 for unencrypted, 8883 enc, 8884 enc cert needed, "cafile": "", // optional file with server CA "capath": "", // optional path for server CAs. see mosquitto.conf. Specify only cafile or capath "certfile": "", // optional file for your client certificate (e.g. client.crt) "keyfile": "", // optional path for your client certficate private key (e.g. client.key) "keypass": "", // optional password for your private key "keepalive": 30, // optional keepalive in seconds. "topic": "home/stromzaehler", // optional topic dont use $ at start and no / at end "id": "", // optional static id, if not set "vzlogger_<pid>" will be used "user": "user", // optional user name for the mqtt server "pass": "mqttpw", // optional password for the mqtt server "retain": false, // optional use retain message flag "rawAndAgg": false, // optional publish raw values even if agg mode is used "qos": 0, // optional quality of service, default is 0 "timestamp": false // optional whether to include a timestamp in the payload }, "meters" : [ { // EFR SGM-C8 "enabled" : true, /* disabled meters will be ignored */ "protocol" : "sml", /* use 'vzlogger -h' for list of available protocols */ "device" : "/dev/ttyS1", // Serial device "parity": "8N1", "baudrate": 9600, "interval": 10, "aggtime":30, // aggrate for 30sec and then send "use_local_time": true, "channels": [ { "uuid": "034a512b-3958-4d74-a58b-caa297c6f28c", //Powershell [system.guid]::NewGuid().Guid | Set-Clipboard "identifier": "1-0:1.8.0", "api": "null", // Nur MQTT https://wiki.volkszaehler.org/software/controller/vzlogger/vzlogger_conf_parameter#channels "middleware": "http://localhost", "aggmode": "max", // Possible avg, max, none "duplicates": 60 }, { "uuid": "e0d53b6d-45d7-483e-b3f0-da6832c9843b", "identifier": "1-0:2.8.0", "api": "null", // Nur MQTT https://wiki.volkszaehler.org/software/controller/vzlogger/vzlogger_conf_parameter#channels "middleware": "http://localhost", "aggmode": "max", // Possible avg, max, none "duplicates": 60 }, { "uuid": "c0398814-e358-405c-8ae7-1ea1ccf34882", "identifier": "1-0:16.7.0", "api": "null", // Nur MQTT https://wiki.volkszaehler.org/software/controller/vzlogger/vzlogger_conf_parameter#channels "middleware": "http://localhost", "aggmode": "max", // Possible avg, max, none "duplicates": 60 }, { "uuid": "26d47a34-ca49-4941-8459-ba82a6427f40", "identifier": "1-0:36.7.0", "api": "null", // Nur MQTT https://wiki.volkszaehler.org/software/controller/vzlogger/vzlogger_conf_parameter#channels "middleware": "http://localhost", "aggmode": "max", // Possible avg, max, none "duplicates": 60 }, { "uuid": "3460a86e-de8b-4168-b058-57933e8995ca", "identifier": "1-0:56.7.0", "api": "null", // Nur MQTT https://wiki.volkszaehler.org/software/controller/vzlogger/vzlogger_co> "middleware": "http://localhost", "aggmode": "max", // Possible avg, max, none "duplicates": 60 }, { "uuid": "2bd577a9-5b61-445d-aaaf-47ad664e8a94", "identifier": "1-0:76.7.0", "api": "null", // Nur MQTT https://wiki.volkszaehler.org/software/controller/vzlogger/vzlogger_conf_parameter#channels "middleware": "http://localhost", "aggmode": "max", // Possible avg, max, none "duplicates": 60 }, { "uuid": "9d6c3b8b-c4b8-469d-94d8-fb85c4e8caba", "identifier": "1-0:32.7.0", "api": "null", // Nur MQTT https://wiki.volkszaehler.org/software/controller/vzlogger/vzlogger_conf_parameter#channels "middleware": "http://localhost", "aggmode": "max", // Possible avg, max, none "duplicates": 60 }, { "uuid": "3008ee57-06c6-4f47-a426-2996126e5fb9", "identifier": "1-0:52.7.0", "api": "null", // Nur MQTT https://wiki.volkszaehler.org/software/controller/vzlogger/vzlogger_conf_parameter#channels "middleware": "http://localhost", "aggmode": "max", // Possible avg, max, none "duplicates": 60 }, { "uuid": "3d05b927-45a1-4dd8-bc29-b57d07fb6c11", "identifier": "1-0:72.7.0", "api": "null", // Nur MQTT https://wiki.volkszaehler.org/software/controller/vzlogger/vzlogger_conf_parameter#channels "middleware": "http://localhost", "aggmode": "max", // Possible avg, max, none "duplicates": 60 }, { "uuid": "9bfc0a8b-7a4e-420a-a8fb-c8a125c1b4aa", "identifier": "1-0:31.7.0", "api": "null", // Nur MQTT https://wiki.volkszaehler.org/software/controller/vzlogger/vzlogger_conf_parameter#channels "middleware": "http://localhost", "aggmode": "max", // Possible avg, max, none "duplicates": 60 }, { "uuid": "3739a365-96f7-4e4c-bfa5-c4e7c6766430", "identifier": "1-0:51.7.0", "api": "null", // Nur MQTT https://wiki.volkszaehler.org/software/controller/vzlogger/vzlogger_conf_parameter#channels "middleware": "http://localhost", "aggmode": "max", // Possible avg, max, none "duplicates": 60 }, { "uuid": "3cae1182-b5ae-43b0-b924-52cf17a21853", "identifier": "1-0:71.7.0", "api": "null", // Nur MQTT https://wiki.volkszaehler.org/software/controller/vzlogger/vzlogger_conf_parameter#channels "middleware": "http://localhost", "aggmode": "max", // Possible avg, max, none "duplicates": 60 }, { "uuid": "3e9463b5-7319-403e-a597-0b02b580f0c4", "identifier": "1-0:81.7.1", "api": "null", // Nur MQTT https://wiki.volkszaehler.org/software/controller/vzlogger/vzlogger_conf_parameter#channels "middleware": "http://localhost", "aggmode": "max", // Possible avg, max, none "duplicates": 60 }, { "uuid": "c9520c8b-8341-437d-af88-c82a2325c9c2", "identifier": "1-0:81.7.2", "api": "null", // Nur MQTT https://wiki.volkszaehler.org/software/controller/vzlogger/vzlogger_conf_parameter#channels "middleware": "http://localhost", "aggmode": "max", // Possible avg, max, none "duplicates": 60 }, { "uuid": "270d1a11-f458-4a43-8f1c-301578eed7dd", "identifier": "1-0:81.7.4", "api": "null", // Nur MQTT https://wiki.volkszaehler.org/software/controller/vzlogger/vzlogger_conf_parameter#channels "middleware": "http://localhost", "aggmode": "max", // Possible avg, max, none "duplicates": 60 }, { "uuid": "ee2140ec-a9a7-423b-b565-26ddefe20303", "identifier": "1-0:81.7.15", "api": "null", // Nur MQTT https://wiki.volkszaehler.org/software/controller/vzlogger/vzlogger_conf_parameter#channels "middleware": "http://localhost", "aggmode": "max", // Possible avg, max, none "duplicates": 60 }, { "uuid": "7a2c975a-af19-41c7-887e-6097d0590f70", "identifier": "1-0:81.7.26", "api": "null", // Nur MQTT https://wiki.volkszaehler.org/software/controller/vzlogger/vzlogger_conf_parameter#channels "middleware": "http://localhost", "aggmode": "max", // Possible avg, max, none "duplicates": 60 }, { "uuid": "60aef602-d242-4bf2-af0d-86b7077ca917", "identifier": "1-0:14.7.0", "api": "null", // Nur MQTT https://wiki.volkszaehler.org/software/controller/vzlogger/vzlogger_conf_parameter#channels "middleware": "http://localhost", "aggmode": "max", // Possible avg, max, none "duplicates": 60 } ] } ] }
Enable and start vzlooger
root@debdev ~ # systemctl enable vzlogger root@debdev ~ # systemctl start vzlogger
To integrate vzlogger into homeassistant define a sensor for each topic. Import is to add a device_class and unit_of_measurement property to the energy values so that a statistic is gernerated.
Create a file mqtt.yaml
# MQTT # Units of measure https://github.com/home-assistant/core/blob/d7ac4bd65379e11461c7ce0893d3533d8d8b8cbf/homeassistant/const.py#L384 # https://www.home-assistant.io/integrations/sensor/#device-class # https://www.home-assistant.io/docs/energy/faq/#troubleshooting-missing-entities sensor: # 1-0:1.8.0 - name: "Hausstrom: Zaehlerstand Bezug" state_topic: "home/stromzaehler/chn0/agg" unit_of_measurement: "Wh" device_class: "energy" state_class: "total_increasing" unique_id: "home_energy.sumpower" # 1-0:2.8.0 - name: "Hausstrom: Zaehlerstand Einspeisung" state_topic: "home/stromzaehler/chn1/agg" unit_of_measurement: "Wh" device_class: "energy" state_class: "total_increasing" # 1-0:16.7.0 - name: "Hausstrom: Wirkleistung gesamt" state_topic: "home/stromzaehler/chn2/agg" unit_of_measurement: "W" # 1-0:36.7.0 - name: "Hausstrom: Wirkleistung L1" state_topic: "home/stromzaehler/chn3/agg" # device_class: "energy" unit_of_measurement: "W" # 1-0:56.7.0 - name: "Hausstrom: Wirkleistung L2" state_topic: "home/stromzaehler/chn4/agg" unit_of_measurement: "W" # 1-0:76.7.0 - name: "Hausstrom: Wirkleistung L3" state_topic: "home/stromzaehler/chn5/agg" unit_of_measurement: "W" # 1-0:32.7.0 - name: "Hausstrom: Spannung L1" state_topic: "home/stromzaehler/chn6/agg" unit_of_measurement: "V" # 1-0:52.7.0 - name: "Hausstrom: Spannung L2" state_topic: "home/stromzaehler/chn7/agg" unit_of_measurement: "V" # 1-0:72.7.0 - name: "Hausstrom: Spannung L3" state_topic: "home/stromzaehler/chn8/agg" unit_of_measurement: "V" # 1-0:31.7.0 - name: "Hausstrom: Strom L1" state_topic: "home/stromzaehler/chn9/agg" unit_of_measurement: "A" # 1-0:51.7.0 - name: "Hausstrom: Strom L2" state_topic: "home/stromzaehler/chn10/agg" unit_of_measurement: "A" # 1-0:71.7.0 - name: "Hausstrom: Strom L3" state_topic: "home/stromzaehler/chn11/agg" unit_of_measurement: "A" # 1-0:81.7.1 - name: "Hausstrom: Phasenwinkel U L2 zu L1" state_topic: "home/stromzaehler/chn12/agg" unit_of_measurement: "°" # 1-0:81.7.2 - name: "Hausstrom: Phasenwinkel U L2 zu L1" state_topic: "home/stromzaehler/chn13/agg" unit_of_measurement: "°" # 1-0:81.7.4 - name: "Hausstrom: Phasenwinkel L1 I zu U" state_topic: "home/stromzaehler/chn14/agg" unit_of_measurement: "°" # 1-0:81.15.4 - name: "Hausstrom: Phasenwinkel L2 I zu U" state_topic: "home/stromzaehler/chn15/agg" unit_of_measurement: "°" # 1-0:81.7.26 - name: "Hausstrom: Phasenwinkel L3 I zu U" state_topic: "home/stromzaehler/chn16/agg" unit_of_measurement: "°" # 1-0:14.7.0 - name: "Hausstrom: Netzfrequenz" state_topic: "home/stromzaehler/chn17/agg" unit_of_measurement: "Hz"
and include it to configuration.yaml
mqtt: !include mqtt.yaml