Skip to content

Commit

Permalink
Add multiple device support in Hassio addon
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurkrupa committed Apr 28, 2019
1 parent 0fe0950 commit b4e610d
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 17 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,38 @@ docker build \
docker run --rm -v "$PWD/data":/data gree-hvac-mqtt-bridge
```

### Multiple devices

As of 1.2.0 the Hassio addon supports multiple devices by running paralell NodeJS processes in PM2. Old configurations will work, but are deprecated.

Deprecated config example:

```json
"hvac_host": "192.168.0.255",
"mqtt": {
"broker_url": "mqtt:https://localhost",
"topic_prefix": "/my/topic/prefix",
}
```

Correct config example:

```json
"mqtt": {
"broker_url": "mqtt:https://localhost",
},
"devices": [
{
"hvac_host": "192.168.0.255",
"mqtt_topic_prefix": "/home/hvac01"
},
{
"hvac_host": "192.168.0.254",
"mqtt_topic_prefix": "/home/hvac02"
}
]
```

## Configuring HVAC WiFi

1. Make sure your HVAC is running in AP mode. You can reset the WiFi config by pressing MODE +WIFI (or MODE + TURBO) on the AC remote for 5s.
Expand All @@ -137,6 +169,13 @@ echo -n "{\"psw\": \"YOUR_WIFI_PASSWORD\",\"ssid\": \"YOUR_WIFI_SSID\",\"t\": \"
Note: This command may vary depending on your OS (e.g. Linux, macOS, CygWin). If facing problems, please consult the appropriate netcat manual.

## Changelog

[1.2.0]

- Add multiple device support
- Update config with supported architectures
- Fix state being published even if nothing changed

[1.1.2]

- Discovered codes added for Air and Quiet to avoid errors
Expand Down
22 changes: 16 additions & 6 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,31 @@
"hassio_api": true,
"hassio_role": "default",
"options": {
"hvac_host": "192.168.1.255",
"mqtt": {
"broker_url": "mqtt:https://localhost",
"topic_prefix": "home/greehvac",
"username": "",
"password": ""
}
},
"devices": [
{
"hvac_host": "192.168.1.255",
"mqtt_topic_prefix": "home/greehvac"
}
]
},
"schema": {
"hvac_host": "str",
"hvac_host": "str?",
"mqtt": {
"broker_url": "str",
"topic_prefix": "str",
"topic_prefix": "str?",
"username": "str?",
"password": "str?"
}
},
"devices": [
{
"hvac_host": "str",
"mqtt_topic_prefix": "str"
}
]
}
}
43 changes: 32 additions & 11 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,37 @@ set -e

CONFIG_PATH=/data/options.json

HVAC_HOST=$(jq --raw-output ".hvac_host" $CONFIG_PATH)
MQTT_BROKER_URL=$(jq --raw-output ".mqtt.broker_url" $CONFIG_PATH)
MQTT_TOPIC_PREFIX=$(jq --raw-output ".mqtt.topic_prefix" $CONFIG_PATH)
MQTT_USERNAME=$(jq --raw-output ".mqtt.username" $CONFIG_PATH)
MQTT_PASSWORD=$(jq --raw-output ".mqtt.password" $CONFIG_PATH)
HVAC_HOST=$(jq -r ".hvac_host" $CONFIG_PATH)
MQTT_BROKER_URL=$(jq -r ".mqtt.broker_url" $CONFIG_PATH)
MQTT_TOPIC_PREFIX=$(jq -r ".mqtt.topic_prefix" $CONFIG_PATH)
MQTT_USERNAME=$(jq -r ".mqtt.username" $CONFIG_PATH)
MQTT_PASSWORD=$(jq -r ".mqtt.password" $CONFIG_PATH)

npm install
node index.js \
--hvac-host="${HVAC_HOST}" \
--mqtt-broker-url="${MQTT_BROKER_URL}" \
--mqtt-topic-prefix="${MQTT_TOPIC_PREFIX}" \
--mqtt-username="${MQTT_USERNAME}" \
--mqtt-password="${MQTT_PASSWORD}"

INSTANCES=$(jq '.devices | length' $CONFIG_PATH)

if [ "$INSTANCES" -gt 0 ]; then
for i in $(seq 0 $(($INSTANCES - 1))); do
HVAC_HOST=$(jq -r ".devices[$i].hvac_host" $CONFIG_PATH);
MQTT_TOPIC_PREFIX=$(jq -r ".devices[$i].mqtt_topic_prefix" $CONFIG_PATH);
if [[ $HVAC_HOST = null ]]; then echo "[ERROR] Missing hvac_host for device $i. Skipping." && continue; fi
if [[ $MQTT_TOPIC_PREFIX = null ]]; then echo "[ERROR] Missing mqtt_topic_prefix for device $i. Skipping." && continue; fi
echo "Running instance $i for $HVAC_HOST"
npx pm2 start index.js --silent -m --merge-logs --name="HVAC_${i}" -- \
--hvac-host="${HVAC_HOST}" \
--mqtt-broker-url="${MQTT_BROKER_URL}" \
--mqtt-topic-prefix="${MQTT_TOPIC_PREFIX}" \
--mqtt-username="${MQTT_USERNAME}" \
--mqtt-password="${MQTT_PASSWORD}"
done
npx pm2 logs /HVAC_/
else
echo "Running in single-instance mode (DEPRECATED)"
node index.js \
--hvac-host="${HVAC_HOST}" \
--mqtt-broker-url="${MQTT_BROKER_URL}" \
--mqtt-topic-prefix="${MQTT_TOPIC_PREFIX}" \
--mqtt-username="${MQTT_USERNAME}" \
--mqtt-password="${MQTT_PASSWORD}"
fi

0 comments on commit b4e610d

Please sign in to comment.