Proxmox CPU+ temp to HA (working guide + files)

I decided to publish working guide with already generated files for proxmox CPU temperatures…

The goal, to see temperatures in Home Assistant:
image

1. STEP - Set up API access in Home Assistant:


Click on user, then create new long-term token.
Please be careful to write down the API secret string as this you will need later in configuration *.py file (step 3) so that proxmox could connect to HA.

2. STEP - Set up sensors in HA configuration:

sensor:
  - platform: template
    sensors:
      proxmox_cpu_temp:
        friendly_name: "Procesor"
        value_template: '{{ states("input_number.proxmox_input_cpu_temp") | multiply(0.001) | round(1) }}'
        unit_of_measurement: °C

  - platform: template
    sensors:
      proxmox_acpi_interface:
        friendly_name: "ACPI vmesnik"
        value_template: '{{ states("input_number.proxmox_input_acpi_interface") | multiply(0.001) | round(1) }}'
        unit_of_measurement: °C

  - platform: template
    sensors:
      proxmox_isa_adapter:
        friendly_name: "ISA adapter"
        value_template: '{{ states("input_number.proxmox_input_isa_adapter") | multiply(0.001) | round(1) }}'
        unit_of_measurement: °C
input_number:
    proxmox_input_cpu_temp:
      name: Procesor
      min: 0
      max: 200000

    proxmox_input_acpi_interface:
      name: ACPI
      min: 0
      max: 200000

    proxmox_input_isa_adapter:
      name: ISA adapter
      min: 0
      max: 200000

In main configuration file you must also add API access, so add line:
api:

After that changes restart Home Assistant.

3. STEP - Upload modified .py files to PROXMOX:

Login to:
https://www.vseznalec.si/homeassistant/Proxmox_CPU_temp/
Username:
homeassistant
Password:
virtualclone2020_weeWX%

Download files:
proxmox_cpu_temp.py
proxmox_isa_adapter.py
proxmox_acpi_interface.py

Edit the files (use Notepad++) and change url (bold) based on your HA static IP address:
url = “http://192.168.X.XX:8123/api/states/input_number.proxmox_input_acpi_interface”
Edit the API key (bold):
“Authorization”: “Bearer HA_API_KEY”,
you get the API key in step 1.

After you change file upload files via WinSCP
image

image

You must upload to /root/.

4. STEP - Install dependencies on Debian Linux (proxmox)
Login to proxmox as root via SSH (PuTTy) and enter commands (after every line press ENTER):
sudo apt update
sudo apt install python3-pip
(confirm installation with Y)

5. STEP - Make .py files executable on Debian
Login to proxmox as root via SSH (PuTTy) and enter commands (after every line press ENTER):
chmod +x proxmox_cpu_temp.py
chmod +x proxmox_acpi_interface.py
chmod +x proxmox_isa_adapter.py

6. STEP - Most important step - edit crontab via SSH (PuTTy)
Enter command:
crontab -e
and enter lines the same as seen here:
image

* * * * * /root/proxmox_cpu_temp.py >/dev/null 2>&1
* * * * * (sleep 30 ; /root/proxmox_cpu_temp.py) >/dev/null 2>&1
* * * * * /root/proxmox_isa_adapter.py >/dev/null 2>&1
* * * * * (sleep 30 ; /root/proxmox_isa_adapter.py) >/dev/null 2>&1
* * * * * /root/proxmox_acpi_interface.py >/dev/null 2>&1
* * * * * (sleep 30 ; /root/proxmox_acpi_interface.py) >/dev/null 2>&1

Do not forget to add “>/dev/null 2>&1”, this means that in case that you will make restart of Home Assistant you won’t get bunch of error e-mails to you proxmox root account :slight_smile:
Also, do not forget to go to new line after last line, or cron job could not be created…

7. STEP - Last step is to add sensor to Lovelace in Home Assistant
sensor.proxmox_cpu_temp
sensor.proxmox_acpi_interface
sensor.proxmox_isa_adapter

That’s it…

