Skip to content

Commit

Permalink
Seperated the Configurations and checked with d0 protocoll (#2)
Browse files Browse the repository at this point in the history
* Added "mqtt_timestamp" and "meter_interval"
* Version increased to 0.9.1
* Added independend config for meter 2
  • Loading branch information
seppelw authored Sep 1, 2021
1 parent 6431a2f commit 928022b
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 59 deletions.
25 changes: 16 additions & 9 deletions vzlogger2mqtt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,38 @@ MQTT password to access broker (you should setup your broker to require this!)

Prefix for MQTT topic to send information (default: vzlogger/data)

### meter_protocol (str)
### mqtt_timestamp (bol)

Protocol for meter, currently only sml
Add Timestamp to MQTT message (default: false)

### meter_parity (str)
### meter1_protocol / meter2_protocol (str)

Protocol for meter, currently only sml and d0 are confirmed working

### meter1_parity / meter2_parity (str)

Parity setting for meter (default: 8N1)

### meter_baudrate (int)
### meter1_baudrate / meter2_baudrate (int)

Baudrate for meter (default: 9600)

### meter_aggtime (int)
### meter1_aggtime / meter2_aggtime (int)

Time in seconds to aggregate meter data before sending (default: 10)

### meter_device (str)
### meter1_interval / meter2_interval (int)

Time in seconds between accesing a pull meter in seconds. Make sure that the time for the meter to respond is sufficient, even at low read speeds. Recommendatation for push-meters: "-1".

### meter1_device (str)

Device name for IR reader on host OS, e.g.:
`/dev/serial/by-id/usb-FTDI_FT230X_Basic_UART_D1234567A-if00-port0`

### meter_device2 (str)
### meter2_device (str)

Second device if available. Currently only max of 2 identical devices are supported,
this means that meter settings (protocol, parity, ... and channel info) need to be identical.
Second device if available. Currently only max of 2 devices are supported.

### channels (list of dict)

Expand Down
54 changes: 38 additions & 16 deletions vzlogger2mqtt/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vzlogger to MQTT Gateway",
"version": "0.9.0",
"version": "0.9.1",
"slug": "vzlogger2mqtt",
"description": "vzlogger - Read your Smart Meter",
"url": "https://github.com/m-reuter/ha-addons/tree/master/vzlogger2mqtt",
Expand All @@ -16,30 +16,52 @@
"mqtt_username": "",
"mqtt_password": "",
"mqtt_topic": "vzlogger/data",
"meter_protocol": "sml",
"meter_parity": "8N1",
"meter_baudrate": 9600,
"meter_aggtime": 10,
"meter_device" : "",
"meter_device2" : "",
"channels" : [
"mqtt_timestamp": "false",
"meter1_protocol": "sml",
"meter1_parity": "8N1",
"meter1_baudrate": 9600,
"meter1_aggtime": 10,
"meter1_interval": 0,
"meter1_device" : "",
"meter1_channels" : [
{ "identifier": "1-0:16.7.0*255", "aggmode": "avg" },
{ "identifier": "1-0:1.8.0*255", "aggmode": "max" }
]},
],
"meter2_protocol": "sml",
"meter2_parity": "8N1",
"meter2_baudrate": 9600,
"meter2_aggtime": 0,
"meter2_interval": 10,
"meter2_device" : "",
"meter2_channels" : [
{ "identifier": "1-0:16.7.0*255", "aggmode": "avg" },
{ "identifier": "1-0:1.8.0*255", "aggmode": "max" }
]
},
"schema": {
"verbosity": "int",
"mqtt_broker": "str",
"mqtt_port": "port",
"mqtt_username": "str?",
"mqtt_password": "password?",
"mqtt_topic": "str",
"meter_protocol": "str",
"meter_parity": "str",
"meter_baudrate": "int",
"meter_aggtime": "int",
"meter_device": "str",
"meter_device2": "str?",
"channels" : [
"mqtt_timestamp":"bool",
"meter1_protocol": "str",
"meter1_parity": "str",
"meter1_baudrate": "int",
"meter1_aggtime": "int",
"meter1_interval": "int",
"meter1_device": "str",
"meter1_channels" : [
{ "identifier": "str", "aggmode": "str" }
],
"meter2_protocol": "str",
"meter2_parity": "str?",
"meter2_baudrate": "int?",
"meter2_aggtime": "int?",
"meter2_interval": "int?",
"meter2_device": "str?",
"meter2_channels" : [
{ "identifier": "str", "aggmode": "str" }
]
},
Expand Down
63 changes: 43 additions & 20 deletions vzlogger2mqtt/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,74 @@

CONFIG_PATH=/data/options.json

# Settings for pyhpsu.conf
# Settings for vzlogger.conf
VERBOSITY="$(bashio::config 'verbosity')"
MQTT_BROKER="$(bashio::config 'mqtt_broker')"
MQTT_PORT="$(bashio::config 'mqtt_port')"
MQTT_USERNAME="$(bashio::config 'mqtt_username')"
MQTT_PASSWORD="$(bashio::config 'mqtt_password')"
MQTT_TOPIC="$(bashio::config 'mqtt_topic')"
MQTT_TIMESTAMP="$(bashio::config 'mqtt_timestamp')"

METER1_PROTOCOL="$(bashio::config 'meter1_protocol')"
METER1_PARITY="$(bashio::config 'meter1_parity')"
METER1_BAUDRATE="$(bashio::config 'meter1_baudrate')"
METER1_AGGTIME="$(bashio::config 'meter1_aggtime')"
METER1_INTERVAL="$(bashio::config 'meter1_interval')"
METER1_DEVICE="$(bashio::config 'meter1_device')"

METER2_PROTOCOL="$(bashio::config 'meter2_protocol')"
METER2_PARITY="$(bashio::config 'meter2_parity')"
METER2_BAUDRATE="$(bashio::config 'meter2_baudrate')"
METER2_AGGTIME="$(bashio::config 'meter2_aggtime')"
METER2_INTERVAL="$(bashio::config 'meter2_interval')"
METER2_DEVICE="$(bashio::config 'meter2_device')"


METER_PROTOCOL="$(bashio::config 'meter_protocol')"
METER_PARITY="$(bashio::config 'meter_parity')"
METER_BAUDRATE="$(bashio::config 'meter_baudrate')"
METER_AGGTIME="$(bashio::config 'meter_aggtime')"
METER_DEVICE="$(bashio::config 'meter_device')"
METER_DEVICE2="$(bashio::config 'meter_device2')"

#CLEN =$(jq '.channels | length' /data/options.json)
CHANNELS=$(jq -r 'if .channels then [.channels[] | "{\n \"uuid\": \"1\", \n \"api\": \"null\", \n \"identifier\": \""+.identifier+"\", \n \"aggmode\": \""+.aggmode+"\" }" ] | join(",\n ") else "" end' /data/options.json)
METER1_CHANNELS=$(jq -r 'if .meter1_channels then [.meter1_channels[] | "{\n \"uuid\": \"1\", \n \"api\": \"null\", \n \"identifier\": \""+.identifier+"\", \n \"aggmode\": \""+.aggmode+"\" }" ] | join(",\n ") else "" end' /data/options.json)
METER2_CHANNELS=$(jq -r 'if .meter2_channels then [.meter2_channels[] | "{\n \"uuid\": \"1\", \n \"api\": \"null\", \n \"identifier\": \""+.identifier+"\", \n \"aggmode\": \""+.aggmode+"\" }" ] | join(",\n ") else "" end' /data/options.json)
#echo "$CHANNELS"

METER_ENABLED2="false"
if [[ ! -z $METER_DEVICE2 ]]
METER2_ENABLED="false"
if [[ ! -z $METER2_DEVICE ]]
then
echo "Enabling second meter ... "
METER_ENABLED2="true"
METER2_ENABLED="true"
fi

# Replace in pyhpsu.conf
# Replace in vzlogger.conf
echo "Initializing vzlogger configuration ..."

#MQTT options
sed -i "s/{verbosity}/${VERBOSITY}/g" "vzlogger.conf"
sed -i "s/{mqtt_broker}/${MQTT_BROKER}/g" "vzlogger.conf"
sed -i "s/{mqtt_port}/${MQTT_PORT}/g" "vzlogger.conf"
sed -i "s/{mqtt_username}/${MQTT_USERNAME}/g" "vzlogger.conf"
sed -i "s/{mqtt_password}/${MQTT_PASSWORD}/g" "vzlogger.conf"
sed -i "s#{mqtt_topic}#${MQTT_TOPIC}#g" "vzlogger.conf"
sed -i "s#{mqtt_timestamp}#${MQTT_TIMESTAMP}#g" "vzlogger.conf"

#Meter 1 options
sed -i "s/{meter1_protocol}/${METER1_PROTOCOL}/g" "vzlogger.conf"
sed -i "s/{meter1_parity}/${METER1_PARITY}/g" "vzlogger.conf"
sed -i "s/{meter1_baudrate}/${METER1_BAUDRATE}/g" "vzlogger.conf"
sed -i "s/{meter1_aggtime}/${METER1_AGGTIME}/g" "vzlogger.conf"
sed -i "s/{meter1_interval}/${METER1_INTERVAL}/g" "vzlogger.conf"
sed -i "s#{meter1_device}#${METER1_DEVICE}#g" "vzlogger.conf"
sed -i "s/{meter1_channels}/${METER1_CHANNELS//$'\n'/\\n}/g" "vzlogger.conf"

sed -i "s/{meter_protocol}/${METER_PROTOCOL}/g" "vzlogger.conf"
sed -i "s/{meter_parity}/${METER_PARITY}/g" "vzlogger.conf"
sed -i "s/{meter_baudrate}/${METER_BAUDRATE}/g" "vzlogger.conf"
sed -i "s/{meter_aggtime}/${METER_AGGTIME}/g" "vzlogger.conf"
sed -i "s#{meter_device}#${METER_DEVICE}#g" "vzlogger.conf"
sed -i "s/{meter_enabled2}/${METER_ENABLED2}/g" "vzlogger.conf"
sed -i "s#{meter_device2}#${METER_DEVICE2}#g" "vzlogger.conf"

sed -i "s/{channels}/${CHANNELS//$'\n'/\\n}/g" "vzlogger.conf"
#Meter 2 options
sed -i "s/{meter2_enabled}/${METER2_ENABLED}/g" "vzlogger.conf"
sed -i "s#{meter2_device}#${METER2_DEVICE}#g" "vzlogger.conf"
sed -i "s/{meter2_protocol}/${METER2_PROTOCOL}/g" "vzlogger.conf"
sed -i "s/{meter2_parity}/${METER2_PARITY}/g" "vzlogger.conf"
sed -i "s/{meter2_baudrate}/${METER2_BAUDRATE}/g" "vzlogger.conf"
sed -i "s/{meter2_aggtime}/${METER2_AGGTIME}/g" "vzlogger.conf"
sed -i "s/{meter2_interval}/${METER2_INTERVAL}/g" "vzlogger.conf"
sed -i "s/{meter2_channels}/${METER2_CHANNELS//$'\n'/\\n}/g" "vzlogger.conf"


echo
Expand Down
30 changes: 16 additions & 14 deletions vzlogger2mqtt/vzlogger.conf
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,31 @@
"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
"timestamp": {mqtt_timestamp} // optional whether to include a timestamp in the payload
},

