Hi,
So i want to monitor the CPU temp on a RPi i have.
I looked in to Glances but no dice.
Looked throw the forum but no luck there.
Is there any one who have solved this or have some tips on how i can move forward?
Hi,
So i want to monitor the CPU temp on a RPi i have.
I looked in to Glances but no dice.
Looked throw the forum but no luck there.
Is there any one who have solved this or have some tips on how i can move forward?
If home assistant is running on the Raspberry Pi, I use this:
sensor:
- platform: command_line
name: CPU Temp
command: "/bin/cat /sys/class/thermal/thermal_zone0/temp"
unit_of_measurement: "ºC"
value_template: '{{ value | multiply(0.001) }}'
- platform: systemmonitor
resources:
- type: disk_use_percent
arg: /
- type: memory_free
- type: memory_use_percent
- type: processor_use
- type: since_last_boot
#- type: network_in
# arg: eth0
#- type: network_out
# arg: eth0
I put this in a file `packages/dev_pi.yaml" or similar, and include the package from the main configuration.
Then I havea group:
dev_pi:
name: Pi
entities:
- sensor.cpu_use
- sensor.cpu_temp
- sensor.disk_use_
#- sensor.disk_use_home
- sensor.ram_free
- sensor.ram_use_percent
- sensor.since_last_boot
@jjmontesl is on to something.
You can install HA on the pi and add the example of how to monitor the CPU. You can remove the frontend, logbook , and history from this instance.
Then on your main HA instance you can create a command line sensor that uses an API call to get the information from the 2nd RPi.
May be a bit much though.
Hi,
Thanks for your input.
No, HA is not running on this PI.
The one i would like to monitor is running kodi and i wanted to keep an eye on the temp.
No suggestions there?
Thanks for the suggestion but as you say, it is a bit much to just get the temp.
Must be a better way of doing this
So i though of something that i don´t know will work but i ask you anyway
If i run a bash script that connect to the remote host and check the temp and then write this to a file that it the copy to HA and then i run a command_line to read the file?
Is this possible or am i just way way off?
For a quick value like that, maybe you can use a command line sensor, and ssh into the second raspberry to run the very same command.
I’d:
sudo adduser homeassistant
)ssh-copy-id homeassistant@kodipi
.ssh homeassistant@kodipi "/bin/cat /sys/class/thermal/thermal_zone0/temp"
I’ll be looking into monitoring temperature with Glance (in my case for my laptop), not sure I’ll make it today. Hopefully the approach above works for you.
Hi, i tried you approach and i’m sorry to say that it did not work.
Just get a - in the bubble were the temp should be
Try the chain of commands.
sudo su - homeassistant
/bin/cat /sys/class/thermal/thermal_zone0/temp
sudo su - your_first_raspberry_ha_user
homeassistant@kodipi “/bin/cat /sys/class/thermal/thermal_zone0/temp”
And let us know the results.
Success!
Thanks so much for your help!
So, just for reference and if someone else is trying to do the same in the future i will write down the steps
Create the homeassistant user on the second RPI, sudo adduser homeassistant
I generated RSA keys, and copied them from HA to the second RPI, was using this site, http://www.thegeekstuff.com/2008/11/3-steps-to-perform-ssh-login-without-password-using-ssh-keygen-ssh-copy-id
If i didn’t do this step is asked for password when i try to log on to the Second RPI from HA.
Added this to my configuration.yaml on HA:
And that´s about it to get it to read the temp of the second RPI.
Thanks again for your help, could not have done this without you
For anyone following along with this later on - if you’re trying to do this, make sure you add the ssh keys from INSIDE your HA virtual environment (ie, follow the update commands). That’s where I was being tripped up!
This is a great sample, thank you!
I’ve got a question in addition to this post:
what if i’d like so change the format of “type: since_last_boot”?
in this sample it wil result in “hh-mm-ss.xxxxxxx”
can i change this to “hh-mm-ss”?
or perhaps set conditions: if < 1 day --> “hh-mm” , if < 1 day --> “dd”, if < 30 days --> “mm-dd” ?
I know this is an old thread but I’m having trouble using this to grab the CPU temp on a remote Pi 4. I created the RSA keys and set them up successfully. Added code to my configuration.yaml:
The card just shows “unknown” for the value. I’ve experimented with several different command formats (single/double quotes, quoting different parts/all of command, etc.) Nothing changes.
I’m able to SSH to my remote pi w/o typing a PW. Also, this command ran from the terminal on my HA Pi 4 seems to work:
$ssh remote_IP cat /sys/class/thermal/thermal_zone0/temp
It returns:
Welcome to remote_RPi_name
46251
Any ideas what I’m doing wrong?
Thanks.
I wonder if the welcome message is confusing things. Try changing the command to:
platform: command_line
name: Driveway CAM temp
command: ssh "remote_IP" "cat /sys/class/thermal/thermal_zone0/temp | tail -n 1"
unit_of_measurement: "°C"
value_template: '{{ value | multiply(0.001) | round(1) }}'
(and for future reference, please format your code snippets correctly, surrounded by three backticks)
Troon -
Thank you for your reply and the tip on formatting my code.
That did not work. Same result. I initially thought the same so after some research I added a .hushlogin file to /home but that did not seem to do anything. After adding your suggestion to my yaml the card still showed “uknown”. To test, from my HA terminal I executed:
ssh *remote_IP* cat /sys/class/thermal/thermal_zone0/temp | tail -n 1 > output.txt
AND
ssh *remote_IP* cat /sys/class/thermal/thermal_zone0/temp > output.txt
In both cases it does not appear to have the welcome message stored in the output.txt:
*ssh commands*
Welcome to *remote_RPi_name*!
$ cat output.txt
46738
So, it would seem that while I am seeing the welcome message when I test from my HA Pi, it is not included in the returned cat value.
Any other ideas? Thanks again for your help.
How to create and or add the key to the rpi that has Hassio with docker installed?
Hey guys, i ended up ditching my ssh command line sensor for cpu temp as the value is included when running the system_sensors script. I’m using this now instead of glances and have had no issues so far. This script publishes the following values to MQTT:
If you use the MQTT add-on, the raspberry pi will be discovered automatically and added as a device. This is all coming over now by way of the script. I owe the dev a beer:
I’ve never got the ssh key sorted out. But I think you can generate the key using puttygen. To add the key to Ha, you will need to install ssh & web terminal add-on and cd to .ssh and drop the key in there.
I found another solution and it has worked for me. I install the sensor.ssh and place it in the custom_components folder in HA. Create a dev_rpi.yaml
and add to your package folder.
dev_rpi.yaml (Note: the first sensor is HA and is local. The rest is from different RPIs)
## Uses the SSH Sensor from HAC
## https://github.com/custom-components/sensor.ssh
sensor:
# Hassio CPU
- platform: command_line
name: HA CPU Temperature
command: "cat /sys/class/thermal/thermal_zone0/temp"
unit_of_measurement: "°C"
value_template: '{{ value | multiply(0.001) | round(1) }}'
# ns1 CPU
- platform: ssh
host: 192.168.1.10
username: ns1
password: !secret rpi_pass
name: NS1 CPU Temperature
command: cat /sys/class/thermal/thermal_zone0/temp
unit_of_measurement: "°C"
value_template: >-
{%- set line = value.split("\r\n") -%}
{{ (line[1]|int / 1000) | round(1) }}
# ws1 CPU
- platform: ssh
host: 192.168.1.15
username: ws1
password: !secret rpi_pass
name: WS1 CPU Temperature
command: cat /sys/class/thermal/thermal_zone0/temp
unit_of_measurement: "°C"
value_template: >-
{%- set line = value.split("\r\n") -%}
{{ (line[1]|int / 1000) | round(1) }}
# ps1 CPU
- platform: ssh
host: 192.168.1.25
username: ps1
password: !secret rpi_pass
name: PS1 CPU Temperature
command: cat /sys/class/thermal/thermal_zone0/temp
unit_of_measurement: "°C"
value_template: >-
{%- set line = value.split("\r\n") -%}
{{ (line[1]|int / 1000) | round(1) }}
Thanks so much. That works great!