Skip to content

Commit 2a14c29

Browse files
authored
make MQTT feature configurable (#4)
1 parent 40b06c0 commit 2a14c29

4 files changed

Lines changed: 32 additions & 3 deletions

File tree

config.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version: "1.0.1"
44
slug: "orb_homeassistant"
55
init: false
66
host_network: true
7-
image: "orbforge/orb"
7+
image: "orbforge/orb-ha"
88
environment:
99
ORB_DATA_DIR: /data
1010
arch:
@@ -14,3 +14,9 @@ arch:
1414
boot: auto
1515
services:
1616
- mqtt:need
17+
options:
18+
mqtt_push: false
19+
mqtt_frequency: 5
20+
schema:
21+
mqtt_push: bool
22+
mqtt_frequency: int(1,120)

docker/entrypoint.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@ echo "Starting MQTT publishing script..."
66
date
77

88
# Start MQTT publishing in the background
9-
/app/mqtt.sh &
9+
CONFIG_PATH=/data/options.json
10+
MQTT_PUSH=$(jq -r '.mqtt_push // false' $CONFIG_PATH)
11+
12+
if [ "$MQTT_PUSH" == "true" ]; then
13+
echo "MQTT Push is enabled"
14+
/app/mqtt.sh &
15+
else
16+
echo "MQTT Push is disabled"
17+
fi
18+
1019

1120
# Now start the original entrypoint or command
1221
exec /app/orb sensor

docker/mqtt.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ MQTT_PORT=$(echo "$MQTT_INFO" | jq -r '.data.port')
1010
MQTT_USER=$(echo "$MQTT_INFO" | jq -r '.data.username')
1111
MQTT_PASS=$(echo "$MQTT_INFO" | jq -r '.data.password')
1212

13+
CONFIG_PATH=/data/options.json
14+
MQTT_PAUSE=$(jq -r '.mqtt_frequency // 5' $CONFIG_PATH)
15+
1316
echo "MQTT Host: $MQTT_HOST"
1417
echo "MQTT Port: $MQTT_PORT"
1518
echo "MQTT User: $MQTT_USER"
@@ -82,5 +85,5 @@ while true; do
8285
mosquitto_pub -h "$MQTT_HOST" -p "$MQTT_PORT" -u "$MQTT_USER" -P "$MQTT_PASS" \
8386
-t "$STATE_TOPIC" -m "$ORB_OUTPUT" -r
8487

85-
sleep 15
88+
sleep "$MQTT_PAUSE"
8689
done

translations/en.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
configuration:
3+
mqtt_push:
4+
name: Push Scores to MQTT
5+
description: >-
6+
If set to `true`, the Orb will push scores to the MQTT broker.
7+
mqtt_frequency:
8+
name: MQTT Frequency
9+
description: >-
10+
The frequency in seconds at which the Orb will push scores to the MQTT
11+
broker.

0 commit comments

Comments
 (0)