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`
|
#### 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]
|
See [project README for more information][github]
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
meters:
|
meters:
|
||||||
- |-
|
- name: ElectricityMeter
|
||||||
name=MainWater
|
driver: amiplus
|
||||||
driver=apator162
|
id: "12345678" #Note "123" casts number as string
|
||||||
id=01234567
|
key: DEADBEEF1337DEADBEEF1337DEADBEEF
|
||||||
key=00000000000000000000000000000000
|
- name: WaterMeter
|
||||||
|
driver: apator162
|
||||||
|
id: "87654321" #Note "123" casts number as string
|
||||||
|
key: "00000000000000000000000000000000" #Note "123" casts number as string
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Option: `conf`
|
#### 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]
|
See [project README for more information][github]
|
||||||
|
|
||||||
|
|
|
@ -29,9 +29,16 @@
|
||||||
"options": {
|
"options": {
|
||||||
"data_path": "/config/wmbusmeters",
|
"data_path": "/config/wmbusmeters",
|
||||||
"enable_mqtt_discovery": false,
|
"enable_mqtt_discovery": false,
|
||||||
"conf":
|
"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\"",
|
"loglevel": "normal",
|
||||||
"meters": [],
|
"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": {}
|
"mqtt": {}
|
||||||
},
|
},
|
||||||
"schema": {
|
"schema": {
|
||||||
|
@ -43,7 +50,20 @@
|
||||||
"user": "str?",
|
"user": "str?",
|
||||||
"password": "str?"
|
"password": "str?"
|
||||||
},
|
},
|
||||||
"conf": "str",
|
"conf": {
|
||||||
"meters": [ "str" ]
|
"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
|
declare kv
|
||||||
for line in $(printf '%s\n' $meter | jq --raw-output -c -M '.')
|
for line in $(printf '%s\n' $meter | jq --raw-output -c -M '.')
|
||||||
do
|
do
|
||||||
readarray -d = -t kv <<< $line
|
aryKV["name"]=$(printf '%s\n' $meter | jq --raw-output -c -M '.name')
|
||||||
#echo "${kv[0]} = ${kv[1]}"
|
aryKV["id"]=$(printf '%s\n' $meter | jq --raw-output -c -M '.id')
|
||||||
aryKV[${kv[0]}]=${kv[1]%$'\n'}
|
aryKV["driver"]=$(printf '%s\n' $meter | jq --raw-output -c -M '.driver')
|
||||||
|
|
||||||
done
|
done
|
||||||
echo " Adding meter: ${aryKV['name']} ..."
|
echo " Adding meter: ${aryKV['name']} ..."
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,11 @@ CONFIG_DATA_PATH=$(bashio::config 'data_path')
|
||||||
CONFIG_CONF=$(bashio::jq "${CONFIG_PATH}" '.conf')
|
CONFIG_CONF=$(bashio::jq "${CONFIG_PATH}" '.conf')
|
||||||
CONFIG_METERS=$(bashio::jq "${CONFIG_PATH}" '.meters')
|
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 ..."
|
bashio::log.info "Syncing wmbusmeters configuration ..."
|
||||||
if ! bashio::fs.directory_exists "${CONFIG_DATA_PATH}/logs/meter_readings"; then
|
if ! bashio::fs.directory_exists "${CONFIG_DATA_PATH}/logs/meter_readings"; then
|
||||||
mkdir -p "${CONFIG_DATA_PATH}/logs/meter_readings"
|
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
|
if ! bashio::fs.directory_exists "${CONFIG_DATA_PATH}/etc/wmbusmeters.d"; then
|
||||||
mkdir -p "${CONFIG_DATA_PATH}/etc/wmbusmeters.d"
|
mkdir -p "${CONFIG_DATA_PATH}/etc/wmbusmeters.d"
|
||||||
fi
|
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 ..."
|
bashio::log.info "Registering meters ..."
|
||||||
rm -f $CONFIG_DATA_PATH/etc/wmbusmeters.d/*
|
rm -f $CONFIG_DATA_PATH/etc/wmbusmeters.d/*
|
||||||
|
@ -25,7 +31,7 @@ do
|
||||||
METER_NAME=$(printf 'meter-%04d' "$(( meter_no ))")
|
METER_NAME=$(printf 'meter-%04d' "$(( meter_no ))")
|
||||||
bashio::log.info "Adding $METER_NAME ..."
|
bashio::log.info "Adding $METER_NAME ..."
|
||||||
METER_DATA=$(printf '%s\n' $meter | jq --raw-output -c -M '.')
|
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
|
done
|
||||||
|
|
||||||
bashio::log.info "Generating MQTT configuration ... "
|
bashio::log.info "Generating MQTT configuration ... "
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"name": "Wmbusmeter",
|
"name": "Wmbusmeters",
|
||||||
"url": "https://github.com/weetmuts/wmbusmeters/",
|
"url": "https://github.com/weetmuts/wmbusmeters/",
|
||||||
"maintainer": "weetmuts"
|
"maintainer": "weetmuts"
|
||||||
}
|
}
|
Ładowanie…
Reference in New Issue