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.