How to monitor Proxmox CPU temp

I run HA in a VM on a Proxmox host and since migrating from a Pi 3B+, I’ve wanted to keep an eye on the host’s CPU temp. Most of the info below is from this awesome community but I thought it would help to have it in once place

Digital Ocean has a great guide for creating a pair of SSH keys. Essentially you’ll want to run the following commands:

To generate the SSH key on the HA VM (I used the Terminal & SSH add-on). No name or passphrase are required.

$ ssh-keygen

To push the public key to the Proxmox server:

$ ssh-copy-id username@proxmox_host_ip

You should now be able to SSH to the Proxmox host without needing to enter a password. I tested this by running the following command in the Terminal & SSH add-on in HA.

$ ssh username@proxmox__host
$ exit

I found that the sensor in HA couldn’t get to the default /root/.ssh/ directory so I copied the id_rsa file to the HA config directory. Once again, using the Terminal & SSH add-on in HA.

$ cp /root/.ssh/id_rsa /config

From here, it’s just the config in HA. You’ll need to enter the username & IP address for your Proxmox most. Thermal_zone2 is the CPU package temp for me.

command_line:
  - sensor:
      name: "Lenovo M720q CPU Temp"
      command: "ssh -i /config/id_rsa -o StrictHostKeyChecking=no username@proxmox_host_ip -t 'cat /sys/class/thermal/thermal_zone2/temp'"
      unit_of_measurement: "°C"
      scan_interval: 300
      value_template: "{{ (value | multiply(0.001)) | round(1) }}"

And here we are - CPU temp showing in lovelace!

Capture

23 Likes

Or you could run Glances on Proxmox, with the added benefit of other sensors without the need for templates…

1 Like

You could do that… but I didn’t.

1 Like

Thanks, this worked great on my Proxmox NUC system!

1 Like

Any idea what I am doing wrong?

~ $ ssh-copy-id [email protected]
/usr/bin/ssh-copy-id: ERROR: No identities found

Hi, when doing the first step it says read only, and I can’t sudo from the terminal ingress. How did you get around this?

Thanks.

EDIT: I ended up remotely ssh’ing in and had no problems. Just couldn’t use the ingress.

I didn’t realize I didn’t have to add a paraphrase to ssh. How can I include the password to the sensor template line or is there a way to delete that password?

Delete the id_rsa file and then start again.

how do I do that?

in the terminal type rm /config/.ssh/id_rsa if /config/.ssh/id_rsa is where you copied it to.

1 Like

its telling me cant remove. no such file or directory

Then you didn’t follow the command to save the file there (or you did, but the post has a typo and calls it is_rsa rather than id_rsa which is what it should be called.

EDIT: If you followed the commands exactly - then the file you want to delete will be /config/is_rsa

Web capture_12-11-2021_72345_homeassistant.local
I pressed enter twice. I tested sshing to the server and it keeps asking for password

usage sensors:

  - platform: command_line
    name: 'Proxmox CPU'
    command: ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /config/.ssh/id_rsa [email protected] top -d 0.5 -b -n2 | grep "Cpu(s)"|tail -n 1 | awk '{printf ("%.0f\n",$2 + $4)}'
    unit_of_measurement: '%'
  - platform: command_line
    name: 'Proxmox RAM'
    command: ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /config/.ssh/id_rsa user@ip free -m | grep Mem | awk '{printf ("%.0f\n",$3*100/$2)}'
    unit_of_measurement: '%'
  - platform: command_line
    name: 'Proxmox SSD'
    command: ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /config/.ssh/id_rsa user@ip df | grep pve-root | awk '{printf ("%.0f\n",$3*100/($3+$4))}'
    unit_of_measurement: '%'
2 Likes

Yes - it’s asking YOU for the password for the proxmox server, it wouldn’t be very secure if anyone could just copy whatever SSH key they liked to any server, without proving to the server that they have an account on the server.

You should type in the root password for the Proxmox server, and then it will copy the key to the Proxmox server. After that whenever you do ssh -i /config/id_rsa [email protected] it will NOT ask for the password anymore.

(Make sure you after you have provided the root password, you then copy the key to /config/id_rsa)

1 Like

Ah so It wont need password when HA calls for the cpu temp from server, right?
sorry I am a total noob here

1 Like

Yes you provide the password once, which is not HA asking for the password, it’s Proxmox asking for you to prove you have permission to access the server. You provide the root password, and Proxmox copies the SSH key to it’s file, and in future because it already trusts the SSH key that is connecting to it, it won’t ask for a password. (Providing you use the -i option with the ssh command, -i means identity)

So to be clear the full list of commands should be:

ssh-keygen
ssh-copy-id root@proxmox-ip-address
**TYPE IN ROOT PASSWORD FOR PROXMOX**
mkdir -p /config/.ssh
cp /root/.ssh/id_rsa /config/.ssh/id_rsa
ssh -i /config/.ssh/id_rsa root@proxmox-ip-address
exit

Copying the ssh file in to the config file is extremely important. Because otherwise HomeAssistant does not have access to it.

1 Like

Thank you so much for sticking with me.
Web capture_12-11-2021_9371_192.168.0.108
what am I doing wrong here please?

update: I got to here


I noticed that warning about the /config/.ssh/id_rsa not accessible though

can you run

ls -lah /root/.ssh

please

in the server itself or through shh addon in home assistant?