I’ve got a couple of pi’s working away in my place. One is for my HA installation, the other is for a Pihole and pivpn server using DNScrypt. Unfortunately the the pihole machine is an original Pi, and can get a little warm so i like to keep an eye on it.
I was wondering whether i can periodically forward the temp/cpu usage from this machine to my HA dashboard so i can monitor it? Since it’s already got a Pihole running, and the pihole admin interface outputs the cpu temp, load and memory usage, I was wondering whether this would be a simple fix?
Thanks mate, that sounds a good route. I’ve never used MQTT, and having a look seems fairly complex to me, i’m sure i can get my head around it in time.
So do i need a broker on the RP1 as well as the HA machine?
Can you break it down so i know where i’m going? I guess i need to write a script to publish the temperature on the RP1, and then, do i have to send it to the HA, or does the HA MQTT scan it, or probe it etc?
I have exactly the same scenario as you do, and this is the kind of script I have running as a cron job every 5 minutes on all PIs (except the one where HASS is installed):
#!/bin/bash
PATH=/bin:/usr/bin
# Get CPU Temperature in degrees celsius
VALUE=$( cat /sys/class/thermal/thermal_zone0/temp | awk -v FS=" " '{print $1/1000""}' | cut -c1-5 )
if [[ "$VALUE" == "" ]]
then
VALUE=0
fi
curl -X POST \
-H "Content-Type: application/json" \
-H "x-ha-access: PASSWORD" \
-d '{"payload": "'"$VALUE"'", "topic": "rpi_name", "retain": "True"}' \
http://IP:PORT/api/services/mqtt/publish > /dev/null 2>&1 &
exit 0
Thanks for this, i’ll have a crack tomorrow. It’s taken me a while to get mqtt working, seems it’s got issues with rasbian-stretch, but tldr, installed via aptitude and seems to be working finally.
So your x-ha-access: Password, is this the HA api password? And the IP/Port, is that the HA ip too? Just getting my head around it. Thanks!
But in addition to the password of HA do not you also need to specify the username and password of the broker and IDClient?
I always have this connection error:" socket error on client unknown".
Help me, please.