Last active
September 10, 2024 19:59
-
-
Save jffz/dbcfed2792ab07749ddf0a3e6f5039ea to your computer and use it in GitHub Desktop.
Publish hiveos logs to mqtt broker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# MQTT settings | |
BROKER="" | |
TOPIC="" | |
USER="" | |
PASS="" | |
# Ensure mosquitto-clients is installed | |
dpkg -s mosquitto-clients >/dev/null 2>&1 || apt update && apt install -y mosquitto-clients | |
# Stream logs to MQTT | |
tail -f /var/log/hive-agent.log | while read -r line; do | |
json_line=$(echo ${line} | awk -F'[<>]' {'print $2'}) | |
if $(echo "$json_line" | jq -e 'has("method")'); then | |
mosquitto_pub -h $BROKER -t $TOPIC -u "$USER" -P "$PASS" -m "$json_line" | |
fi | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- platform: mqtt | |
name: hiveos_stats | |
state_topic: "hiveos" | |
value_template: "{{ value_json.params.uptime }}" | |
json_attributes_topic: "hiveos" | |
json_attributes_template: "{{ value_json.params.miner_stats | to_json }}" | |
- platform: mqtt | |
name: hiveos_params | |
state_topic: "hiveos" | |
value_template: "{{ value_json.params .uptime }}" | |
json_attributes_topic: "hiveos" | |
json_attributes_template: "{{ value_json.params | to_json }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for your great work.
i have managed to get the worker to connect to the MQTT broker on my home assistant, but i get no data, and sensors are unavailable
i get this on mqtt broker logs
1660905302: New connection from 192.168.1.140:51864 on port 1883.
1660905302: New client connected from 192.168.1.140:51864 as mosqpub|26074-hive02_30 (p1, c1, k60, u'mqtt').
then in the config.yaml for my home assistant i have added
sensor:
platform: mqtt
name: hiveos_stats
state_topic: "hive_mqtt_1"
value_template: "{{ value_json.params.miner_stats.uptime }}"
json_attributes_topic: "hive_mqtt_1"
json_attributes_template: "{{ value_json.params.miner_stats | to_json }}"
platform: mqtt
name: hiveos_params
state_topic: "hive_mqtt_1"
value_template: "{{ value_json.params.miner_stats.uptime }}"
json_attributes_topic: "hive_mqtt_1"
json_attributes_template: "{{ value_json.params | to_json }}"
im a bit confused
should i add a new file somewhere named mqtt_sensors.yaml
and if yes, where should the file be located