Added the possibility to write directly to Influx
Since I am not using Influx as a DB of my HomeAssistant setup, I wanted a way to bring the data there. Another issue is that I used another script to gather the data and hence have other naming conventions on my dashboards. Therefore the name of the measurements are now part of the config JSON file. This could be an idea adopted to MQTT as well.
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
#!/bin/bash
|
||||
INFLUX_HOST=`cat /etc/inverter/mqtt.json | jq '.influx.host' -r`
|
||||
if [[ -n $INFLUX_HOST ]]; then
|
||||
INFLUX_ENABLED=true
|
||||
else
|
||||
INFLUX_ENABLED=false
|
||||
fi
|
||||
|
||||
pushMQTTData () {
|
||||
|
||||
MQTT_SERVER=`cat /etc/inverter/mqtt.json | jq '.server' -r`
|
||||
MQTT_PORT=`cat /etc/inverter/mqtt.json | jq '.port' -r`
|
||||
MQTT_TOPIC=`cat /etc/inverter/mqtt.json | jq '.topic' -r`
|
||||
@@ -16,6 +21,22 @@ pushMQTTData () {
|
||||
-P "$MQTT_PASSWORD" \
|
||||
-t "$MQTT_TOPIC/sensor/"$MQTT_DEVICENAME"_$1" \
|
||||
-m "$2"
|
||||
|
||||
if "$INFLUX_ENABLED"; then
|
||||
pushInfluxData $1 $2
|
||||
fi
|
||||
}
|
||||
|
||||
pushInfluxData () {
|
||||
INFLUX_HOST=`cat /etc/inverter/mqtt.json | jq '.influx.host' -r`
|
||||
INFLUX_USERNAME=`cat /etc/inverter/mqtt.json | jq '.influx.username' -r`
|
||||
INFLUX_PASSWORD=`cat /etc/inverter/mqtt.json | jq '.influx.password' -r`
|
||||
INFLUX_DEVICE=`cat /etc/inverter/mqtt.json | jq '.influx.device' -r`
|
||||
INFLUX_PREFIX=`cat /etc/inverter/mqtt.json | jq '.influx.prefix' -r`
|
||||
INFLUX_DATABASE=`cat /etc/inverter/mqtt.json | jq '.influx.database' -r`
|
||||
INFLUX_MEASUREMENT_NAME=`cat /etc/inverter/mqtt.json | jq '.influx.namingMap.'$1'' -r`
|
||||
|
||||
curl -i -XPOST "$INFLUX_HOST/write?db=$INFLUX_DATABASE&precision=s" -u "$INFLUX_USERNAME:$INFLUX_PASSWORD" --data-binary "$INFLUX_PREFIX,device=$INFLUX_DEVICE $INFLUX_MEASUREMENT_NAME=$2"
|
||||
}
|
||||
|
||||
INVERTER_DATA=`timeout 10 /opt/inverter-cli/bin/inverter_poller -1`
|
||||
|
||||
Reference in New Issue
Block a user