Page 1 of 1

Sent CPU temperature from Proxmox to Domoticz

Posted: Friday 10 January 2025 22:31
by SunHopper
With help of google I made a Python scrip for sending my server CPU temperature running PROXMOX VM to a virtual sensor
The temperature is updated in the file : /sys/class/thermal/thermal_zone0/temp
Only reading the first 2 digits on the first line.
Send this value to a virtual sensor in Domoticz every 5 minutes.

Note: This script has to run on the Proxmox server itself !! Not on the OS Domoticz runs on !!!!!

Code: Select all

import os
import re
import requests
import time
import sys

while True:

    file = open('/sys/class/thermal/thermal_zone0/temp', 'r')

    first_line = file.readline(2).strip()

# Close the file
    file.close()

    domoticzserver = "192.168.178.37:8080"
    idx_temp = "373"  # Put youre own IDX here of the virtual sensor

    val_temp = first_line


    res = requests.get(
        "http://"
        + domoticzserver
        + "/json.htm?type=command&param=udevice&idx="
        + idx_temp
        + "&nvalue=0&svalue="
        + val_temp
    )
    time.sleep(300)  # send every 5 minutes


Re: Sent CPU temperature from Proxmox to Domoticz

Posted: Saturday 11 January 2025 0:11
by waltervl
Normal Domoticz motherboard sensor gateway is not working in Proxmox environment?

Re: Sent CPU temperature from Proxmox to Domoticz

Posted: Saturday 11 January 2025 10:37
by SunHopper
Thats right. Domoticz runs on Ubuntu in a Proxmox VM.
Domoticz can't access the server sensors.
With this script running on the proxmox server itself it sends the CPU temperature to the IP address od Domoticz.
This way I'm able to monitor and get an alarm on Telegram when my CPU temperature is getting to high (summer time).

Re: Sent CPU temperature from Proxmox to Domoticz

Posted: Saturday 11 January 2025 13:09
by sloeber70
Hi.

Works fine!!
Do I need to create a crontab for this python file?
How can I check that this process is running and restart it if that would be necessary?

Kind regards.

Re: Sent CPU temperature from Proxmox to Domoticz

Posted: Saturday 11 January 2025 18:12
by sloeber70
Hi.

The script runs once and then it stops.. The delay for restarting the query is not working.

So I've altered the script and just remarked the timer and added "quit()". So that the script stops and the process is deleted.

I've added a crontab line so that the script runs every xx minutes (choice).
Crontab:
*/5 * * * * python3 /root/temp2domoticz.py

Script:
## start script ##
import os
import re
import requests
import time
import sys

while True:

file = open('/sys/class/thermal/thermal_zone1/temp', 'r')

first_line = file.readline(2).strip()

# Close the file
file.close()

domoticzserver = "10.10.3.2:9080"
idx_temp = "4856" # Put youre own IDX here of the virtual sensor

val_temp = first_line


res = requests.get(
"http://"
+ domoticzserver
+ "/json.htm?type=command&param=udevice&idx="
+ idx_temp
+ "&nvalue=0&svalue="
+ val_temp
)
#time.sleep(5) # wait 5 seconds
quit()
## end script ##

See the result in attachment

Re: Sent CPU temperature from Proxmox to Domoticz

Posted: Saturday 11 January 2025 18:13
by sloeber70
attachment

Re: Sent CPU temperature from Proxmox to Domoticz

Posted: Tuesday 14 January 2025 18:44
by SunHopper
@sloeber my script keeps running I started the script ending with & like: python3 /home/domoticz/domoticzCPU.py &
Added this to contrab for auto startup.

Nice to see it works for you :D