kopia lustrzana https://github.com/weetmuts/wmbusmeters
refactor addon config
rodzic
7f0ff31890
commit
260aa7cfd8
|
@ -24,22 +24,35 @@ Once the wmbusmeters is receiving the telegrams you need to configure your meter
|
|||
|
||||
#### Option: `meters`
|
||||
|
||||
Specify your meters using wmbusmeters meter file format. The `driver` and `id` values can be read from the add-on logs after the initial start (with empty `meters` configuration). The `name` is your label for the meter and `key` is the encryption key to decrypt telegrams (if your meter use any).
|
||||
Specify your meters using YAML format. The `driver` and `id` values can be read from the add-on logs after the initial start (with empty `meters` configuration). The `name` is your label for the meter and `key` is the encryption key to decrypt telegrams (if your meter use any).
|
||||
|
||||
See [project README for more information][github]
|
||||
|
||||
```yaml
|
||||
meters:
|
||||
- |-
|
||||
name=MainWater
|
||||
driver=apator162
|
||||
id=01234567
|
||||
key=00000000000000000000000000000000
|
||||
- name: ElectricityMeter
|
||||
driver: amiplus
|
||||
id: "12345678" #Note "123" casts number as string
|
||||
key: DEADBEEF1337DEADBEEF1337DEADBEEF
|
||||
- name: WaterMeter
|
||||
driver: apator162
|
||||
id: "87654321" #Note "123" casts number as string
|
||||
key: "00000000000000000000000000000000" #Note "123" casts number as string
|
||||
```
|
||||
|
||||
#### Option: `conf`
|
||||
|
||||
The wmbusmeters configuration file. It will be used as `wmbusmeters.conf`.
|
||||
The wmbusmeters configuration file casted as YAML. It will be used as `wmbusmeters.conf`.
|
||||
|
||||
```yaml
|
||||
loglevel: normal
|
||||
device: auto:t1
|
||||
donotprobe: /dev/ttyAMA0
|
||||
logtelegrams: false
|
||||
format: json
|
||||
logfile: /dev/stdout
|
||||
shell: /wmbusmeters/mosquitto_pub.sh "wmbusmeters/$METER_NAME" "$METER_JSON"
|
||||
```
|
||||
|
||||
See [project README for more information][github]
|
||||
|
||||
|
|
|
@ -29,9 +29,16 @@
|
|||
"options": {
|
||||
"data_path": "/config/wmbusmeters",
|
||||
"enable_mqtt_discovery": false,
|
||||
"conf":
|
||||
"loglevel=normal\ndevice=auto:t1\ndonotprobe=/dev/ttyAMA0\nlogtelegrams=false\nformat=json\nlogfile=/dev/stdout\nshell=/wmbusmeters/mosquitto_pub.sh \"wmbusmeters/$METER_NAME\" \"$METER_JSON\"",
|
||||
"meters": [],
|
||||
"conf": {
|
||||
"loglevel": "normal",
|
||||
"device": "auto:t1",
|
||||
"donotprobe": "/dev/ttyAMA0",
|
||||
"logtelegrams": false,
|
||||
"format": "json",
|
||||
"logfile": "/dev/stdout",
|
||||
"shell": "/wmbusmeters/mosquitto_pub.sh \"wmbusmeters/$METER_NAME\" \"$METER_JSON\""
|
||||
},
|
||||
"meters": {},
|
||||
"mqtt": {}
|
||||
},
|
||||
"schema": {
|
||||
|
@ -43,7 +50,20 @@
|
|||
"user": "str?",
|
||||
"password": "str?"
|
||||
},
|
||||
"conf": "str",
|
||||
"meters": [ "str" ]
|
||||
"conf": {
|
||||
"loglevel": "str",
|
||||
"device": "str",
|
||||
"donotprobe": "str",
|
||||
"logtelegrams": "bool?",
|
||||
"shell": "str"
|
||||
},
|
||||
"meters": [
|
||||
{
|
||||
"name": "str",
|
||||
"driver": "str",
|
||||
"id": "str",
|
||||
"key": "str"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,9 +39,10 @@ if [ $CONFIG_MQTTDISCOVERY_ENABLED == "true" ]; then
|
|||
declare kv
|
||||
for line in $(printf '%s\n' $meter | jq --raw-output -c -M '.')
|
||||
do
|
||||
readarray -d = -t kv <<< $line
|
||||
#echo "${kv[0]} = ${kv[1]}"
|
||||
aryKV[${kv[0]}]=${kv[1]%$'\n'}
|
||||
aryKV["name"]=$(printf '%s\n' $meter | jq --raw-output -c -M '.name')
|
||||
aryKV["id"]=$(printf '%s\n' $meter | jq --raw-output -c -M '.id')
|
||||
aryKV["driver"]=$(printf '%s\n' $meter | jq --raw-output -c -M '.driver')
|
||||
|
||||
done
|
||||
echo " Adding meter: ${aryKV['name']} ..."
|
||||
|
||||
|
|
|
@ -6,6 +6,11 @@ CONFIG_DATA_PATH=$(bashio::config 'data_path')
|
|||
CONFIG_CONF=$(bashio::jq "${CONFIG_PATH}" '.conf')
|
||||
CONFIG_METERS=$(bashio::jq "${CONFIG_PATH}" '.meters')
|
||||
|
||||
bashio::log.info "CONFIG_CONF ..."
|
||||
bashio::log.info "${CONFIG_CONF}"
|
||||
bashio::log.info "CONFIG_METERS ..."
|
||||
bashio::log.info "${CONFIG_METERS}"
|
||||
|
||||
bashio::log.info "Syncing wmbusmeters configuration ..."
|
||||
if ! bashio::fs.directory_exists "${CONFIG_DATA_PATH}/logs/meter_readings"; then
|
||||
mkdir -p "${CONFIG_DATA_PATH}/logs/meter_readings"
|
||||
|
@ -13,7 +18,8 @@ fi
|
|||
if ! bashio::fs.directory_exists "${CONFIG_DATA_PATH}/etc/wmbusmeters.d"; then
|
||||
mkdir -p "${CONFIG_DATA_PATH}/etc/wmbusmeters.d"
|
||||
fi
|
||||
echo -e "$CONFIG_CONF" > $CONFIG_DATA_PATH/etc/wmbusmeters.conf
|
||||
|
||||
echo -e "$CONFIG_CONF" | jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' > $CONFIG_DATA_PATH/etc/wmbusmeters.conf
|
||||
|
||||
bashio::log.info "Registering meters ..."
|
||||
rm -f $CONFIG_DATA_PATH/etc/wmbusmeters.d/*
|
||||
|
@ -25,7 +31,7 @@ do
|
|||
METER_NAME=$(printf 'meter-%04d' "$(( meter_no ))")
|
||||
bashio::log.info "Adding $METER_NAME ..."
|
||||
METER_DATA=$(printf '%s\n' $meter | jq --raw-output -c -M '.')
|
||||
echo -e "$METER_DATA" > $CONFIG_DATA_PATH/etc/wmbusmeters.d/$METER_NAME
|
||||
echo -e "$METER_DATA" | jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' > $CONFIG_DATA_PATH/etc/wmbusmeters.d/$METER_NAME
|
||||
done
|
||||
|
||||
bashio::log.info "Generating MQTT configuration ... "
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "Wmbusmeter",
|
||||
"name": "Wmbusmeters",
|
||||
"url": "https://github.com/weetmuts/wmbusmeters/",
|
||||
"maintainer": "weetmuts"
|
||||
}
|
Ładowanie…
Reference in New Issue