Report temperature from second rpi to HA?

Hey guys.

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?

Cheers for any input!

Send MQTT message to HA with temp stats

1 Like

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?

HA has built in MQTT server OR you may install your own

Install mosquito on remote RPi and send message like
mosquitto_pub -t ‘sensor/remote/temp’ -m ‘83’

HA has component to receive the message

It is very easy

1 Like

Brilliant, thanks mate, i’m just reading up on the examples on HA. I’ve got the broker on HA working, so now playing with the remote Pi.

I appreciate your input, love learning something new, however trivial it may be!

I use two HA’s and I just ask one HA if I want to know something though its api.

binary_sensor:
  - platform: rest
    resource: http://192.168.x.xxx:8124/api/states/binary_sensor.xxxxxxx
    name: xxxxxxxxx
    value_template: '{{ value_json.state }}'
    scan_interval: 5
3 Likes

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

On the HASS config side, I have:

### RPi Temp Sensor ###
sensor:
  - platform: mqtt
    state_topic: "rpi_name"
    name: RPi Name
    unit_of_measurement: '°C'
    force_update: True

This way, every RPi you want, can send the data to HASS.

3 Likes

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!

Yes to all.

1 Like

How about adding a sensor to either configuration.yaml or sensors.yaml:

Sensor:
- platform: command_line
name: Pi Temp
command: “cat /sys/class/thermal/thermal_zone0/temp”
unit_of_measurement: “°C”
value_template: ‘{{ value | multiply(0.001) | round(1) }}’

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.