Vzlogger - openhab3 - mqtt how to

Hi all,

I integrated my Powermeter in openhab 3 and send the data via mqtt.
After sending the data, I create hourly and dayly statistics. They are also sent to an Influxdb for grafana.

Perhaps this is interesting for somebody:

vzlogger:

/**
 * vzlogger configuration
 *
 * Use properly encoded JSON with javascript comments
 *
 * Take a look at the wiki for detailed information:
 * http://wiki.volkszaehler.org/software/controller/vzlogger#configuration
 *
 * For an online configuration editor refer to:
 * http://volkszaehler.github.io/vzlogger/
 */

{
    // General settings
    "daemon": true,        // run periodically
    "verbosity": 5,         // log verbosity (0=log_alert, 1=log_error, 3=log_warning, 5=log_info, 10=log_debug, 15=log_finest)
    "log": "/var/log/vzlogger.log", // log file, optional
    "retry": 30,            // http retry delay in seconds

    // Build-in HTTP server
    "local": {
        "enabled": true,   // enable local HTTPd for serving live readings
        "port": 8080,       // TCP port for local HTTPd
        "index": true,      // provide index listing of available channels if no UUID was requested
        "timeout": 30,      // timeout for long polling comet requests in seconds (0 disables comet)
        "buffer": -1        // HTTPd buffer configuration for serving readings, default -1
                            //   >0: number of seconds of readings to serve
                            //   <0: number of tuples to server per channel (e.g. -3 will serve 3 tuples)
    },

    // realtime notification settings
    "push": [
        {
            "url": "http://127.0.0.1:5582"  // notification destination, e.g. frontend push-server
        }
    ],

    // mqtt client support (if ENABLE_MQTT set at cmake generation)
    "mqtt": {
        "enabled": true,  // enable mqtt client. needs host and port as well
        "host": "192.168.250.20", // 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": "vzlogger/data", // optional topic dont use $ at start and no / at end
        "user": "", // optional user name for the mqtt server
        "pass": "", // 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
    },


    // Meter configuration
    "meters": [

//Normalstrom

        {
        "enabled" : true,
        "device" : "/dev/ttyUSB0",
        "protocol" : "sml",
        "parity" : "8N1",
        "baudrate" : 9600,
        "aggtime" : 60,
        "aggfixedinterval" : true,
        "channels": [{
        "uuid" : "21319e00-a389-11e7-8e90-e5e2c7b8a71e",
            "middleware" : "http://localhost/middleware.php",
            "identifier" : "1-0:1.8.0",
            "aggmode" : "MAX"
            }]
        },


//Heizung

        {
        "enabled" : true,
        "device" : "/dev/ttyUSB1",
        "protocol" : "sml",
        "parity" : "8N1",
        "baudrate" : 9600,
        "aggtime" : 60,
        "aggfixedinterval" : true,
        "channels": [{
            "uuid" : "64c5e3c0-a67d-11e7-8bef-d9dfee017ace",
            "middleware" : "http://localhost/middleware.php",
            "identifier" : "1-0:1.8.1",
            "aggmode" : "MAX"
            }]
        }

    ]
}

Rules for statistics:

rule "Tageverbrauch_Normalstrom_letzter_Tag"
	when
		Time cron "1 59 23 ? * * *"
	then
		Tagesverbrauch_Normalstrom.postUpdate (StromzahlerHaushalt_GesamtverbrauchHaushalt.deltaSince(now.minusDays(1)).floatValue)
end

rule "Stundenverbrauch_Normalstrom_letzte_Stunde"
	when
		Time cron "1 59 * ? * * *"
	then
		Stundenverbrauch_Normalstrom.postUpdate (StromzahlerHaushalt_GesamtverbrauchHaushalt.deltaSince(now.minusHours(1)).floatValue)
end

rule "Tageverbrauch_Heizstrom_letzter_Tag"
	when
		Time cron "1 59 23 ? * * *"
	then
		Tagesverbrauch_Heizstrom.postUpdate (StromzahlerHaushalt_GesamtverbrauchHeizung.deltaSince(now.minusDays(1)).floatValue)
end

rule "Stundenverbrauch_Heizstrom_letzte_Stunde"
	when
		Time cron "1 59 * ? * * *"
	then
		Stundenverbrauch_Heizstrom.postUpdate (StromzahlerHaushalt_GesamtverbrauchHeizung.deltaSince(now.minusHours(1)).floatValue)
end

image

1 Like

Thank you, I have also implemented this (according to your instructions).
Can you post the code for the BarChart? I don’t have any columns but only an area - and “barWidth” as a parameter doesn’t change anything.

vzlogger has to be rebuilt as the mqtt client feature is not implemented in the standard version shipped inside the Raspberry Pi image.

Luckily, all that has to be done is following instructions at GitHub - volkszaehler/vzlogger: Logging utility for various meters & sensors, that is: get build prequerities for debian, get libmosquitto-dev, download build-script and process installation.

Hi Florian,
I found your thread belongs to vzlogger via mqtt into openhab. I like to go the same way but still testing / gambling with the settings.
Can you provide the configuration files you use?
best regards
Ralf

Hi Ralf,

the config files are in the first Post.
It is just the vzlogger.conf.

Do you need something else?

Flo

Hi Florian,
thank you for the quick response. It was the openhab configuration and the vzlogger.conf.

I the meantime i found an excellent post in the photovoltaikforum . It help me to start with some settings.

But I like to see your items and things file too.

In my vzlogger.conf file I removed the section “push” for “realtime notification”. I am on the way to move all my “services” (database, openhab, mqtt, vzlogger etc) into docker container. Therefore I use a docker vzlogger container. It force me to have keep the middleware line. But I don’t use a middleware, because the data flow is directly to mqtt. What’s your opinion. In the example of the photovoltaik form the done have the line “middleware…”

best regards
Ralf

Thing topic Zaehlerstand "Zaehlerstand" {
Channels:
    Type number : zaehler_heizung       "Zaehler Heizung"                [ stateTopic="vzlogger/data/chn0/agg"]
    Type number : zaehler_haushalt      "Zaehler Haushalt"               [ stateTopic="vzlogger/data/chn2/agg"]
    Type number : zaehler_Einspeisung   "Zaehler Einspeisung"            [ stateTopic="vzlogger/data/chn1/agg"]