diff --git a/README.md b/README.md index 0941549..c0981d4 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,9 @@ cd /opt/ha-inverter-mqtt-agent # Configure the 'device=' directive (in inverter.conf) to suit for RS232 or USB..  vi config/inverter.conf -# Configure your MQTT server host, port, Home Assistant topic, and name of the Inverter that you want displayed in Home Assistant. +# Configure your MQTT server's IP/Host Name, Port, Credentials, HA topic, and name of the Inverter that you want displayed in Home Assistant... +# If your MQTT server does not need a username/password just leave these values empty. + vi config/mqtt.json ``` @@ -62,7 +64,7 @@ docker-compose up -d ``` -_Note if you have issues standing up the image on your Linux distribution, you may need to manually build the image - This can be done by uncommenting the build flag in your docker-compose.yml file._ +_**Note:** builds on docker hub are currently for x64 -- If you have issues standing up the image on your Linux distribution (i.e. Your Raspberry Pi/ARM device) you will need to manually build the image - This can be done by uncommenting the build flag in your docker-compose.yml file._ ## Integrating into Home Assistant. diff --git a/config/mqtt.json b/config/mqtt.json index fffce8e..6d7fa04 100644 --- a/config/mqtt.json +++ b/config/mqtt.json @@ -2,5 +2,7 @@ "server": "10.16.10.4", "port": "1883", "topic": "homeassistant", - "devicename": "voltronic" + "devicename": "voltronic", + "username": "", + "password": "" } \ No newline at end of file diff --git a/sources/inverter-mqtt/mqtt-init.sh b/sources/inverter-mqtt/mqtt-init.sh index 21b734f..e9e6197 100755 --- a/sources/inverter-mqtt/mqtt-init.sh +++ b/sources/inverter-mqtt/mqtt-init.sh @@ -6,11 +6,15 @@ 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` MQTT_DEVICENAME=`cat /etc/inverter/mqtt.json | jq '.devicename' -r` +MQTT_USERNAME=`cat /etc/inverter/mqtt.json | jq '.username' -r` +MQTT_PASSWORD=`cat /etc/inverter/mqtt.json | jq '.password' -r` registerTopic () { mosquitto_pub \ -h $MQTT_SERVER \ -p $MQTT_PORT \ + -u "$MQTT_USERNAME" \ + -P "$MQTT_PASSWORD" \ -t "$MQTT_TOPIC/sensor/"$MQTT_DEVICENAME"_$1/config" \ -m "{ \"name\": \""$MQTT_DEVICENAME"_$1\", @@ -24,11 +28,12 @@ registerInverterRawCMD () { mosquitto_pub \ -h $MQTT_SERVER \ -p $MQTT_PORT \ + -u "$MQTT_USERNAME" \ + -P "$MQTT_PASSWORD" \ -t "$MQTT_TOPIC/sensor/$MQTT_DEVICENAME/config" \ -m "{ \"name\": \""$MQTT_DEVICENAME"\", - \"state_topic\": \"$MQTT_TOPIC/sensor/$MQTT_DEVICENAME\", - \"retain\": true + \"state_topic\": \"$MQTT_TOPIC/sensor/$MQTT_DEVICENAME\" }" } diff --git a/sources/inverter-mqtt/mqtt-push.sh b/sources/inverter-mqtt/mqtt-push.sh index 2df9816..6fa8d9f 100755 --- a/sources/inverter-mqtt/mqtt-push.sh +++ b/sources/inverter-mqtt/mqtt-push.sh @@ -6,10 +6,14 @@ pushMQTTData () { MQTT_PORT=`cat /etc/inverter/mqtt.json | jq '.port' -r` MQTT_TOPIC=`cat /etc/inverter/mqtt.json | jq '.topic' -r` MQTT_DEVICENAME=`cat /etc/inverter/mqtt.json | jq '.devicename' -r` + MQTT_USERNAME=`cat /etc/inverter/mqtt.json | jq '.username' -r` + MQTT_PASSWORD=`cat /etc/inverter/mqtt.json | jq '.password' -r` mosquitto_pub \ -h $MQTT_SERVER \ -p $MQTT_PORT \ + -u "$MQTT_USERNAME" \ + -P "$MQTT_PASSWORD" \ -t "$MQTT_TOPIC/sensor/"$MQTT_DEVICENAME"_$1" \ -m "$2" } diff --git a/sources/inverter-mqtt/mqtt-subscriber.sh b/sources/inverter-mqtt/mqtt-subscriber.sh index f152e73..f30ce27 100755 --- a/sources/inverter-mqtt/mqtt-subscriber.sh +++ b/sources/inverter-mqtt/mqtt-subscriber.sh @@ -4,6 +4,8 @@ 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` MQTT_DEVICENAME=`cat /etc/inverter/mqtt.json | jq '.devicename' -r` +MQTT_USERNAME=`cat /etc/inverter/mqtt.json | jq '.username' -r` +MQTT_PASSWORD=`cat /etc/inverter/mqtt.json | jq '.password' -r` while read rawcmd; do @@ -11,4 +13,4 @@ do echo "Incoming request send: [$rawcmd] to inverter." /opt/inverter-cli/bin/inverter_poller -r $rawcmd; -done < <(mosquitto_sub -h $MQTT_SERVER -p $MQTT_PORT -t "$MQTT_TOPIC/sensor/$MQTT_DEVICENAME" -q 1) +done < <(mosquitto_sub -h $MQTT_SERVER -p $MQTT_PORT -u "$MQTT_USERNAME" -P "$MQTT_PASSWORD" -t "$MQTT_TOPIC/sensor/$MQTT_DEVICENAME" -q 1)