Tools which are needed:
WinSCP:
https://winscp.net/eng/download.php
PuTTy:
https://www.putty.org/
Notepad++:
https://notepad-plus-plus.org/downloads/

Hardware used:
Intel NUC8i7BEH
https://www.intel.com/content/www/us/en/products/boards-kits/nuc/kits/nuc8i7beh.html

So that this user guide is possible to make I need to thank to:



7 Likes

Why not use a command line sensor that SSH into the host?
I use the below to get the temp of my NUC, no cronjob or python script needed.

##################
  # Temperature NUC
  ##################
  - platform: command_line
    name: temperature_cpu_nuc
    command: 'ssh -i /root/.ssh/id_rsa -o StrictHostKeyChecking=no -q [email protected] cat /sys/class/thermal/thermal_zone3/temp'
    value_template: "{{ value | int / 1000 }}"
    unit_of_measurement: "°C"
7 Likes

Same result, completly different approach…

:wink:

That’s why I’m asking, why all the overhead and scripts for something that can be done with way less steps?

1 Like

This cron job way we can also send HDD disk space to HA etc…
Can be this done via cmd from HA also?

Yes, I took a quick look at your files and they just execute a shell command and send it to HA over the HA API. Also I don’t see why you need three scripts for this, instead of having one script that updates all three or a script that generates one sensor where the other values are attributes.

You are wellcome to modify the scripts…

I could, but I don’t see a reason why I should do that, when there is an easier approach that requires less steps.
Also if I’d write a script for this, I would send the data to HA over MQTT with a discovery mesaage, so that the entities will be created automatically by HA.

1 Like

I created a python script to post ALL lm-sensor value to HA.

sensors2hass.py

It can be used instead of
proxmox_cpu_temp.py
proxmox_acpi_interface.py
pproxmox_isa_adapter.py

There is even a way to create all input_number section by using -c flag

python3 /root/sensors2hass.py -u http://192.168.1.123:8123 -s proxmox -a HA_API_KEY -c

or -d flag to see called url and values but nothing it posted to HA

python3 /root/sensors2hass.py -u http://192.168.1.123:8123 -s proxmox -a HA_API_KEY -d

the cron job used on my system

* * * * * root python3 /root/sensors2hass.py -u http://192.168.1.123:8123 -s proxmox -a HA_API_KEY

HA_API_KEY need to be replace by your own.

You will need to write you own sensor section in configuration.yaml

1 Like

Nevermind. I was in the wrong server.

do you have a guide on this one?

A guide for what?

on how to make that work, and what needs to be replaced in order to make it work

Here’s a guide to create ssh keys:

And here’s a guide for the NUC temp sensor

2 Likes

I followed your guide, but it still doesn’t work.

I followed your guide and doesnt work, maybe a i missed a step?

can you please share some details on how to set it ?

Thanks a lot to @kslb for posting this - it helped me a lot

your comand didn’t work - maybe because its a different hardware? (AMD?)
anyway - I took the output of ‘sensors’ and modified it to my needs:

temp=subprocess.run("sensors -u k10temp-* | grep 'temp3_input:' | sed -r 's/  temp3_input: //'", shell=True, text=True, capture_output=True).stdout.strip()
#temp = [int(i) for i in temp.split() if i.isdigit()][0]

i do not see it changing over the time
image

Hello, everyone,

I’ve experimented with this topic and managed to get everything working when the Python script accesses a Home Assistant running outside the Proxmox system, essentially as external “hardware.”

However, when I try to run the script on a VM (HAOS) within the Proxmox system, I encounter the error message “401 Unauthorized.”

I’ve tested various settings in the Home Assistant configuration.yaml without success:
frontend:
api:
html: (with and without parameters)
Generated a new long-term token
Deleted the IP ban list

I’ve restarted several times.

All without success.

The parameters of the Proxmox node and the VM are standard. An auditor has been added to the data center for the integration “proxmoxve:”

Since I’m not a Proxmox expert but suspect that the issue might be with the host system, specifically the parameters of the node or the VM, my question is whether anyone has solved similar problems?

Thanks in advance.