// information on the (up to two) meters and their channels
"meters" : [{
"protocol" : "{meter_protocol}",
"protocol" : "{meter1_protocol}",
"enabled" : true,
"device" : "{meter_device}",
"parity" : "{meter_parity}",
"baudrate" : {meter_baudrate},
"aggtime" : {meter_aggtime}, // aggregate meter readings for <aggtime> seconds
"device" : "{meter1_device}",
"parity" : "{meter1_parity}",
"baudrate" : {meter1_baudrate},
"aggtime" : {meter1_aggtime}, // aggregate meter readings for <aggtime> seconds
"interval" : {meter1_interval},
"aggfixedinterval" : true, // round timestamps to nearest <aggtime> before sending
"duplicates" : 60,
"channels": [{channels}]
"channels": [{meter1_channels}]
},{
"protocol" : "{meter_protocol}",
"enabled" : {meter_enabled2},
"device" : "{meter_device2}",
"parity" : "{meter_parity}",
"baudrate" : {meter_baudrate},
"aggtime" : {meter_aggtime},
"protocol" : "{meter2_protocol}",
"enabled" : {meter2_enabled},
"device" : "{meter2_device}",
"parity" : "{meter2_parity}",
"baudrate" : {meter2_baudrate},
"aggtime" : {meter2_aggtime},
"interval" : {meter2_interval},
"aggfixedinterval" : true,
"duplicates" : 60,
"channels": [{channels}]
"channels": [{meter2_channels}]
}]
}

0 comments on commit 928022b

Please sign in to comment.