-
-
Save jffz/dbcfed2792ab07749ddf0a3e6f5039ea to your computer and use it in GitHub Desktop.
| #!/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 |
| - 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 }}" |
@PablexXXXX add the mqtt_sensors.yaml to your HA configuration, and run the hiveos2mqtt.sh on your miner. You will need to make sure that it runs on boot. I will share my experience on setting up the script to start on boot when I give it a try.
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
Great. Can anyone describe how to implement this? Should I compile this? Or just copy and paste on my hiveos?